Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upEpoch lints don't handle macros very well #48704
Comments
Manishearth
added
the
A-lint
label
Mar 3, 2018
This comment has been minimized.
This comment has been minimized.
|
In the epochs RFC discussion, we got promised that macros will get "epoch hygiene" aka using a macro from an older epoch that emits old epoch stuff inside a crate from the newer epoch (and vice versa) will work. Can't this hygiene be extended to lints? |
This comment has been minimized.
This comment has been minimized.
|
idk. I don't think epoch hygiene can be perfect given that the error can be caused by the interactions of macros from different crates. Epoch breakages can be conservative, but lints should go the other way and try to warn more even for stuff you can't directly fix. The problem is not that we want to precisely detect these things, it's that we want to emit good suggestions. Also, we don't have hygiene. yet, but we want the epoch lints to exist early. |
This comment has been minimized.
This comment has been minimized.
|
The whole "deprecation" part of the epoch RFC: "Let's invent problems so we have something to solve." |
This comment has been minimized.
This comment has been minimized.
|
I think that hygiene questions are orthogonal here anyhow. The macro may well originate in the same crate, for example. |
This comment has been minimized.
This comment has been minimized.
|
I also think this concern is orthogonal from epochs, basically -- this seems to apply equally well to any lint. Epochs are only different in that we want to try harder; but having lints that just 'turn off' around code in macros is pretty suboptimal (even if sometimes the most expedient thing). |
This comment has been minimized.
This comment has been minimized.
This sounds reasonable, but what is this flag? I guess it's something you added in #47540... feels like we need a tracking issue of some kind for this feature? Then we can do an FCP? And/or an RFC? (I still feel grumpy that we have so little process around our JSON output, which then makes it hard to specify small incremental changes to it.) This feels like @rust-lang/dev-tools concern, in any case? Or possibly @rust-lang/compiler -- it's right on that intersecting line. |
This comment has been minimized.
This comment has been minimized.
|
Yeah the json field is behind a -Z flag so we could add it backwards compatibly. It can be RFCd, and we can move towards using it for everything in rustc. Default to not-approximate and use it whenever. Mini-rfc (perhaps just an FCP on a PR?) should be ok imo. Yeah, the concern is orthogonal from epochs; like, it's something we have tried (and failed) to solve in clippy as well because rustc just doesn't (or didn't, at the time) have enough expansion info to solve this correctly. Clippy currently just bails on macro-y things. The concern is a major one for epochs because we can't brush it away with "it's ok to have false negatives on a lint"; epoch lints and compat lints have to catch everything. |
This comment has been minimized.
This comment has been minimized.
|
Note that I'm refferring to @nrc's comment in the epoch RFC discussion. The concern is very much not orthogonal to epochs. I think it is even more important for epochs than the raw identifiers RFC is. |
Manishearth
added
the
WG-epoch
label
Mar 7, 2018
This comment has been minimized.
This comment has been minimized.
|
@est31 do you mean that "epoch hygiene" is not orthogonal to epochs, or the need to be able to identify "approximate" suggestions? |
This comment has been minimized.
This comment has been minimized.
|
One thing we noticed yesterday is that at least for this epoch the only breaking change is new keywords, which will work in the lexer, so epoch hygeine is not a problem (I assume macros are exported as tokens and not source). However, if we decide to enable |
This comment has been minimized.
This comment has been minimized.
yes, I meant that. Think of a future date where you have multiple epochs each with its own style. Here, writing code in a macro that works on all epochs is hard, you need hygiene. Avoiding to use the keywords from those epochs as identifiers should be quite easy on the other hand though. That's why I believe epoch hygiene is so important. |
This comment has been minimized.
This comment has been minimized.
I'm a bit confused by this. I mean if you have some macro that generates a local variable named
Yeah so right now you have to do Clearly we can't give warnings unless there is a new form available for you to migrate to! So either we should limit (I do suspect the breakage here is largely theoretical, but then isn't the point of the epoch to enable us to avoid even theoretical breakage?) cc @rust-lang/core -- the |
This comment has been minimized.
This comment has been minimized.
Yeah, because we store the macro as tokentrees ( If macros worked in all positions we literally wouldn't need the identifier RFC, we could just export macros called
We do? 0cb3672
That's going to happen anyway, the moment |
XAMPPRocky
added
C-enhancement
T-compiler
labels
May 21, 2018
nikomatsakis
referenced this issue
May 29, 2018
Merged
merge unused-extern-crate and unnecessary-extern-crate lints #51015
bors
added a commit
that referenced
this issue
May 29, 2018
nikomatsakis
referenced this issue
May 30, 2018
Closed
"path starts with module" lint fails with rustfix when triggered in macro #51205
nikomatsakis
added
the
A-rust-2018-preview
label
May 30, 2018
bors
added a commit
that referenced
this issue
Jun 2, 2018
nrc
added
the
A-edition-2018-lints
label
Jul 2, 2018
This comment has been minimized.
This comment has been minimized.
|
I believe #52214 is another instance of this |
alexcrichton
added this to the Rust 2018 Preview 2 milestone
Jul 11, 2018
This comment has been minimized.
This comment has been minimized.
|
Ok we've had a lot of improvements in the last few weeks to this:
Overall this has made the story much better here, so I'm going to close this. If there are remaining issues though I think at this point they probably are best to open dedicated issues for! |
Manishearth commentedMar 3, 2018
If a lint originates in a macro, epoch lints will still emit a suggestion.
This suggestion often works, especially when the linted code comes from within the macro, entirely.
Given that these are backcompat lints we have to emit them even if the current crate cannot fix them.
I suggest stabilizing the
approximateflag on suggestions, so that rustfix can differentiate between these and provide a mode where it fixes everything but prompts for these. Either that, or we don't emit suggestions at all in these cases.https://github.com/killercup/rustfix/issues/57 tracks a bug in rustfix that occurs for macros where duplicate suggestions apply to the same place.
cc @nikomatsakis