-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Hygiene break in macros involving string containing single quote #50061
Comments
Alrighty-roo. As everything these days with hygiene, there's a couple of bugs here. With this one though I think only two! Everything has to do here with #43081 basically. AKA anything that runs through this block of code that falls off this happy path Why does this function not fit on the happy path?The usual reasons we think you fall off the "happy path" are due to things like inner attributes, Turns out though #49852 had a bug in it (surprise surprise!). There we're using Here in the example you're using the literal string tl;dr the token stream of Recent regression in hygiene informationOK so in the case above we're falling off the happy path when we didn't expect to, but even still there's some weird bad hygiene behavior when we're not on the happy path. There's still something to fix! It turns out that there's also a regression due to #49154 (found via bisection). Before that PR this example would compile just fine, afterwards though it's hitting this error. @petrochenkov can you help diagnose this and see what's going on? The reduced test case I have right now is: // foo.rs
#![crate_type = "proc-macro"]
#![feature(proc_macro)]
extern crate proc_macro;
use proc_macro::TokenStream;
#[proc_macro_attribute]
pub fn foo(_a: TokenStream, b: TokenStream) -> TokenStream {
b.into_iter().collect()
} // bar.rs
#![feature(proc_macro)]
extern crate foo;
use foo::*;
macro_rules! j {
(@ $v:tt) => {
let _ = $v;
};
(# $v:tt) => {
j!(@ $v);
};
}
#[foo]
fn main() {
//! test
let s = "12'3";
j!(# s);
} (note the inner attribute on
|
Discovered in rust-lang#50061 we're falling off the "happy path" of using a stringified token stream more often than we should. This was due to the fact that a user-written token like `0xf` is equality-different from the stringified token of `15` (despite being semantically equivalent). This patch updates the call to `eq_unspanned` with an even more awful solution, `probably_equal_for_proc_macro`, which ignores the value of each token and basically only compares the structure of the token stream, assuming that the AST doesn't change just one token at a time. While this is a step towards fixing rust-lang#50061 there is still one regression from rust-lang#49154 which needs to be fixed.
I've posted a fix for the "happy path" at https://github.com/rust-lang/rust/pull/50069which will actually fix @dtolnay's example above. That PR does not, however, fix the regression from #49154 which is still reproducible with the example I gisted. |
Any idea why my repro case above is fixed if you remove the macro_rules! j {
- (@ $v:tt) => {
+ ($v:tt) => {
let _ = $v;
};
(# $v:tt) => {
- j!(@ $v);
+ j!($v);
};
} |
If you remove the |
I'll investigate. |
proc_macro: Stay on the "use the cache" path more Discovered in #50061 we're falling off the "happy path" of using a stringified token stream more often than we should. This was due to the fact that a user-written token like `0xf` is equality-different from the stringified token of `15` (despite being semantically equivalent). This patch updates the call to `eq_unspanned` with an even more awful solution, `probably_equal_for_proc_macro`, which ignores the value of each token and basically only compares the structure of the token stream, assuming that the AST doesn't change just one token at a time. While this is a step towards fixing #50061 there is still one regression from #49154 which needs to be fixed.
e2afefd is the commit causing the regression. |
An issue recently popped up on Rocket (rwf2/Rocket#635) that appears to be identical to this one and is not resolved in any recent nightly. It's possible that the root cause is #50050, however. |
This is minimized from the dramatic forum thread The latest nightly compiler has broken macros. The following code is fine in nightly-2018-04-12 but breaks with nightly-2018-04-15. Oddly, lots of minor perturbations make it succeed. For example remove the two
@
characters and it works. Or remove the single quote in the string and it works.@alexcrichton
The text was updated successfully, but these errors were encountered: