Add more tests
This commit is contained in:
parent
4a86ef6f4c
commit
f5f298dad4
26
tests/ui/impl-trait/unsized_coercion.next.stderr
Normal file
26
tests/ui/impl-trait/unsized_coercion.next.stderr
Normal file
@ -0,0 +1,26 @@
|
||||
error[E0271]: type mismatch resolving `impl Trait <: dyn Trait`
|
||||
--> $DIR/unsized_coercion.rs:14:17
|
||||
|
|
||||
LL | let x = hello();
|
||||
| ^^^^^^^ types differ
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/unsized_coercion.rs:18:14
|
||||
|
|
||||
LL | fn hello() -> Box<impl Trait> {
|
||||
| ---------- the expected opaque type
|
||||
...
|
||||
LL | Box::new(1u32)
|
||||
| -------- ^^^^ types differ
|
||||
| |
|
||||
| arguments to this function are incorrect
|
||||
|
|
||||
= note: expected opaque type `impl Trait`
|
||||
found type `u32`
|
||||
note: associated function defined here
|
||||
--> $SRC_DIR/alloc/src/boxed.rs:LL:COL
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0271, E0308.
|
||||
For more information about an error, try `rustc --explain E0271`.
|
21
tests/ui/impl-trait/unsized_coercion.rs
Normal file
21
tests/ui/impl-trait/unsized_coercion.rs
Normal file
@ -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) //[next]~ ERROR: mismatched types
|
||||
}
|
||||
|
||||
fn main() {}
|
12
tests/ui/impl-trait/unsized_coercion2.old.stderr
Normal file
12
tests/ui/impl-trait/unsized_coercion2.old.stderr
Normal file
@ -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
tests/ui/impl-trait/unsized_coercion2.rs
Normal file
21
tests/ui/impl-trait/unsized_coercion2.rs
Normal file
@ -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() {}
|
Loading…
Reference in New Issue
Block a user