diff --git a/tests/ui/self/arbitrary-self-from-method-substs-custom-types.default.stderr b/tests/ui/self/arbitrary-self-from-method-substs-custom-types.default.stderr new file mode 100644 index 0000000000000..1ef5f1c06f3cd --- /dev/null +++ b/tests/ui/self/arbitrary-self-from-method-substs-custom-types.default.stderr @@ -0,0 +1,14 @@ +error[E0658]: `R` cannot be used as the type of `self` without the `arbitrary_self_types` feature + --> $DIR/arbitrary-self-from-method-substs-custom-types.rs:8:43 + | +LL | fn get>(self: R) -> u32 { + | ^ + | + = note: see issue #44874 for more information + = help: add `#![feature(arbitrary_self_types)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + = help: consider changing to `self`, `&self`, `&mut self`, `self: Box`, `self: Rc`, `self: Arc`, or `self: Pin

` (where P is one of the previous types except `Self`) + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/self/arbitrary-self-from-method-substs-custom-types.feature.stderr b/tests/ui/self/arbitrary-self-from-method-substs-custom-types.feature.stderr new file mode 100644 index 0000000000000..34c65e17953ce --- /dev/null +++ b/tests/ui/self/arbitrary-self-from-method-substs-custom-types.feature.stderr @@ -0,0 +1,9 @@ +error[E0308]: mismatched types + --> $DIR/arbitrary-self-from-method-substs-custom-types.rs:16:5 + | +LL | foo.get::<&Foo>(); + | ^^^ expected `&Foo`, found `Foo` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/self/arbitrary-self-from-method-substs-custom-types.rs b/tests/ui/self/arbitrary-self-from-method-substs-custom-types.rs new file mode 100644 index 0000000000000..99977ed9b8c51 --- /dev/null +++ b/tests/ui/self/arbitrary-self-from-method-substs-custom-types.rs @@ -0,0 +1,18 @@ +//@ revisions: default feature +#![cfg_attr(feature, feature(arbitrary_self_types))] + +use std::ops::Deref; + +struct Foo(u32); +impl Foo { + fn get>(self: R) -> u32 { + //[default]~^ ERROR: `R` cannot be used as the type of `self` + self.0 + } +} + +fn main() { + let mut foo = Foo(1); + foo.get::<&Foo>(); + //[feature]~^ ERROR mismatched types +} diff --git a/tests/ui/self/arbitrary-self-from-method-substs-no-turbofish.default.stderr b/tests/ui/self/arbitrary-self-from-method-substs-no-turbofish.default.stderr new file mode 100644 index 0000000000000..0b91b030937a3 --- /dev/null +++ b/tests/ui/self/arbitrary-self-from-method-substs-no-turbofish.default.stderr @@ -0,0 +1,43 @@ +error[E0658]: `::Receiver` cannot be used as the type of `self` without the `arbitrary_self_types` feature + --> $DIR/arbitrary-self-from-method-substs-no-turbofish.rs:13:36 + | +LL | fn get(self: FR::Receiver, other: FR) -> u32 { + | ^^^^^^^^^^^^ + | + = note: see issue #44874 for more information + = help: add `#![feature(arbitrary_self_types)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + = help: consider changing to `self`, `&self`, `&mut self`, `self: Box`, `self: Rc`, `self: Arc`, or `self: Pin

` (where P is one of the previous types except `Self`) + +error[E0271]: type mismatch resolving `::Receiver == Foo` + --> $DIR/arbitrary-self-from-method-substs-no-turbofish.rs:36:9 + | +LL | foo.get(Silly); + | ^^^ type mismatch resolving `::Receiver == Foo` + | +note: expected this to be `SmartPtr` + --> $DIR/arbitrary-self-from-method-substs-no-turbofish.rs:29:21 + | +LL | type Receiver = SmartPtr; + | ^^^^^^^^^^^^^ + = note: expected struct `SmartPtr` + found struct `Foo` + +error[E0271]: type mismatch resolving `::Receiver == &Foo` + --> $DIR/arbitrary-self-from-method-substs-no-turbofish.rs:40:9 + | +LL | foo.get(Silly); + | ^^^ type mismatch resolving `::Receiver == &Foo` + | +note: expected this to be `SmartPtr` + --> $DIR/arbitrary-self-from-method-substs-no-turbofish.rs:29:21 + | +LL | type Receiver = SmartPtr; + | ^^^^^^^^^^^^^ + = note: expected struct `SmartPtr` + found reference `&Foo` + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0271, E0658. +For more information about an error, try `rustc --explain E0271`. diff --git a/tests/ui/self/arbitrary-self-from-method-substs-no-turbofish.feature.stderr b/tests/ui/self/arbitrary-self-from-method-substs-no-turbofish.feature.stderr new file mode 100644 index 0000000000000..14c8fd361e766 --- /dev/null +++ b/tests/ui/self/arbitrary-self-from-method-substs-no-turbofish.feature.stderr @@ -0,0 +1,31 @@ +error[E0271]: type mismatch resolving `::Receiver == Foo` + --> $DIR/arbitrary-self-from-method-substs-no-turbofish.rs:36:9 + | +LL | foo.get(Silly); + | ^^^ type mismatch resolving `::Receiver == Foo` + | +note: expected this to be `SmartPtr` + --> $DIR/arbitrary-self-from-method-substs-no-turbofish.rs:29:21 + | +LL | type Receiver = SmartPtr; + | ^^^^^^^^^^^^^ + = note: expected struct `SmartPtr` + found struct `Foo` + +error[E0271]: type mismatch resolving `::Receiver == &Foo` + --> $DIR/arbitrary-self-from-method-substs-no-turbofish.rs:40:9 + | +LL | foo.get(Silly); + | ^^^ type mismatch resolving `::Receiver == &Foo` + | +note: expected this to be `SmartPtr` + --> $DIR/arbitrary-self-from-method-substs-no-turbofish.rs:29:21 + | +LL | type Receiver = SmartPtr; + | ^^^^^^^^^^^^^ + = note: expected struct `SmartPtr` + found reference `&Foo` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0271`. diff --git a/tests/ui/self/arbitrary-self-from-method-substs-no-turbofish.rs b/tests/ui/self/arbitrary-self-from-method-substs-no-turbofish.rs new file mode 100644 index 0000000000000..0dda15ee09b16 --- /dev/null +++ b/tests/ui/self/arbitrary-self-from-method-substs-no-turbofish.rs @@ -0,0 +1,42 @@ +//@ revisions: default feature +#![cfg_attr(feature, feature(arbitrary_self_types))] + +use std::ops::Deref; +use std::marker::PhantomData; + +trait FindReceiver { + type Receiver: Deref; +} + +struct Foo(u32); +impl Foo { + fn get(self: FR::Receiver, other: FR) -> u32 { + //[default]~^ ERROR: `::Receiver` cannot be used as the type of `self` + 42 + } +} + +struct SmartPtr(T); +impl Deref for SmartPtr { + type Target = T; + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +struct Silly; +impl FindReceiver for Silly { + type Receiver = SmartPtr; +} + +fn main() { + let mut foo = Foo(1); + // This test is slightly contrived in an attempt to generate a mismatched types + // error for the self type below, without using the turbofish. + foo.get(Silly); + //~^ ERROR type mismatch + let mut foo = Foo(1); + let foo = &foo; + foo.get(Silly); + //~^ ERROR type mismatch +} diff --git a/tests/ui/self/arbitrary_self_types_mismatched.rs b/tests/ui/self/arbitrary_self_types_mismatched.rs new file mode 100644 index 0000000000000..6c1819513e309 --- /dev/null +++ b/tests/ui/self/arbitrary_self_types_mismatched.rs @@ -0,0 +1,38 @@ +#![feature(arbitrary_self_types)] + +use std::ops::Deref; + +struct SmartPtr<'a, T: ?Sized>(&'a T); + +impl<'a, T: ?Sized> Deref for SmartPtr<'a, T> { + type Target = T; + fn deref(&self) -> &Self::Target { + unimplemented!() + } +} + +struct SmartPtr2<'a, T: ?Sized>(&'a T); + +impl<'a, T: ?Sized> Deref for SmartPtr2<'a, T> { + type Target = T; + fn deref(&self) -> &Self::Target { + unimplemented!() + } +} + + +struct Foo(u32); +impl Foo { + fn a>(self: R) { } +} + +fn main() { + let foo = Foo(1); + let smart_ptr = SmartPtr(&foo); + let smart_ptr2 = SmartPtr2(&foo); + smart_ptr.a(); // this compiles + smart_ptr.a::>(); + //~^ ERROR mismatched types + smart_ptr.a::<&Foo>(); + //~^ ERROR mismatched types +}