-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #75656 - tirr-c:match-suggest-semi, r=estebank
Provide better spans for the match arm without tail expression Resolves #75418. Applied the same logic in the `if`-`else` type mismatch case. r? @estebank
- Loading branch information
Showing
5 changed files
with
154 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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`. |