File tree 4 files changed +80
-0
lines changed
4 files changed +80
-0
lines changed Original file line number Diff line number Diff line change
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[E0308]: mismatched types
8
+ --> $DIR/unsized_coercion.rs:18:14
9
+ |
10
+ LL | fn hello() -> Box<impl Trait> {
11
+ | ---------- the expected opaque type
12
+ ...
13
+ LL | Box::new(1u32)
14
+ | -------- ^^^^ types differ
15
+ | |
16
+ | arguments to this function are incorrect
17
+ |
18
+ = note: expected opaque type `impl Trait`
19
+ found type `u32`
20
+ note: associated function defined here
21
+ --> $SRC_DIR/alloc/src/boxed.rs:LL:COL
22
+
23
+ error: aborting due to 2 previous errors
24
+
25
+ Some errors have detailed explanations: E0271, E0308.
26
+ For more information about an error, try `rustc --explain E0271`.
Original file line number Diff line number Diff line change
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 ) //[next]~ ERROR: mismatched types
19
+ }
20
+
21
+ fn main ( ) { }
Original file line number Diff line number Diff line change
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`.
Original file line number Diff line number Diff line change
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 ( ) { }
You can’t perform that action at this time.
0 commit comments