-
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
Add explanations and suggestions to irrefutable_let_patterns
lint
#79747
Conversation
r? @varkor (rust-highfive has picked a reviewer for you, use r? to override) |
Ugh, |
My preference would be to not add one-off links like this. Ideally, every warning should (automatically) have some way to get more information. The issue is that it is not clear exactly what that should look like. Some options that were considered:
There is some history in #48041 and #48337 about trying to reduce the verbosity with |
I based this off of errors like:
but if we want to wait for a unified approach before adding more, I'm okay with that. And I have another Con to add to using HTTP links: we currently don't check links produced in error messages, so they're prone to link rot. |
Another example:
|
I think we ought to link to the stable version of the documentation (or, even better, to the relevant version). But that aside, it seems like a link to the documentation is not the best fix for this issue. We should be suggesting the user change the |
dd64a71
to
c3367ab
Compare
Starting with a rebase. |
This comment has been minimized.
This comment has been minimized.
c3367ab
to
2b00f81
Compare
@varkor How does this look:
? I added similar notes and suggestions to if-let and if-let guard as well. Ideally they would be structured suggestions, but I think it would be tricky to recover the span information. Also, these aren't mechanical fixes which makes them more difficult to automate and not as useful to users. |
Note that the current output uses |
irrefutable_let_patterns
lint
This comment has been minimized.
This comment has been minimized.
2b00f81
to
dc9215d
Compare
Yes, that's true. This is definitely an improvement as-is. |
(I think I need to bless tests from the error message change.) |
This comment has been minimized.
This comment has been minimized.
I can squash before you |
hir::MatchSource::IfLetDesugar { .. } => { | ||
let mut diag = lint.build("irrefutable if-let pattern"); | ||
diag.note("this pattern will always match, so the if-let is useless"); | ||
diag.help("consider replacing the if-let with a 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.
diag.help("consider replacing the if-let with a let"); | |
diag.help("consider replacing the if-let with a `let`"); |
I wonder whether it would be more readable to write
diag.help("consider replacing the if-let with a let"); | |
diag.help("consider replacing the `if let` with a `let`"); |
as well.
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 intentionally removed the backticks on let
to be consistent with if-let. I thought of doing the second option you suggest, but didn't because then it would be inconsistent with the error message. I'm still open to it, I just want to make sure we don't confuse people. What do you think?
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'd be tempted to replace if-let
with `if let`
in general (including in the main error message). To me, it's slightly easier to read, and feels more consistent with other uses of code fragments in error messages.
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 like the look of if-let
, though I do think it's probably clearer as `if let`
. However, it seems like if-let
and the like are used a lot, not just in the compiler but also in documentation. So can we do that as a separate change so this one doesn't wallow too long?
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.
That works (as long as we don't overlook that let
needs to be enclosed in backticks in the message above as well).
r=me after squashing. |
Also: blocked on #82215 (not adding S-blocked since that PR will merge very soon). |
9bbd3fb
to
9eba9c8
Compare
Starting with a squash to make the rebase easier (and since I need to anyway). |
9eba9c8
to
7baf39d
Compare
Rebased. Ready for review! |
This comment has been minimized.
This comment has been minimized.
7baf39d
to
2f2653f
Compare
This comment has been minimized.
This comment has been minimized.
2f2653f
to
5d2a2a1
Compare
Thanks, looks good! @bors r+ |
📌 Commit 5d2a2a1 has been approved by |
Rollup of 10 pull requests Successful merges: - rust-lang#79747 (Add explanations and suggestions to `irrefutable_let_patterns` lint) - rust-lang#81496 (name async generators something more human friendly in type error diagnostic) - rust-lang#81873 (Add Mutex::unlock) - rust-lang#82093 (Add tests for Atomic*::fetch_{min,max}) - rust-lang#82238 (ast: Keep expansion status for out-of-line module items) - rust-lang#82245 (Do not ICE when evaluating locals' types of invalid `yield`) - rust-lang#82259 (Fix popping singleton paths in when generating E0433) - rust-lang#82261 (rustdoc: Support argument files) - rust-lang#82274 (libtest: Fix unwrap panic on duplicate TestDesc) - rust-lang#82275 (Update cargo) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Fixes #79716.