diff --git a/src/test/ui/impl-trait/auto-trait.rs b/src/test/ui/impl-trait/auto-trait.rs new file mode 100644 index 0000000000000..c767578120883 --- /dev/null +++ b/src/test/ui/impl-trait/auto-trait.rs @@ -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 OpaqueTrait for T { } +type OpaqueType = impl OpaqueTrait; +fn mk_opaque() -> OpaqueType { () } + +#[derive(Debug)] +struct D(T); + +trait AnotherTrait { } +impl 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 { + //~^ ERROR conflicting implementations of trait `AnotherTrait` for type `D` +} + +fn main() {} diff --git a/src/test/ui/impl-trait/auto-trait.stderr b/src/test/ui/impl-trait/auto-trait.stderr new file mode 100644 index 0000000000000..5e72ca7a47ba1 --- /dev/null +++ b/src/test/ui/impl-trait/auto-trait.stderr @@ -0,0 +1,12 @@ +error[E0119]: conflicting implementations of trait `AnotherTrait` for type `D`: + --> $DIR/auto-trait.rs:19:1 + | +LL | impl AnotherTrait for T { } + | -------------------------------- first implementation here +... +LL | impl AnotherTrait for D { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `D` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0119`. diff --git a/src/test/ui/impl-trait/negative-reasoning.rs b/src/test/ui/impl-trait/negative-reasoning.rs new file mode 100644 index 0000000000000..4977f9bdbacd9 --- /dev/null +++ b/src/test/ui/impl-trait/negative-reasoning.rs @@ -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 OpaqueTrait for T { } +type OpaqueType = impl OpaqueTrait; +fn mk_opaque() -> OpaqueType { () } + +#[derive(Debug)] +struct D(T); + +trait AnotherTrait { } +impl AnotherTrait for T { } + + +// This is in error, because we cannot assume that `OpaqueType: !Debug` +impl AnotherTrait for D { + //~^ ERROR conflicting implementations of trait `AnotherTrait` for type `D` +} + +fn main() {} diff --git a/src/test/ui/impl-trait/negative-reasoning.stderr b/src/test/ui/impl-trait/negative-reasoning.stderr new file mode 100644 index 0000000000000..526a664726ac2 --- /dev/null +++ b/src/test/ui/impl-trait/negative-reasoning.stderr @@ -0,0 +1,14 @@ +error[E0119]: conflicting implementations of trait `AnotherTrait` for type `D`: + --> $DIR/negative-reasoning.rs:18:1 + | +LL | impl AnotherTrait for T { } + | ------------------------------------------- first implementation here +... +LL | impl AnotherTrait for D { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `D` + | + = 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`.