forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#126455 - surechen:fix_126222, r=estebank For [E0308]: mismatched types, when expr is in an arm's body, not add semicolon ';' at the end of it. For [E0308]: mismatched types, when expr is in an arm's body, and it is the end expr without a semicolon of the block, not add semicolon ';' at the end of it. fixes rust-lang#126222 <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r? <reviewer name> -->
- Loading branch information
Showing
4 changed files
with
170 additions
and
9 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
34 changes: 34 additions & 0 deletions
34
tests/ui/mismatched_types/mismatched-types-issue-126222.fixed
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,34 @@ | ||
//@ run-rustfix | ||
#![allow(unreachable_code, dead_code)] | ||
|
||
fn main() { | ||
fn mismatch_types1() -> i32 { | ||
match 1 { | ||
x => return dbg!(x), //~ ERROR mismatched types | ||
} | ||
todo!() | ||
} | ||
|
||
fn mismatch_types2() -> i32 { | ||
match 2 { | ||
x => { | ||
return dbg!(x) //~ ERROR mismatched types | ||
} | ||
} | ||
todo!() | ||
} | ||
|
||
fn mismatch_types3() -> i32 { | ||
match 1 { | ||
_ => return dbg!(1) //~ ERROR mismatched types | ||
} | ||
todo!() | ||
} | ||
|
||
fn mismatch_types4() -> i32 { | ||
match 1 { | ||
_ => {return dbg!(1)} //~ ERROR mismatched types | ||
} | ||
todo!() | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
tests/ui/mismatched_types/mismatched-types-issue-126222.rs
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,34 @@ | ||
//@ run-rustfix | ||
#![allow(unreachable_code, dead_code)] | ||
|
||
fn main() { | ||
fn mismatch_types1() -> i32 { | ||
match 1 { | ||
x => dbg!(x), //~ ERROR mismatched types | ||
} | ||
todo!() | ||
} | ||
|
||
fn mismatch_types2() -> i32 { | ||
match 2 { | ||
x => { | ||
dbg!(x) //~ ERROR mismatched types | ||
} | ||
} | ||
todo!() | ||
} | ||
|
||
fn mismatch_types3() -> i32 { | ||
match 1 { | ||
_ => dbg!(1) //~ ERROR mismatched types | ||
} | ||
todo!() | ||
} | ||
|
||
fn mismatch_types4() -> i32 { | ||
match 1 { | ||
_ => {dbg!(1)} //~ ERROR mismatched types | ||
} | ||
todo!() | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
tests/ui/mismatched_types/mismatched-types-issue-126222.stderr
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,51 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/mismatched-types-issue-126222.rs:7:18 | ||
| | ||
LL | x => dbg!(x), | ||
| ^^^^^^^ expected `()`, found integer | ||
| | ||
= note: this error originates in the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
help: you might have meant to return this value | ||
| | ||
LL | x => return dbg!(x), | ||
| ++++++ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/mismatched-types-issue-126222.rs:15:17 | ||
| | ||
LL | dbg!(x) | ||
| ^^^^^^^ expected `()`, found integer | ||
| | ||
= note: this error originates in the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
help: you might have meant to return this value | ||
| | ||
LL | return dbg!(x) | ||
| ++++++ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/mismatched-types-issue-126222.rs:23:18 | ||
| | ||
LL | _ => dbg!(1) | ||
| ^^^^^^^ expected `()`, found integer | ||
| | ||
= note: this error originates in the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
help: you might have meant to return this value | ||
| | ||
LL | _ => return dbg!(1) | ||
| ++++++ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/mismatched-types-issue-126222.rs:30:19 | ||
| | ||
LL | _ => {dbg!(1)} | ||
| ^^^^^^^ expected `()`, found integer | ||
| | ||
= note: this error originates in the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
help: you might have meant to return this value | ||
| | ||
LL | _ => {return dbg!(1)} | ||
| ++++++ | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |