diff options
Diffstat (limited to 'tests/ui/self')
| -rw-r--r-- | tests/ui/self/arbitrary-self-opaque.rs | 1 | ||||
| -rw-r--r-- | tests/ui/self/arbitrary-self-opaque.stderr | 10 | ||||
| -rw-r--r-- | tests/ui/self/dyn-dispatch-requires-supertrait-norm.rs | 38 | ||||
| -rw-r--r-- | tests/ui/self/dyn-dispatch-requires-supertrait.rs | 38 |
4 files changed, 82 insertions, 5 deletions
diff --git a/tests/ui/self/arbitrary-self-opaque.rs b/tests/ui/self/arbitrary-self-opaque.rs index c26ef658b69..b176a982e5f 100644 --- a/tests/ui/self/arbitrary-self-opaque.rs +++ b/tests/ui/self/arbitrary-self-opaque.rs @@ -4,6 +4,7 @@ struct Foo; type Bar = impl Sized; impl Foo { + #[define_opaque(Bar)] fn foo(self: Bar) {} //~^ ERROR: invalid `self` parameter type: `Bar` //~| ERROR: item does not constrain diff --git a/tests/ui/self/arbitrary-self-opaque.stderr b/tests/ui/self/arbitrary-self-opaque.stderr index c75165d9f8e..36ae3d6fd02 100644 --- a/tests/ui/self/arbitrary-self-opaque.stderr +++ b/tests/ui/self/arbitrary-self-opaque.stderr @@ -1,5 +1,5 @@ error[E0307]: invalid `self` parameter type: `Bar` - --> $DIR/arbitrary-self-opaque.rs:7:18 + --> $DIR/arbitrary-self-opaque.rs:8:18 | LL | fn foo(self: Bar) {} | ^^^ @@ -7,14 +7,14 @@ LL | fn foo(self: Bar) {} = note: type of `self` must be `Self` or a type that dereferences to it = help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`) -error: item does not constrain `Bar::{opaque#0}`, but has it in its signature - --> $DIR/arbitrary-self-opaque.rs:7:8 +error: item does not constrain `Bar::{opaque#0}` + --> $DIR/arbitrary-self-opaque.rs:8:8 | LL | fn foo(self: Bar) {} | ^^^ | - = note: consider moving the opaque type's declaration and defining uses into a separate module -note: this opaque type is in the signature + = note: consider removing `#[define_opaque]` or adding an empty `#[define_opaque()]` +note: this opaque type is supposed to be constrained --> $DIR/arbitrary-self-opaque.rs:4:12 | LL | type Bar = impl Sized; diff --git a/tests/ui/self/dyn-dispatch-requires-supertrait-norm.rs b/tests/ui/self/dyn-dispatch-requires-supertrait-norm.rs new file mode 100644 index 00000000000..55c070eb036 --- /dev/null +++ b/tests/ui/self/dyn-dispatch-requires-supertrait-norm.rs @@ -0,0 +1,38 @@ +//@ check-pass + +#![feature(derive_coerce_pointee)] +#![feature(arbitrary_self_types)] + +use std::ops::Deref; +use std::marker::CoercePointee; +use std::sync::Arc; + +trait MyTrait<T> {} + +#[derive(CoercePointee)] +#[repr(transparent)] +struct MyArc<T: ?Sized + MyTrait<u8>>(Arc<T>); + +impl<T: ?Sized + MyTrait<u8>> Deref for MyArc<T> { + type Target = T; + fn deref(&self) -> &T { + &self.0 + } +} + +trait Mirror { + type Assoc; +} +impl<T> Mirror for T { + type Assoc = T; +} + +// This is variant on "tests/ui/self/dyn-dispatch-requires-supertrait.rs" but with +// a supertrait that requires normalization to match the pred in the old solver. +trait MyOtherTrait: MyTrait<<u8 as Mirror>::Assoc> { + fn foo(self: MyArc<Self>); +} + +fn test(_: MyArc<dyn MyOtherTrait>) {} + +fn main() {} diff --git a/tests/ui/self/dyn-dispatch-requires-supertrait.rs b/tests/ui/self/dyn-dispatch-requires-supertrait.rs new file mode 100644 index 00000000000..f2661c406fe --- /dev/null +++ b/tests/ui/self/dyn-dispatch-requires-supertrait.rs @@ -0,0 +1,38 @@ +//@ check-pass + +#![feature(derive_coerce_pointee)] +#![feature(arbitrary_self_types)] + +use std::ops::Deref; +use std::marker::CoercePointee; +use std::sync::Arc; + +trait MyTrait {} + +#[derive(CoercePointee)] +#[repr(transparent)] +struct MyArc<T> +where + T: MyTrait + ?Sized, +{ + inner: Arc<T> +} + +impl<T: MyTrait + ?Sized> Deref for MyArc<T> { + type Target = T; + fn deref(&self) -> &T { + &self.inner + } +} + +// Proving that `MyArc<Self>` is dyn-dispatchable requires proving `MyArc<T>` implements +// `DispatchFromDyn<MyArc<U>>`. The `DispatchFromDyn` impl that is generated from the +// `CoercePointee` implementation requires the pointee impls `MyTrait`, but previously we +// were only assuming the pointee impl'd `MyOtherTrait`. Elaboration comes to the rescue here. +trait MyOtherTrait: MyTrait { + fn foo(self: MyArc<Self>); +} + +fn test(_: MyArc<dyn MyOtherTrait>) {} + +fn main() {} |
