Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds ability to use provided ident verbatim for export #13

Merged
merged 5 commits into from
Oct 10, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Supports both in import_attr
Nikhil Gupta committed Oct 9, 2023
commit 3d02187803f263aa42a80fd53bb41034cb05078a
38 changes: 27 additions & 11 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -777,6 +777,7 @@ impl ToTokens for OverridePath {
pub fn import_tokens_attr_internal<T1: Into<TokenStream2>, T2: Into<TokenStream2>>(
attr: T1,
tokens: T2,
hidden_source_path: bool,
) -> Result<TokenStream2> {
let attr = attr.into();
let mm_override_path = parse2::<OverridePath>(attr)?;
@@ -873,18 +874,33 @@ pub fn import_tokens_attr_internal<T1: Into<TokenStream2>, T2: Into<TokenStream2
Ok(res) => res,
Err(err) => return err.to_compile_error().into()
};
quote::quote! {
#pound resolved_mm_override_path::forward_tokens_verbatim! {
#pound path,
#orig_sig_ident,
#pound resolved_mm_override_path,
{
{ #pound attached_item },
{ #pound path },
{ #pound custom_parsed }
if #hidden_source_path {
quote::quote! {
#pound resolved_mm_override_path::forward_tokens! {
#pound path,
#orig_sig_ident,
#pound resolved_mm_override_path,
{
{ #pound attached_item },
{ #pound path },
{ #pound custom_parsed }
}
}
}
}.into()
}.into()
} else {
quote::quote! {
#pound resolved_mm_override_path::forward_tokens_verbatim! {
#pound path,
#orig_sig_ident,
#pound resolved_mm_override_path,
{
{ #pound attached_item },
{ #pound path },
{ #pound custom_parsed }
}
}
}.into()
}
}
}
};
10 changes: 9 additions & 1 deletion macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -395,7 +395,15 @@ pub fn import_tokens_proc(attr: TokenStream, tokens: TokenStream) -> TokenStream
/// For more information and an example see [`macro@with_custom_parsing`].
#[proc_macro_attribute]
pub fn import_tokens_attr(attr: TokenStream, tokens: TokenStream) -> TokenStream {
match import_tokens_attr_internal(attr, tokens) {
match import_tokens_attr_internal(attr, tokens, true) {
Ok(tokens) => tokens.into(),
Err(err) => err.to_compile_error().into(),
}
}

#[proc_macro_attribute]
pub fn import_tokens_attr_verbatim(attr: TokenStream, tokens: TokenStream) -> TokenStream {
match import_tokens_attr_internal(attr, tokens, false) {
Ok(tokens) => tokens.into(),
Err(err) => err.to_compile_error().into(),
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@ pub use macro_magic_macros::{

#[cfg(feature = "proc_support")]
pub use macro_magic_macros::{
import_tokens, import_tokens_attr, import_tokens_proc, with_custom_parsing,
import_tokens, import_tokens_attr, import_tokens_attr_verbatim, import_tokens_proc, with_custom_parsing,
};

/// Contains re-exports required at compile-time by the macro_magic macros and support