-
Notifications
You must be signed in to change notification settings - Fork 13k
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
break
and continue
are not hygienic
#12262
Comments
Note that #9047 was caused by (semi-)hygienic |
My first try here: edwardw@4e06bc6 I may not fully revert the change of #9103 since three new tests still fail. |
@edwardw Thanks, looking good. I think you can squash those test in a single test that ensures break and continue are hygienic. Also, could you please add this test too? macro_rules! foo {
() => {
// this should just break from this inner loop...
'x: loop { break 'x; }
}
}
'x: loop {
// ...but it may refer to the outer 'x when used inside here
foo!();
println!("should be printed");
} |
Yes it was even with this change seconds ago: edwardw@9427d36 |
I noticed two things. One is that |
@edwardw I think you need to be renaming the labels as you register them, e.g.: diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs
index 7eb9b23..99ce3f9 100644
--- a/src/librustc/middle/resolve.rs
+++ b/src/librustc/middle/resolve.rs
@@ -5177,7 +5177,7 @@ impl Resolver {
let rib = label_ribs.get()[label_ribs.get().len() -
1];
let mut bindings = rib.bindings.borrow_mut();
- bindings.get().insert(label.name, def_like);
+ bindings.get().insert(mtwt_resolve(label), def_like);
}
visit::walk_expr(this, expr, ()); (Just building this to test it now.) (You'll need to adjust the comments too.) |
Also, I'd recommend that you have some compile-fail tests to double/triple check the hygiene is working, e.g. macro_rules! foo { () => { break 'x; } } //~ ERROR use of undeclared label `x`
fn main() {
'x: loop { foo!() }
} macro_rules! foo { ($e: expr) => { 'x: loop { $e } } }
fn main() {
foo!(break 'x); //~ ERROR use of undeclared label `x`
} |
Ah, so the problem is actually the macro expansion never renames these idents... see |
Tried to rename label of for loop: edwardw@9054b80 but the tests still fail. |
Just a quick note based on your last commit. You need to do the rename for both |
Oh, I leave |
@edwardw it might be easier to get feedback and iterate if you open a PR even if it's not ready (for commenting, etc.). |
Can we remove the E-easy label? This one is far from easy. |
Makes labelled loops hygiene by performing renaming of the labels defined in e.g. `'x: loop { ... }` and then used in break and continue statements within loop body so that they act hygienically when used with macros. Closes #12262.
…in-macro-expansion, r=lnicola ide: insert whitespace between 'mut' and 'self' in macro expansion fixes rust-lang#12260
Working on #6993 specifically on #12179 raised the fact that
break
andcontinue
useName
as opposed ofIdent
. This was introduced in #9103 and unfortunately this change seems to have made them non-hygienic.An example taken from @huonw comment:
Presumably, reverting the change should make them hygienic again.
I volunteer as a mentor for this fix.
The text was updated successfully, but these errors were encountered: