File tree 2 files changed +55
-0
lines changed
tests/ui/type-alias-impl-trait
2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change
1
+ #![ feature( impl_trait_in_assoc_type) ]
2
+
3
+ trait Foo < T > {
4
+ type Assoc ;
5
+
6
+ fn test ( ) -> u32 ;
7
+ }
8
+
9
+ struct DefinesOpaque ;
10
+ impl Foo < DefinesOpaque > for ( ) {
11
+ type Assoc = impl Sized ;
12
+
13
+ // This test's return type is `u32`, *not* the opaque that is defined above.
14
+ // Previously we were only checking that the self type of the assoc matched,
15
+ // but this doesn't account for other impls with different trait substs.
16
+ fn test ( ) -> <( ) as Foo < NoOpaques > >:: Assoc {
17
+ let _: <Self as Foo < DefinesOpaque > >:: Assoc = "" ;
18
+ //~^ ERROR mismatched types
19
+
20
+ 1
21
+ }
22
+ }
23
+
24
+ struct NoOpaques ;
25
+ impl Foo < NoOpaques > for ( ) {
26
+ type Assoc = u32 ;
27
+
28
+ fn test ( ) -> u32 {
29
+ 1
30
+ }
31
+ }
32
+
33
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error[E0308]: mismatched types
2
+ --> $DIR/not-matching-trait-refs-isnt-defining.rs:17:54
3
+ |
4
+ LL | type Assoc = impl Sized;
5
+ | ---------- the expected opaque type
6
+ ...
7
+ LL | let _: <Self as Foo<DefinesOpaque>>::Assoc = "";
8
+ | ----------------------------------- ^^ expected opaque type, found `&str`
9
+ | |
10
+ | expected due to this
11
+ |
12
+ = note: expected opaque type `<() as Foo<DefinesOpaque>>::Assoc`
13
+ found reference `&'static str`
14
+ note: this item must have the opaque type in its signature in order to be able to register hidden types
15
+ --> $DIR/not-matching-trait-refs-isnt-defining.rs:16:5
16
+ |
17
+ LL | fn test() -> <() as Foo<NoOpaques>>::Assoc {
18
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19
+
20
+ error: aborting due to previous error
21
+
22
+ For more information about this error, try `rustc --explain E0308`.
You can’t perform that action at this time.
0 commit comments