Skip to content
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

fix: Implement mixed site hygiene #18264

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ChayimFriedman2
Copy link
Contributor

@ChayimFriedman2 ChayimFriedman2 commented Oct 8, 2024

The realization that made me do this (as explained in detail in the first commit) is that while def-site hygiene is incredibly hard for us, mixed-site hygiene should be easy (well, I underestimated it due to the need of the second commit, but still). And the best part in that is that mixed-site hygiene rules: def-site hygiene is available only on nightly and without a clear path to stabilization, and even when (if) it will stabilize this will still help solving the case of variables/labels.

This brings diagnostics on self down to four (from five, I think? or more) 🎉 and the remaining diagnostics all require next solver (three due to coercion issue, one due to the issue of trait bounds not being preferred).

Best reviewed commit by commit.

Fixes #18262.
Fixes #16342.
Fixes #13758.
Fixes #11681.
Fixes #10535.

(Wow, so many issues! That's heart-filling ❤️)

Or macro_rules hygiene, or mixed site hygiene. In other words, hygiene for variables and labels but not items.

The realization that made me implement this was that while "full" hygiene (aka. def site hygiene) is really hard for us to implement, and will likely involve intrusive changes and performance losses, since every `Name` will have to carry hygiene, mixed site hygiene is very local: it applies only to bodies, and we very well can save it in a side map with minor losses.

This fixes one diagnostic in r-a that was about `izip!()` using hygiene (yay!) but it introduces a huge number of others, because of rust-lang#18262. Up until now this issue wasn't a major problem because it only affected few cases, but with hygiene identifiers referred by macros like that are not resolved at all. The next commit will fix that.
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 8, 2024
…n macro expansion

E.g.:
```rust
let v;
macro_rules! m { () => { v }; }
```

This was an existing bug, but it was less severe because unless the variable was shadowed it would be correctly resolved. With hygiene however, without this fix the variable is never resolved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment