rust/tests/ui/impl-trait/unsized_coercion.rs

23 lines
620 B
Rust
Raw Normal View History

2024-05-28 10:38:18 -05:00
//! 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> {
2024-10-14 12:04:10 -05:00
//[next]~^ ERROR the size for values of type `dyn Trait` cannot be known at compilation time
2024-05-28 10:38:18 -05:00
if true {
let x = hello();
2024-10-14 12:04:10 -05:00
//[next]~^ ERROR: the size for values of type `dyn Trait` cannot be known at compilation time
2024-05-28 10:38:18 -05:00
let y: Box<dyn Trait> = x;
}
Box::new(1u32) //[next]~ ERROR: mismatched types
}
fn main() {}