-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Detect missing if let
or let-else
#145582
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
Conversation
r? @SparrowLii rustbot has assigned @SparrowLii. Use |
I'd like to have a review on it |
This comment has been minimized.
This comment has been minimized.
During `let` binding parse error and encountering a block, detect if there is a likely missing `if` or `else`: ``` error: expected one of `.`, `;`, `?`, `else`, or an operator, found `{` --> $DIR/missing-if-let-or-let-else.rs:14:25 | LL | let Some(x) = foo() { | ^ expected one of `.`, `;`, `?`, `else`, or an operator | help: you might have meant to use `if let` | LL | if let Some(x) = foo() { | ++ help: alternatively, you might have meant to use `let else` | LL | let Some(x) = foo() else { | ++++ ```
If we wanted to improve the handling of these, then we would have to actually add a new error recovery AST node, with all the information that an |
| | ||
help: you might have meant to use `let else` | ||
| | ||
LL | let Some(x) = foo() else { |
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.
if we suggest add else
here, a following error missing ;
will comes after applying the fix.
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.
so the correct code maybe:
let Some(x) = foo() else {
return;
}; // need `;` here
i'm not sure whether we should also suggest the ;
at the same time, maybe goes too far.
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.
emm, this code is also valid 😀
fn b() {
if let Some(x) = foo() {
return;
};
}
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.
The last example is valid, but unless x
is used, then the intent seems muddled. We can of course just suggest if-let in all cases.
Keep in mind that a person is still in the loop. If they didn't mean let-else, then it would give them enough information to realize that the code they wrote wasn't 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.
yeah, make sense.
@bors r=chenyukang |
☀️ Test successful - checks-actions |
What is this?This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.Comparing cd60c60 (parent) -> 64a99db (this PR) Test differencesShow 4 test diffsStage 1
Stage 2
Additionally, 2 doctest diffs were found. These are ignored, as they are noisy. Job group index
Test dashboardRun cargo run --manifest-path src/ci/citool/Cargo.toml -- \
test-dashboard 64a99db105f45ea3304732ffb51066c3b5193bc7 --output-dir test-dashboard And then open Job duration changes
How to interpret the job duration changes?Job durations can vary a lot, based on the actual runner instance |
Finished benchmarking commit (64a99db): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesResults (primary 2.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 466.008s -> 466.641s (0.14%) |
During
let
binding parse error and encountering a block, detect if there is a likely missingif
orelse
:Fix #107806.