From 9835e2ae736235810b4ea1c162ca5e65c547e770 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 18 May 2024 04:49:50 +0200 Subject: Merging upstream version 1.71.1+dfsg1. Signed-off-by: Daniel Baumann --- tests/ui/self/arbitrary-self-from-method-substs.rs | 16 +++++++++ .../self/arbitrary-self-from-method-substs.stderr | 9 +++++ ...rbitrary-self-types-not-object-safe.curr.stderr | 3 +- ...not-object-safe.object_safe_for_dispatch.stderr | 3 +- tests/ui/self/elision/nested-item.rs | 13 ++++++++ tests/ui/self/elision/nested-item.stderr | 38 ++++++++++++++++++++++ tests/ui/self/self-ctor-nongeneric.rs | 15 +++++++++ 7 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 tests/ui/self/arbitrary-self-from-method-substs.rs create mode 100644 tests/ui/self/arbitrary-self-from-method-substs.stderr create mode 100644 tests/ui/self/elision/nested-item.rs create mode 100644 tests/ui/self/elision/nested-item.stderr create mode 100644 tests/ui/self/self-ctor-nongeneric.rs (limited to 'tests/ui/self') diff --git a/tests/ui/self/arbitrary-self-from-method-substs.rs b/tests/ui/self/arbitrary-self-from-method-substs.rs new file mode 100644 index 000000000..0f911a208 --- /dev/null +++ b/tests/ui/self/arbitrary-self-from-method-substs.rs @@ -0,0 +1,16 @@ +#![feature(arbitrary_self_types)] + +use std::ops::Deref; + +struct Foo(u32); +impl Foo { + fn get>(self: R) -> u32 { + self.0 + } +} + +fn main() { + let mut foo = Foo(1); + foo.get::<&Foo>(); + //~^ ERROR mismatched types +} diff --git a/tests/ui/self/arbitrary-self-from-method-substs.stderr b/tests/ui/self/arbitrary-self-from-method-substs.stderr new file mode 100644 index 000000000..6c252fadf --- /dev/null +++ b/tests/ui/self/arbitrary-self-from-method-substs.stderr @@ -0,0 +1,9 @@ +error[E0308]: mismatched types + --> $DIR/arbitrary-self-from-method-substs.rs:14:5 + | +LL | foo.get::<&Foo>(); + | ^^^ expected `&Foo`, found `Foo` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/self/arbitrary-self-types-not-object-safe.curr.stderr b/tests/ui/self/arbitrary-self-types-not-object-safe.curr.stderr index 0ec0d4be5..13591f5b6 100644 --- a/tests/ui/self/arbitrary-self-types-not-object-safe.curr.stderr +++ b/tests/ui/self/arbitrary-self-types-not-object-safe.curr.stderr @@ -31,8 +31,7 @@ LL | trait Foo { | --- this trait cannot be made into an object... LL | fn foo(self: &Rc) -> usize; | ^^^^^^^^^ ...because method `foo`'s `self` parameter cannot be dispatched on - = note: required for `Rc` to implement `CoerceUnsized>` - = note: required by cast to type `Rc` + = note: required for the cast from `Rc` to `Rc` error: aborting due to 2 previous errors diff --git a/tests/ui/self/arbitrary-self-types-not-object-safe.object_safe_for_dispatch.stderr b/tests/ui/self/arbitrary-self-types-not-object-safe.object_safe_for_dispatch.stderr index b494b448e..593f70535 100644 --- a/tests/ui/self/arbitrary-self-types-not-object-safe.object_safe_for_dispatch.stderr +++ b/tests/ui/self/arbitrary-self-types-not-object-safe.object_safe_for_dispatch.stderr @@ -14,8 +14,7 @@ LL | trait Foo { | --- this trait cannot be made into an object... LL | fn foo(self: &Rc) -> usize; | ^^^^^^^^^ ...because method `foo`'s `self` parameter cannot be dispatched on - = note: required for `Rc` to implement `CoerceUnsized>` - = note: required by cast to type `Rc` + = note: required for the cast from `Rc` to `Rc` error: aborting due to previous error diff --git a/tests/ui/self/elision/nested-item.rs b/tests/ui/self/elision/nested-item.rs new file mode 100644 index 000000000..4bcb645c6 --- /dev/null +++ b/tests/ui/self/elision/nested-item.rs @@ -0,0 +1,13 @@ +// Regression test for #110899. +// When looking for the elided lifetime for `wrap`, +// we must not consider the lifetimes in `bar` as candidates. + +fn wrap(self: Wrap<{ fn bar(&self) {} }>) -> &() { + //~^ ERROR `self` parameter is only allowed in associated functions + //~| ERROR `self` parameter is only allowed in associated functions + //~| ERROR missing lifetime specifier + //~| ERROR cannot find type `Wrap` in this scope + &() +} + +fn main() {} diff --git a/tests/ui/self/elision/nested-item.stderr b/tests/ui/self/elision/nested-item.stderr new file mode 100644 index 000000000..752fd8233 --- /dev/null +++ b/tests/ui/self/elision/nested-item.stderr @@ -0,0 +1,38 @@ +error: `self` parameter is only allowed in associated functions + --> $DIR/nested-item.rs:5:9 + | +LL | fn wrap(self: Wrap<{ fn bar(&self) {} }>) -> &() { + | ^^^^ not semantically valid as function parameter + | + = note: associated functions are those in `impl` or `trait` definitions + +error: `self` parameter is only allowed in associated functions + --> $DIR/nested-item.rs:5:29 + | +LL | fn wrap(self: Wrap<{ fn bar(&self) {} }>) -> &() { + | ^^^^^ not semantically valid as function parameter + | + = note: associated functions are those in `impl` or `trait` definitions + +error[E0106]: missing lifetime specifier + --> $DIR/nested-item.rs:5:46 + | +LL | fn wrap(self: Wrap<{ fn bar(&self) {} }>) -> &() { + | ^ expected named lifetime parameter + | + = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from +help: consider using the `'static` lifetime + | +LL | fn wrap(self: Wrap<{ fn bar(&self) {} }>) -> &'static () { + | +++++++ + +error[E0412]: cannot find type `Wrap` in this scope + --> $DIR/nested-item.rs:5:15 + | +LL | fn wrap(self: Wrap<{ fn bar(&self) {} }>) -> &() { + | ^^^^ not found in this scope + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0106, E0412. +For more information about an error, try `rustc --explain E0106`. diff --git a/tests/ui/self/self-ctor-nongeneric.rs b/tests/ui/self/self-ctor-nongeneric.rs new file mode 100644 index 000000000..0ae7f8da4 --- /dev/null +++ b/tests/ui/self/self-ctor-nongeneric.rs @@ -0,0 +1,15 @@ +// `Self` as a constructor is currently allowed when the outer item is not generic. +// check-pass + +struct S0(usize); + +impl S0 { + fn foo() { + const C: S0 = Self(0); + fn bar() -> S0 { + Self(0) + } + } +} + +fn main() {} -- cgit v1.2.3