-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
diagnostics: avoid syntactically invalid suggestion in if conditionals
Fixes #101065
- Loading branch information
Showing
4 changed files
with
61 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// check-fail | ||
// run-rustfix | ||
|
||
enum FakeResult<T> { | ||
Ok(T) | ||
} | ||
|
||
fn main() { | ||
let _x = if true { | ||
FakeResult::Ok(FakeResult::Ok(())) | ||
} else { | ||
FakeResult::Ok(FakeResult::Ok(())) //~ERROR E0308 | ||
}; | ||
} |
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,14 @@ | ||
// check-fail | ||
// run-rustfix | ||
|
||
enum FakeResult<T> { | ||
Ok(T) | ||
} | ||
|
||
fn main() { | ||
let _x = if true { | ||
FakeResult::Ok(FakeResult::Ok(())) | ||
} else { | ||
FakeResult::Ok(()) //~ERROR E0308 | ||
}; | ||
} |
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,23 @@ | ||
error[E0308]: `if` and `else` have incompatible types | ||
--> $DIR/issue-101065.rs:12:9 | ||
| | ||
LL | let _x = if true { | ||
| ______________- | ||
LL | | FakeResult::Ok(FakeResult::Ok(())) | ||
| | ---------------------------------- expected because of this | ||
LL | | } else { | ||
LL | | FakeResult::Ok(()) | ||
| | ^^^^^^^^^^^^^^^^^^ expected enum `FakeResult`, found `()` | ||
LL | | }; | ||
| |_____- `if` and `else` have incompatible types | ||
| | ||
= note: expected enum `FakeResult<FakeResult<()>>` | ||
found enum `FakeResult<()>` | ||
help: try wrapping the expression in `FakeResult::Ok` | ||
| | ||
LL | FakeResult::Ok(FakeResult::Ok(())) | ||
| +++++++++++++++ + | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |