forked from rwf2/Rocket
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mod-export 'msg!', 'local_cache!', 'try_outcome!'.
This removes the export of each of these macros from the root, limiting their export-scope to their respective module. This is accomplished using a new internal macro, 'export!', which does some "magic" to work around rustdoc deficiencies.
- Loading branch information
1 parent
41018a5
commit bab3b1c
Showing
13 changed files
with
258 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use std::hash::Hash; | ||
|
||
use devise::Spanned; | ||
use devise::ext::SpanDiagnosticExt; | ||
use devise::proc_macro2::{TokenStream, TokenTree, Punct}; | ||
use devise::syn; | ||
|
||
use crate::syn_ext::IdentExt; | ||
|
||
pub fn _macro(input: proc_macro::TokenStream) -> devise::Result<TokenStream> { | ||
let mac: syn::ItemMacro = syn::parse(input)?; | ||
let macro_name = match mac.ident { | ||
Some(ident) => ident, | ||
None => return Err(mac.span().error("expected `macro_rules!`")), | ||
}; | ||
|
||
// We rename the actual `macro_export` macro so we don't accidentally use it | ||
// internally from the auto-imported crate root macro namespace. | ||
let (attrs, def) = (mac.attrs, mac.mac); | ||
let internal_name = macro_name.prepend("___internal_"); | ||
let mod_name = macro_name.uniqueify_with(|mut hasher| def.hash(&mut hasher)); | ||
|
||
let macro_rules_tokens = def.tokens.clone(); | ||
let decl_macro_tokens: TokenStream = def.tokens.into_iter() | ||
.map(|t| match t { | ||
TokenTree::Punct(p) if p.as_char() == ';' => { | ||
let mut token = Punct::new(',', p.spacing()); | ||
token.set_span(p.span()); | ||
TokenTree::Punct(token) | ||
}, | ||
_ => t, | ||
}) | ||
.collect(); | ||
|
||
Ok(quote! { | ||
#[allow(non_snake_case)] | ||
mod #mod_name { | ||
#[doc(hidden)] | ||
#[macro_export] | ||
macro_rules! #internal_name { | ||
#macro_rules_tokens | ||
} | ||
|
||
pub use #internal_name; | ||
} | ||
|
||
#(#attrs)* | ||
#[cfg(all(nightly, doc))] | ||
pub macro #macro_name { | ||
#decl_macro_tokens | ||
} | ||
|
||
#[cfg(not(all(nightly, doc)))] | ||
pub use #mod_name::#internal_name as #macro_name; | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.