File tree 4 files changed +71
-0
lines changed
4 files changed +71
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Tests that type alias impls traits do not leak auto-traits for
2
+ // the purposes of coherence checking
3
+ #![ feature( type_alias_impl_trait) ]
4
+
5
+ trait OpaqueTrait { }
6
+ impl < T > OpaqueTrait for T { }
7
+ type OpaqueType = impl OpaqueTrait ;
8
+ fn mk_opaque ( ) -> OpaqueType { ( ) }
9
+
10
+ #[ derive( Debug ) ]
11
+ struct D < T > ( T ) ;
12
+
13
+ trait AnotherTrait { }
14
+ impl < T : Send > AnotherTrait for T { }
15
+
16
+ // This is in error, because we cannot assume that `OpaqueType: !Send`.
17
+ // (We treat opaque types as "foreign types" that could grow more impls
18
+ // in the future.)
19
+ impl AnotherTrait for D < OpaqueType > {
20
+ //~^ ERROR conflicting implementations of trait `AnotherTrait` for type `D<OpaqueType>`
21
+ }
22
+
23
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error[E0119]: conflicting implementations of trait `AnotherTrait` for type `D<OpaqueType>`:
2
+ --> $DIR/auto-trait.rs:19:1
3
+ |
4
+ LL | impl<T: Send> AnotherTrait for T { }
5
+ | -------------------------------- first implementation here
6
+ ...
7
+ LL | impl AnotherTrait for D<OpaqueType> {
8
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `D<OpaqueType>`
9
+
10
+ error: aborting due to previous error
11
+
12
+ For more information about this error, try `rustc --explain E0119`.
Original file line number Diff line number Diff line change
1
+ // Tests that we cannot assume that an opaque type does *not* implement some
2
+ // other trait
3
+ #![ feature( type_alias_impl_trait) ]
4
+
5
+ trait OpaqueTrait { }
6
+ impl < T > OpaqueTrait for T { }
7
+ type OpaqueType = impl OpaqueTrait ;
8
+ fn mk_opaque ( ) -> OpaqueType { ( ) }
9
+
10
+ #[ derive( Debug ) ]
11
+ struct D < T > ( T ) ;
12
+
13
+ trait AnotherTrait { }
14
+ impl < T : std:: fmt:: Debug > AnotherTrait for T { }
15
+
16
+
17
+ // This is in error, because we cannot assume that `OpaqueType: !Debug`
18
+ impl AnotherTrait for D < OpaqueType > {
19
+ //~^ ERROR conflicting implementations of trait `AnotherTrait` for type `D<OpaqueType>`
20
+ }
21
+
22
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error[E0119]: conflicting implementations of trait `AnotherTrait` for type `D<OpaqueType>`:
2
+ --> $DIR/negative-reasoning.rs:18:1
3
+ |
4
+ LL | impl<T: std::fmt::Debug> AnotherTrait for T { }
5
+ | ------------------------------------------- first implementation here
6
+ ...
7
+ LL | impl AnotherTrait for D<OpaqueType> {
8
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `D<OpaqueType>`
9
+ |
10
+ = note: upstream crates may add a new impl of trait `std::fmt::Debug` for type `OpaqueType` in future versions
11
+
12
+ error: aborting due to previous error
13
+
14
+ For more information about this error, try `rustc --explain E0119`.
You can’t perform that action at this time.
0 commit comments