-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Set CompilerDesugaring expn_info for all desugared expressions #39766
Conversation
It looks like the highfive bot has missed this PR. Can anyone review this? |
☔ The latest upstream changes (presumably #40091) made this pull request unmergeable. Please resolve the merge conflicts. |
0e75e7b
to
b6d8569
Compare
r? @Manishearth noone seems to want to take this, and it's clippy related ;) |
cc @rust-lang/compiler |
r? @jseyfried |
I would avoid giving sole r+ on PRs that affect clippy |
I think we should not do this - we have avoided it in the past. I have tried to keep a strong distinction in the compiler around generated code - in particular lowered code is not generated code. The contract is basically that if the user should recognise that the code is generated (i.e., they used a macro or other form of codegen) then the span should have an expn_info and error messages should be explicit about the expansion. Tools can recognise that the source code does not reflect the compiler's representation and can 'correct' that via the expansion stack. OTOH, code that the user cannot recognise as generated (e.g., I'm not sure how best to help Clippy here. I suspect it should be using a higher level API to the compiler's info, but not sure how that should work in general. |
@nrc For precise spans we need to do this though, however I agree users shouldn't be able to see it. |
@eddyb yeah, long term I think we should consider changes - I do envision lowering being reflected in the spans, but distinct from other kinds of generated code (this might just be a flag, but ideally we'd have some way of handling the 'macro definition'). |
@nrc FWIW we already create such spans - we have to, for |
@eddyb I'm not sure what you mean by "such spans" - if we did this for lowered expressions then this PR would be redundant, no? I'm not sure how the stability checking works though. |
@nrc We only do it when have to for stability, look for calls to the |
@@ -13,6 +13,8 @@ fn main() { | |||
//~^ expected (), found integral variable | |||
//~| expected type `()` | |||
//~| found type `{integer}` | |||
//~| NOTE: in this expansion of desugaring of `if let` | |||
//~| NOTE: in this expansion of desugaring of `if let` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I definitely think we should not be writing this to the output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines are required by compiletest, but not shown in rustc output (see the second commit).
@@ -14,4 +14,5 @@ fn main() { | |||
for Some(x) in xs {} | |||
//~^ ERROR E0297 | |||
//~| NOTE pattern `None` not covered | |||
//~| NOTE in this expansion of desugaring of `for` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nor this.
@nikomatsakis We already have that distinction, we use it for creating |
@eddyb so ... what are we arguing about exactly? I must be confused. |
@nikomatsakis I am saying we're already using this in some cases, and I'm pretty sure we agree we need unique spans in the future, so I'm in favor of making this change with no user-visible output. |
@eddyb ok I agree with you :) |
So I assume the |
I'm not sure how that makes sense? save-analysis doesn't look at HIR spans, does it? |
save-analysis certainly looks at HIR nodes (we have to in order to get type check info). We also look at spans from deep inside nodes. I'm not sure if we actually look at spans from HIR nodes because of that, so you are right that it is probably not as bad as I thought. However, it is certainly possible that we do look at some HIR span somewhere, so if we move to doing the span stuff everywhere, then I'd like to make sure we don't break any save-analysis stuff. |
@nrc You should auto-generate a corpus of tests (from run-pass tests or something), IMO. |
@eddyb yeah, tests for save-analysis have been on my mind for like the last 6 months. Someday I'll implement them |
☔ The latest upstream changes (presumably #39921) made this pull request unmergeable. Please resolve the merge conflicts. |
So what action is required here? |
@oli-obk @sinkuu I think this PR needs changing so that the changes are not user-visible (see @nikomatsakis's comments). There is apparently a distinction that can be made between lowered and generated code and that should be used (I was under the impression we couldn't directly do this, but perhaps I don't understand exactly what is meant here) - the stuff in this PR should use that. Finally, we should establish that this does not break save-analysis. To do that, fine the two run-make save-analysis tests. Each should emit a JSON or CSV file when run. Compare the files before and after applying this PR, they should be identical. If the post-PR file is smaller, then there are issues that need addressing. |
@sinkuu did you get a chance to compare the save-analysis output? |
I think desugarings should not be user-visible in JSON output either - the expectation is that JSON errors are shown to users fairly directly by tools. I wouldn't expect an IDE (for example) to show the user the macro expansion of a desugared language feature. |
☔️ merge conflicts! |
🕸 We haven't seen activity on this PR for 2 weeks 🕸, so we're closing it to reduce our backlog. Feel free to reopen if you still want to work on it. |
This PR adds
CompilerDesugaring
expn_info for all compiler desugared expressions. This will ease writing lints which need to exclude them (for example https://github.com/Manishearth/rust-clippy/pull/1513).However, it will add
in this macro invocation
note for every error on syntax-sugar span, which is unhelpful. The 2nd commit removes them.