File tree 2 files changed +55
-0
lines changed
2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change
1
+ //! Test that we allow unsizing `Trait<Concrete>` to `Trait<Opaque>` and vice versa
2
+
3
+ trait Trait < T > { }
4
+
5
+ impl < T , U > Trait < T > for U { }
6
+
7
+ fn hello ( ) -> & ' static ( dyn Trait < impl Sized > + Send ) {
8
+ if false {
9
+ let x = hello ( ) ;
10
+ let _: & ' static dyn Trait < ( ) > = x;
11
+ //~^ ERROR: mismatched types
12
+ }
13
+ todo ! ( )
14
+ }
15
+
16
+ fn bye ( ) -> & ' static dyn Trait < impl Sized > {
17
+ if false {
18
+ let mut x = bye ( ) ;
19
+ let y: & ' static ( dyn Trait < ( ) > + Send ) = & ( ) ;
20
+ x = y;
21
+ //~^ ERROR: mismatched types
22
+ }
23
+ todo ! ( )
24
+ }
25
+
26
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error[E0308]: mismatched types
2
+ --> $DIR/trait_upcasting.rs:10:41
3
+ |
4
+ LL | fn hello() -> &'static (dyn Trait<impl Sized> + Send) {
5
+ | ---------- the found opaque type
6
+ ...
7
+ LL | let _: &'static dyn Trait<()> = x;
8
+ | ---------------------- ^ expected trait `Trait<()>`, found trait `Trait<impl Sized> + Send`
9
+ | |
10
+ | expected due to this
11
+ |
12
+ = note: expected reference `&'static (dyn Trait<()> + 'static)`
13
+ found reference `&dyn Trait<impl Sized> + Send`
14
+
15
+ error[E0308]: mismatched types
16
+ --> $DIR/trait_upcasting.rs:20:13
17
+ |
18
+ LL | fn bye() -> &'static dyn Trait<impl Sized> {
19
+ | ---------- the expected opaque type
20
+ ...
21
+ LL | x = y;
22
+ | ^ expected trait `Trait<impl Sized>`, found trait `Trait<()> + Send`
23
+ |
24
+ = note: expected reference `&dyn Trait<impl Sized>`
25
+ found reference `&'static (dyn Trait<()> + Send + 'static)`
26
+
27
+ error: aborting due to 2 previous errors
28
+
29
+ For more information about this error, try `rustc --explain E0308`.
You can’t perform that action at this time.
0 commit comments