Uh oh!
There was an error while loading. Please reload this page.
Parse expression after else as a condition if followed by { - #97298
Merged
Conversation
rust-highfive
commented
May 22, 2022
Contributor
r? @davidtwco (rust-highfive has picked a reviewer for you, use r? to override) |
davidtwco
requested changes
May 23, 2022
davidtwco
left a comment
Member
There was a problem hiding this comment.
One suggestion, otherwise looks good to me.
Uh oh!
There was an error while loading. Please reload this page.
fmease
reviewed
May 23, 2022
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
compiler-errorsforce-pushed
the
if-else-stmt-braces
branch
from
May 24, 2022 04:10
0246585 to
9be37b2Comparecompiler-errors
commented
May 24, 2022
ContributorAuthor
@rustbot ready |
davidtwco
approved these changes
May 24, 2022
davidtwco
commented
May 24, 2022
Member
@bors r+ |
bors
commented
May 24, 2022
Collaborator
📌 Commit 9be37b2 has been approved by |
Dylan-DPC added a commit
to Dylan-DPC/rust
that referenced
this pull request
May 24, 2022
…, r=davidtwco
Parse expression after `else` as a condition if followed by `{`
Fixesrust-lang#49361.
Two things:
1. This wording needs help. I can never find a natural/intuitive phrasing when I write diagnostics 😅
2. Do we even want to show the "wrap in braces" case? I would assume most of the time the "add an `if`" case is the right one.Dylan-DPC added a commit
to Dylan-DPC/rust
that referenced
this pull request
May 24, 2022
…, r=davidtwco
Parse expression after `else` as a condition if followed by `{`
Fixesrust-lang#49361.
Two things:
1. This wording needs help. I can never find a natural/intuitive phrasing when I write diagnostics 😅
2. Do we even want to show the "wrap in braces" case? I would assume most of the time the "add an `if`" case is the right one.bors added a commit
to rust-lang-ci/rust
that referenced
this pull request
May 24, 2022
Rollup of 4 pull requests Successful merges: - rust-lang#97288 (Lifetime variance fixes for rustdoc) - rust-lang#97298 (Parse expression after `else` as a condition if followed by `{`) - rust-lang#97308 (Stabilize `cell_filter_map`) - rust-lang#97321 (explain how to turn integers into fn ptrs) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Comment on lines
+2284
to
+2289
| Ok(cond) | ||
| // If it's not a free-standing expression, and is followed by a block, | ||
| // then it's very likely the condition to an `else if`. | ||
| if self.check(&TokenKind::OpenDelim(Delimiter::Brace)) | ||
| && classify::expr_requires_semi_to_be_stmt(&cond) => | ||
| { |
Contributor
There was a problem hiding this comment.
Given all the checks you have here...
Comment on lines
+2297
to
+2304
| ).multipart_suggestion( | ||
| "... otherwise, place this expression inside of a block if it is not an `if` condition", | ||
| vec![ | ||
| (cond.span.shrink_to_lo(), "{ ".to_string()), | ||
| (cond.span.shrink_to_hi(), " }".to_string()), | ||
| ], | ||
| Applicability::MaybeIncorrect, | ||
| ) |
Contributor
There was a problem hiding this comment.
...I would have likely skipped this suggestion :)
| .span_label(else_span, "expected an `if` or a block after this `else`") | ||
| .span_suggestion( | ||
| cond.span.shrink_to_lo(), | ||
| "add an `if` if this is the condition to an chained `if` statement after the `else`", |
There was a problem hiding this comment.
Suggested change
| "add an `if` if this is the condition to an chained `if` statement after the `else`", | |
| "add an `if` if this is the condition to a chained `if` statement after the `else`", |
ContributorAuthor
Dylan-DPC added a commit
to Dylan-DPC/rust
that referenced
this pull request
May 25, 2022
…an-DPC Minor improvement on else-no-if diagnostic Don't suggest wrapping in block since it's highly likely to be a missing `if` after `else`. Also rework message a bit (open to further suggestions). cc: rust-lang#97298 (comment) r? `@estebank`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes#49361.
Two things:
if" case is the right one.