Add additional tests for type alias impl trait coherence
This commit is contained in:
parent
33e1dd7864
commit
61cfe92a99
4 changed files with 71 additions and 0 deletions
23
src/test/ui/impl-trait/auto-trait.rs
Normal file
23
src/test/ui/impl-trait/auto-trait.rs
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
// Tests that type alias impls traits do not leak auto-traits for
|
||||||
|
// the purposes of coherence checking
|
||||||
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
||||||
|
trait OpaqueTrait { }
|
||||||
|
impl<T> OpaqueTrait for T { }
|
||||||
|
type OpaqueType = impl OpaqueTrait;
|
||||||
|
fn mk_opaque() -> OpaqueType { () }
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct D<T>(T);
|
||||||
|
|
||||||
|
trait AnotherTrait { }
|
||||||
|
impl<T: Send> AnotherTrait for T { }
|
||||||
|
|
||||||
|
// This is in error, because we cannot assume that `OpaqueType: !Send`.
|
||||||
|
// (We treat opaque types as "foreign types" that could grow more impls
|
||||||
|
// in the future.)
|
||||||
|
impl AnotherTrait for D<OpaqueType> {
|
||||||
|
//~^ ERROR conflicting implementations of trait `AnotherTrait` for type `D<OpaqueType>`
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
12
src/test/ui/impl-trait/auto-trait.stderr
Normal file
12
src/test/ui/impl-trait/auto-trait.stderr
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
error[E0119]: conflicting implementations of trait `AnotherTrait` for type `D<OpaqueType>`:
|
||||||
|
--> $DIR/auto-trait.rs:19:1
|
||||||
|
|
|
||||||
|
LL | impl<T: Send> AnotherTrait for T { }
|
||||||
|
| -------------------------------- first implementation here
|
||||||
|
...
|
||||||
|
LL | impl AnotherTrait for D<OpaqueType> {
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `D<OpaqueType>`
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0119`.
|
22
src/test/ui/impl-trait/negative-reasoning.rs
Normal file
22
src/test/ui/impl-trait/negative-reasoning.rs
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
// Tests that we cannot assume that an opaque type does *not* implement some
|
||||||
|
// other trait
|
||||||
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
||||||
|
trait OpaqueTrait { }
|
||||||
|
impl<T> OpaqueTrait for T { }
|
||||||
|
type OpaqueType = impl OpaqueTrait;
|
||||||
|
fn mk_opaque() -> OpaqueType { () }
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct D<T>(T);
|
||||||
|
|
||||||
|
trait AnotherTrait { }
|
||||||
|
impl<T: std::fmt::Debug> AnotherTrait for T { }
|
||||||
|
|
||||||
|
|
||||||
|
// This is in error, because we cannot assume that `OpaqueType: !Debug`
|
||||||
|
impl AnotherTrait for D<OpaqueType> {
|
||||||
|
//~^ ERROR conflicting implementations of trait `AnotherTrait` for type `D<OpaqueType>`
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
14
src/test/ui/impl-trait/negative-reasoning.stderr
Normal file
14
src/test/ui/impl-trait/negative-reasoning.stderr
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
error[E0119]: conflicting implementations of trait `AnotherTrait` for type `D<OpaqueType>`:
|
||||||
|
--> $DIR/negative-reasoning.rs:18:1
|
||||||
|
|
|
||||||
|
LL | impl<T: std::fmt::Debug> AnotherTrait for T { }
|
||||||
|
| ------------------------------------------- first implementation here
|
||||||
|
...
|
||||||
|
LL | impl AnotherTrait for D<OpaqueType> {
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `D<OpaqueType>`
|
||||||
|
|
|
||||||
|
= note: upstream crates may add a new impl of trait `std::fmt::Debug` for type `OpaqueType` in future versions
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0119`.
|
Loading…
Reference in a new issue