Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed May 28, 2024
1 parent 0a6a35e commit 4ffecb9
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/ui/impl-trait/unsized_coercion.next.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0271]: type mismatch resolving `impl Trait <: dyn Trait`
--> $DIR/unsized_coercion.rs:14:17
|
LL | let x = hello();
| ^^^^^^^ types differ

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0271`.
21 changes: 21 additions & 0 deletions tests/ui/impl-trait/unsized_coercion.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! This test checks that opaque types get unsized instead of
//! constraining their hidden type to a trait object.
//@ revisions: next old
//@[next] compile-flags: -Znext-solver
//@[old] check-pass

trait Trait {}

impl Trait for u32 {}

fn hello() -> Box<impl Trait> {
if true {
let x = hello();
//[next]~^ ERROR: type mismatch resolving `impl Trait <: dyn Trait`
let y: Box<dyn Trait> = x;
}
Box::new(1u32)
}

fn main() {}
12 changes: 12 additions & 0 deletions tests/ui/impl-trait/unsized_coercion2.old.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0277]: the size for values of type `impl Trait + ?Sized` cannot be known at compilation time
--> $DIR/unsized_coercion2.rs:15:33
|
LL | let y: Box<dyn Trait> = x;
| ^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `impl Trait + ?Sized`
= note: required for the cast from `Box<impl Trait + ?Sized>` to `Box<dyn Trait>`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
21 changes: 21 additions & 0 deletions tests/ui/impl-trait/unsized_coercion2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! This test checks that opaque types get unsized instead of
//! constraining their hidden type to a trait object.
//@ revisions: next old
//@[next] compile-flags: -Znext-solver
//@[next] check-pass

trait Trait {}

impl Trait for u32 {}

fn hello() -> Box<impl Trait + ?Sized> {
if true {
let x = hello();
let y: Box<dyn Trait> = x;
//[old]~^ ERROR: the size for values of type `impl Trait + ?Sized` cannot be know
}
Box::new(1u32)
}

fn main() {}

0 comments on commit 4ffecb9

Please sign in to comment.