-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix wrong suggestions for boxed trait objects instead of impl trait
- Loading branch information
Showing
7 changed files
with
122 additions
and
31 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
23 changes: 23 additions & 0 deletions
23
src/test/ui/mismatched_types/do-not-suggest-boxed-trait-objects-instead-of-impl-trait.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,23 @@ | ||
struct S; | ||
struct Y; | ||
|
||
trait Trait {} | ||
|
||
impl Trait for Y {} | ||
|
||
fn foo() -> impl Trait { | ||
if true { | ||
S | ||
} else { | ||
Y //~ ERROR `if` and `else` have incompatible types | ||
} | ||
} | ||
|
||
fn bar() -> impl Trait { | ||
match true { | ||
true => S, | ||
false => Y, //~ ERROR `match` arms have incompatible types | ||
} | ||
} | ||
|
||
fn main() {} |
26 changes: 26 additions & 0 deletions
26
src/test/ui/mismatched_types/do-not-suggest-boxed-trait-objects-instead-of-impl-trait.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,26 @@ | ||
error[E0308]: `if` and `else` have incompatible types | ||
--> $DIR/do-not-suggest-boxed-trait-objects-instead-of-impl-trait.rs:12:9 | ||
| | ||
LL | / if true { | ||
LL | | S | ||
| | - expected because of this | ||
LL | | } else { | ||
LL | | Y | ||
| | ^ expected struct `S`, found struct `Y` | ||
LL | | } | ||
| |_____- `if` and `else` have incompatible types | ||
|
||
error[E0308]: `match` arms have incompatible types | ||
--> $DIR/do-not-suggest-boxed-trait-objects-instead-of-impl-trait.rs:19:18 | ||
| | ||
LL | / match true { | ||
LL | | true => S, | ||
| | - this is found to be of type `S` | ||
LL | | false => Y, | ||
| | ^ expected struct `S`, found struct `Y` | ||
LL | | } | ||
| |_____- `match` arms have incompatible types | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain 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
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