Skip to content

Commit 4ffecb9

Browse files
committed
Add more tests
1 parent 0a6a35e commit 4ffecb9

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0271]: type mismatch resolving `impl Trait <: dyn Trait`
2+
--> $DIR/unsized_coercion.rs:14:17
3+
|
4+
LL | let x = hello();
5+
| ^^^^^^^ types differ
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0271`.
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//! This test checks that opaque types get unsized instead of
2+
//! constraining their hidden type to a trait object.
3+
4+
//@ revisions: next old
5+
//@[next] compile-flags: -Znext-solver
6+
//@[old] check-pass
7+
8+
trait Trait {}
9+
10+
impl Trait for u32 {}
11+
12+
fn hello() -> Box<impl Trait> {
13+
if true {
14+
let x = hello();
15+
//[next]~^ ERROR: type mismatch resolving `impl Trait <: dyn Trait`
16+
let y: Box<dyn Trait> = x;
17+
}
18+
Box::new(1u32)
19+
}
20+
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0277]: the size for values of type `impl Trait + ?Sized` cannot be known at compilation time
2+
--> $DIR/unsized_coercion2.rs:15:33
3+
|
4+
LL | let y: Box<dyn Trait> = x;
5+
| ^ doesn't have a size known at compile-time
6+
|
7+
= help: the trait `Sized` is not implemented for `impl Trait + ?Sized`
8+
= note: required for the cast from `Box<impl Trait + ?Sized>` to `Box<dyn Trait>`
9+
10+
error: aborting due to 1 previous error
11+
12+
For more information about this error, try `rustc --explain E0277`.
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//! This test checks that opaque types get unsized instead of
2+
//! constraining their hidden type to a trait object.
3+
4+
//@ revisions: next old
5+
//@[next] compile-flags: -Znext-solver
6+
//@[next] check-pass
7+
8+
trait Trait {}
9+
10+
impl Trait for u32 {}
11+
12+
fn hello() -> Box<impl Trait + ?Sized> {
13+
if true {
14+
let x = hello();
15+
let y: Box<dyn Trait> = x;
16+
//[old]~^ ERROR: the size for values of type `impl Trait + ?Sized` cannot be know
17+
}
18+
Box::new(1u32)
19+
}
20+
21+
fn main() {}

0 commit comments

Comments
 (0)