-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Provide better spans for the match arm without tail expression #75656
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Diagnostic enhancement explained in issue #75418. | ||
// Point at the last statement in the block if there's no tail expression, | ||
// and suggest removing the semicolon if appropriate. | ||
|
||
fn main() { | ||
let _ = match Some(42) { | ||
Some(x) => { | ||
x | ||
}, | ||
None => { | ||
0; | ||
//~^ ERROR incompatible types | ||
//~| HELP consider removing this semicolon | ||
}, | ||
}; | ||
|
||
let _ = if let Some(x) = Some(42) { | ||
x | ||
} else { | ||
0; | ||
//~^ ERROR incompatible types | ||
//~| HELP consider removing this semicolon | ||
}; | ||
|
||
let _ = match Some(42) { | ||
Some(x) => { | ||
x | ||
}, | ||
None => { | ||
(); | ||
//~^ ERROR incompatible types | ||
}, | ||
}; | ||
|
||
let _ = match Some(42) { | ||
Some(x) => { | ||
x | ||
}, | ||
None => { //~ ERROR incompatible types | ||
}, | ||
}; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
error[E0308]: `match` arms have incompatible types | ||
--> $DIR/match-incompat-type-semi.rs:11:13 | ||
| | ||
LL | let _ = match Some(42) { | ||
| _____________- | ||
LL | | Some(x) => { | ||
LL | | x | ||
| | - this is found to be of type `{integer}` | ||
LL | | }, | ||
LL | | None => { | ||
LL | | 0; | ||
| | ^- | ||
| | || | ||
| | |help: consider removing this semicolon | ||
| | expected integer, found `()` | ||
... | | ||
LL | | }, | ||
LL | | }; | ||
| |_____- `match` arms have incompatible types | ||
|
||
error[E0308]: `if` and `else` have incompatible types | ||
--> $DIR/match-incompat-type-semi.rs:20:9 | ||
| | ||
LL | let _ = if let Some(x) = Some(42) { | ||
| _____________- | ||
LL | | x | ||
| | - expected because of this | ||
LL | | } else { | ||
LL | | 0; | ||
| | ^- | ||
| | || | ||
| | |help: consider removing this semicolon | ||
| | expected integer, found `()` | ||
LL | | | ||
LL | | | ||
LL | | }; | ||
| |_____- `if` and `else` have incompatible types | ||
|
||
error[E0308]: `match` arms have incompatible types | ||
--> $DIR/match-incompat-type-semi.rs:30:13 | ||
| | ||
LL | let _ = match Some(42) { | ||
| _____________- | ||
LL | | Some(x) => { | ||
LL | | x | ||
| | - this is found to be of type `{integer}` | ||
LL | | }, | ||
LL | | None => { | ||
LL | | (); | ||
| | ^^^ expected integer, found `()` | ||
LL | | | ||
LL | | }, | ||
LL | | }; | ||
| |_____- `match` arms have incompatible types | ||
|
||
error[E0308]: `match` arms have incompatible types | ||
--> $DIR/match-incompat-type-semi.rs:39:17 | ||
| | ||
LL | let _ = match Some(42) { | ||
| _____________- | ||
LL | | Some(x) => { | ||
LL | | x | ||
| | - this is found to be of type `{integer}` | ||
LL | | }, | ||
LL | | None => { | ||
| |_________________^ | ||
LL | || }, | ||
| ||_________^ expected integer, found `()` | ||
LL | | }; | ||
| |_____- `match` arms have incompatible types | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
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.
Uh oh!
There was an error while loading. Please reload this page.