-
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.
Rollup merge of #112215 - compiler-errors:check-sized-better, r=cjgillot
only suppress coercion error if type is definitely unsized we previously suppressed coercion errors when the return type was `dyn Trait` because we expect a far more descriptive `Sized` trait error to be emitted instead, however the code that does this suppression does not consider where-clause predicates since it just looked at the HIR. let's do that instead by creating an obligation and checking if it may hold. fixes #110683 fixes #112208
- Loading branch information
Showing
5 changed files
with
81 additions
and
11 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,11 @@ | ||
trait Trait<T> {} | ||
|
||
fn foo<T>() -> dyn Trait<T> | ||
where | ||
dyn Trait<T>: Sized, // pesky sized predicate | ||
{ | ||
42 | ||
//~^ ERROR mismatched types | ||
} | ||
|
||
fn main() {} |
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,15 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/return-dyn-type-mismatch-2.rs:7:5 | ||
| | ||
LL | fn foo<T>() -> dyn Trait<T> | ||
| ------------ expected `(dyn Trait<T> + 'static)` because of return type | ||
... | ||
LL | 42 | ||
| ^^ expected `dyn Trait`, found integer | ||
| | ||
= note: expected trait object `(dyn Trait<T> + 'static)` | ||
found type `{integer}` | ||
|
||
error: aborting due to previous error | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
pub trait TestTrait { | ||
type MyType; | ||
|
||
fn func() -> Option<Self> | ||
where | ||
Self: Sized; | ||
} | ||
|
||
impl<T> dyn TestTrait<MyType = T> | ||
where | ||
Self: Sized, // pesky sized predicate | ||
{ | ||
fn other_func() -> dyn TestTrait<MyType = T> { | ||
match Self::func() { | ||
None => None, | ||
//~^ ERROR mismatched types | ||
} | ||
} | ||
} | ||
|
||
fn main() {} |
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,15 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/return-dyn-type-mismatch.rs:15:21 | ||
| | ||
LL | fn other_func() -> dyn TestTrait<MyType = T> { | ||
| ------------------------- expected `(dyn TestTrait<MyType = T> + 'static)` because of return type | ||
LL | match Self::func() { | ||
LL | None => None, | ||
| ^^^^ expected `dyn TestTrait`, found `Option<_>` | ||
| | ||
= note: expected trait object `(dyn TestTrait<MyType = T> + 'static)` | ||
found enum `Option<_>` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |