-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Macro hygiene bug #32922
Comments
cc @nrc |
Another example -- the following should print macro_rules! foo { () => {
let x = 1;
macro_rules! bar { () => {x} }
println!("{}", bar!());
}}
fn main() {
foo! {};
} Either adding another pair of braces (as in the first initial comment) or manually expanding the macro allows this example to compile. |
This is probably a special case of hygiene not really working at all in multi-statement macros, #31856. |
Amazing, thanks! (Should we check crater for breakage, though?) |
I think it's unlikely that there will be breakage, but it would probably be a good idea to check anyway, especially since silent changes in behavior are scary. |
Well crater doesn't catch those, so we just have to hope that nobody was actually using multi-statement macros... |
True, but if there's no breakage I believe that's pretty strong evidence that there won't be any behavior changes since I would think breakage (either due to there not being a shadowing binding in the macro expansion or due to the shadowing binding being of the wrong type) would be much more likely than a behavior change (in which there would need to be a shadowing binding of the same type). |
Also, does crater run tests? |
Right, crater does not normally run tests. So macros not used/expanded in a crate somewhere are entirely unexercised by crater. |
Does it build the tests? If not perhaps it builds bins, and we could "test" macro crates that way? |
It seems that crater simply runs |
Fix macro hygiene bug This fixes rust-lang#32922 (EDIT: and fixes rust-lang#31856), macro hygiene bugs. It is a [breaking-change]. For example, the following would break: ```rust fn main() { let x = true; macro_rules! foo { () => { let x = 0; macro_rules! bar { () => {x} } let _: bool = bar!(); //^ `bar!()` used to resolve the first `x` (a bool), //| but will now resolve to the second x (an i32). }} foo! {}; } ``` r? @nrc
The following should print
1
, but it currently prints0
:For comparison, the following correctly prints
1
:The text was updated successfully, but these errors were encountered: