-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Increase accuracy of if
condition misparse suggestion
#133051
Conversation
r? @Nadrieril rustbot has assigned @Nadrieril. Use |
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.
Thanks! These suggestions are best-effort so that looks good to me. I have one uncertainty (heh) regarding how certain the "try using xxx" diagnostics sounds, but otherwise LGTM. The wording discussions are not blocking, if you prefer the current wording that's fine with me too, then just r=me.
{ | ||
// These are more likely to have been meant as a block body. | ||
e.multipart_suggestion( | ||
"try placing this code inside a block", |
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.
Discussion [UNCERTAINTY 1/2]: "try placing this code inside a block" -> "maybe try placing this code inside a block"? My first reaction when reading this immediately is that it feels like it sounds too certain.
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 think the "try..." wording is what we used to use back in the pre-2018 era, and had slowly tried to move away from it. Looking at this again, what do you think of "you might have meant to write this statement/expression as part of a new block" or similar?
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 sounds good to me yeah
(token::OpenDelim(Delimiter::Brace), _) => {} | ||
(_, _) => { | ||
e.multipart_suggestion( | ||
"try placing this code inside a block", |
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.
Discussion [UNCERTAINTY 2/2]: ditto
r? jieyouxu |
@rustbot author |
// Speculative; has been misleading in the past (#46836). | ||
Applicability::MaybeIncorrect, | ||
); | ||
match (&self.token.kind, &stmt.kind) { |
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's 70 new lines of code, more than doubling the size of a nontrivial function. Maybe split parts out into appropriately named function(s)?
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.
Thanks, you can r=me after pulling out the suggestion into a helper (or a few helpers) as per oli's suggestion.
Look at the expression that was parsed when trying to recover from a bad `if` condition to determine what was likely intended by the user beyond "maybe this was meant to be an `else` body". ``` error: expected `{`, found `map` --> $DIR/missing-dot-on-if-condition-expression-fixable.rs:4:30 | LL | for _ in [1, 2, 3].iter()map(|x| x) {} | ^^^ expected `{` | help: you might have meant to write a method call | LL | for _ in [1, 2, 3].iter().map(|x| x) {} | + ```
If a macro statement has been parsed after `else`, suggest a missing `if`: ``` error: expected `{`, found `falsy` --> $DIR/else-no-if.rs:47:12 | LL | } else falsy! {} { | ---- ^^^^^ | | | expected an `if` or a block after this `else` | help: add an `if` if this is the condition of a chained `else if` statement | LL | } else if falsy! {} { | ++ ```
fcc3bc5
to
6913194
Compare
@bors r=jieyouxu |
🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened. |
Rollup of 6 pull requests Successful merges: - rust-lang#133029 (ABI checks: add support for some tier3 arches, warn on others.) - rust-lang#133051 (Increase accuracy of `if` condition misparse suggestion) - rust-lang#133060 (Trim whitespace in RemoveLet primary span) - rust-lang#133093 (Let chains tests) - rust-lang#133116 (stabilize const_ptr_is_null) - rust-lang#133126 (alloc: fix `String`'s doc) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#133051 - estebank:cond-misparse, r=jieyouxu Increase accuracy of `if` condition misparse suggestion Fix rust-lang#132656. Look at the expression that was parsed when trying to recover from a bad `if` condition to determine what was likely intended by the user beyond "maybe this was meant to be an `else` body". ``` error: expected `{`, found `map` --> $DIR/missing-dot-on-if-condition-expression-fixable.rs:4:30 | LL | for _ in [1, 2, 3].iter()map(|x| x) {} | ^^^ expected `{` | help: you might have meant to write a method call | LL | for _ in [1, 2, 3].iter().map(|x| x) {} | + ``` If a macro statement has been parsed after `else`, suggest a missing `if`: ``` error: expected `{`, found `falsy` --> $DIR/else-no-if.rs:47:12 | LL | } else falsy! {} { | ---- ^^^^^ | | | expected an `if` or a block after this `else` | help: add an `if` if this is the condition of a chained `else if` statement | LL | } else if falsy! {} { | ++ ```
Fix #132656.
Look at the expression that was parsed when trying to recover from a bad
if
condition to determine what was likely intended by the user beyond "maybe this was meant to be anelse
body".If a macro statement has been parsed after
else
, suggest a missingif
: