-
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
Epoch lints don't handle macros very well #48704
Comments
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? |
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. |
The whole "deprecation" part of the epoch RFC: "Let's invent problems so we have something to solve." |
I think that hygiene questions are orthogonal here anyhow. The macro may well originate in the same crate, for example. |
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 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. |
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. |
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. |
@est31 do you mean that "epoch hygiene" is not orthogonal to epochs, or the need to be able to identify "approximate" suggestions? |
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 |
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. |
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 |
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 |
…diom, r=alexcrichton merge unused-extern-crate and unnecessary-extern-crate lints Extend the `unused_extern_crates` lint to offer a suggestion to remove the extern crate and remove the `unnecessary_extern_crate` lint. Still a few minor issues to fix: - [x] this *does* now leave a blank line... (defer to #51176) - idea: extend the span to be replaced by 1 character if the next character is a `\n` - [x] what about macros? do we need to watch out for that? (defer to #48704) - [x] also it doesn't work for `extern crate foo; fn main() { foo::bar(); }` - this is subtle: the `foo` might be shadowing a glob import too, can't always remove - defer to #51177 - [x] we also don't do the `pub use` rewrite thang (#51013) Spun off from #51010 Fixes #50672 r? @alexcrichton
I believe #52214 is another instance of this |
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! |
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
approximate
flag 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
The text was updated successfully, but these errors were encountered: