-
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
name-based comparison in new label-shadowing check has likely hygiene issues. #24278
Comments
It looks like it can't be fixed by a simple hygienic comparison (
so, two label declarations are never equal if compared hygienically. I'm still studying mtwt and trying to understand what can be done with this issue. |
@petrochenkov just because Idents have different syntax contexts, does not necessarily mean they are not equal. Calling |
In the example above |
That seems correct - they don't shadow. The shadowing case is:
I think hygienic equality is what we want, if that doesn't work, there might be a bug in the mtwt implementation. |
According to the code and tests (https://github.com/rust-lang/rust/blob/master/src/test/compile-fail/loops-reject-duplicate-labels.rs) label duplication is supposed to be checked globally in a function, regardless of nesting (at least currently) (not sure why exactly). Some discussion here: #21633 |
Heh, well that seems wrong to me, but explains why there is trouble doing hygienic comparison. I don't see an easy solution in this case (it's possible a different hygiene algorithm can fix this, or at least allow us to fix it with an easy-ish hack, but I don't think that counts as easy). |
Also lol at that issue being E-Easy! |
Ping @pnkfelix @petrochenkov @nrc still a problem? |
@brson |
This should "just work" in with declarative macros 2.0 (#40847) -- I'll add a test. |
I believe the correct test case here is https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=baa075b80cf04df7f1f3f6b8389d82ff; this emits |
Spawned off of #24162. Our lifetimes only carry a
Name
, not anIdent
, which means the comparisons for shadowing are only doing name based comparisons.But macros should be free to introduce labels, and have them be treated as independent due to hygiene.
This bug is believed to only introduce issues where code will cause a warning to be emitted by the new shadowing check when it should be accepted; i.e. there are not any known soundness issues associated with this problem.
(Note: While loop labels themselves are
Ident
s, much of the syntax system does not treat them the same way it treats "normal" variables with respect to e.g. hygiene. For example thesyntax::visit
system does not invokevisit_ident
on loop labels.)The text was updated successfully, but these errors were encountered: