Parse expression after else as a condition if followed by {#97298
Merged
bors merged 1 commit intorust-lang:masterfrom May 24, 2022
Merged
Parse expression after else as a condition if followed by {#97298bors merged 1 commit intorust-lang:masterfrom
else as a condition if followed by {#97298bors merged 1 commit intorust-lang:masterfrom
Conversation
Contributor
|
r? @davidtwco (rust-highfive has picked a reviewer for you, use r? to override) |
davidtwco
requested changes
May 23, 2022
Member
davidtwco
left a comment
There was a problem hiding this comment.
One suggestion, otherwise looks good to me.
fmease
reviewed
May 23, 2022
0246585 to
9be37b2
Compare
Contributor
Author
|
@rustbot ready |
davidtwco
approved these changes
May 24, 2022
Member
|
@bors r+ |
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 `{`
Fixes rust-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 `{`
Fixes rust-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
estebank
reviewed
May 24, 2022
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 :)
neoeinstein
reviewed
May 25, 2022
| .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`", |
Contributor
Author
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 free
to 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.