Closed
Description
I have a macro like this:
#[macro_export]
macro_rules! define_proc_macros {
(
$(
$( #[$attr:meta] )*
pub fn $proc_macro_name: ident ($input: ident : &str) -> String
$body: block
)+
) => {
$(
$( #[$attr] )*
#[proc_macro_derive($proc_macro_name)]
pub fn $proc_macro_name(derive_input: ::proc_macro::TokenStream)
-> ::proc_macro::TokenStream {
let $input = derive_input.to_string();
let $input = $crate::_extract_input(&$input);
$body.parse().unwrap()
}
)+
}
}
pub fn _extract_input(derive_input: &str) -> &str {
// …
}
When I use it, I get the warning in the title twice for every generated functions. When I move things into one crate to avoid "note: this error originates in a macro outside of the current crate", the span of the warning is on $proc_macro_name
in #[proc_macro_derive($proc_macro_name)]
.
Steps to reproduce: runCARGO_INCREMENTAL=1 cargo +nightly build -p cssparser-macros
in https://github.com/servo/rust-cssparser/.
I don’t understand this warning and what I can do about it. What does quasi-quoting mean in this context? How bad is the inefficiency really? Is it possible to fix it while keeping this macro’s flexibility?
CC @michaelwoerister and @nikomatsakis for #37787 that added this warning.
Activity
michaelwoerister commentedon Apr 3, 2017
That's strange. @jseyfried, do you see anything in the macro above that in a
Token::Interpolated
?This is where the warning is generated by the way:
rust/src/librustc_incremental/calculate_svh/svh_visitor.rs
Line 1068 in 5309a3e
michaelwoerister commentedon Apr 10, 2017
ping @jseyfried: Do you know what could be going on here? Where does the macro definition above introduce a
Token::Interpolated
?jseyfried commentedon Apr 24, 2017
The
$proc_macro_name
turns into aNonterminal::Ident
token. Normally, nonterminals are parsed into AST and don't cause warnings. However, now that #40346 has landed, attributes can have arbitrary tokens and theNonterminal::Ident
token ends up in the final AST/HIR.I believe the solution here is to expand interpolated/nonterminal tokens into their underlying terminal tokens as we lower to HIR.
SimonSapin commentedon Apr 24, 2017
@jseyfried If I understand correctly, something is inefficient but what needs to change to fix it is in rustc rather than in my code?
michaelwoerister commentedon Apr 24, 2017
@SimonSapin That is correct. It's an inefficiency in rustc's handling of some parts of the HIR/AST.
michaelwoerister commentedon Apr 24, 2017
@jseyfried, that sounds like a great solution. Would that be much work?
jseyfried commentedon Apr 24, 2017
@michaelwoerister
Once #40939 lands it should be simple.
rushmorem commentedon Apr 26, 2017
I'm getting this warning too when using proc-macro-hack (cc @dtolnay). Is there any way to suppress it?
seanmonstar commentedon Jun 7, 2017
If it will take a while to fix this, it would be nice to at least be able to suppress the warning.
michaelwoerister commentedon Jun 8, 2017
@jseyfried Is there an ETA for #40939?
michaelwoerister commentedon Jul 7, 2017
Now that #40939 has landed, will you look into a fix, @jseyfried?
jseyfried commentedon Jul 10, 2017
@michaelwoerister Sure, I still think #40946 (comment) is the best fix; I'll implement this week.
18 remaining items