From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- .../associated-item-duplicate-bounds.rs | 11 ++++++ .../associated-item-duplicate-bounds.stderr | 11 ++++++ .../associated-item-duplicate-names-2.rs | 8 +++++ .../associated-item-duplicate-names-2.stderr | 11 ++++++ .../associated-item-duplicate-names-3.rs | 19 +++++++++++ .../associated-item-duplicate-names-3.stderr | 11 ++++++ .../associated-item-duplicate-names.rs | 19 +++++++++++ .../associated-item-duplicate-names.stderr | 19 +++++++++++ .../ui/associated-item/associated-item-enum.rs | 20 +++++++++++ .../ui/associated-item/associated-item-enum.stderr | 39 ++++++++++++++++++++++ .../associated-item/associated-item-two-bounds.rs | 16 +++++++++ src/test/ui/associated-item/issue-48027.rs | 8 +++++ src/test/ui/associated-item/issue-48027.stderr | 27 +++++++++++++++ src/test/ui/associated-item/issue-87638.fixed | 22 ++++++++++++ src/test/ui/associated-item/issue-87638.rs | 22 ++++++++++++ src/test/ui/associated-item/issue-87638.stderr | 27 +++++++++++++++ 16 files changed, 290 insertions(+) create mode 100644 src/test/ui/associated-item/associated-item-duplicate-bounds.rs create mode 100644 src/test/ui/associated-item/associated-item-duplicate-bounds.stderr create mode 100644 src/test/ui/associated-item/associated-item-duplicate-names-2.rs create mode 100644 src/test/ui/associated-item/associated-item-duplicate-names-2.stderr create mode 100644 src/test/ui/associated-item/associated-item-duplicate-names-3.rs create mode 100644 src/test/ui/associated-item/associated-item-duplicate-names-3.stderr create mode 100644 src/test/ui/associated-item/associated-item-duplicate-names.rs create mode 100644 src/test/ui/associated-item/associated-item-duplicate-names.stderr create mode 100644 src/test/ui/associated-item/associated-item-enum.rs create mode 100644 src/test/ui/associated-item/associated-item-enum.stderr create mode 100644 src/test/ui/associated-item/associated-item-two-bounds.rs create mode 100644 src/test/ui/associated-item/issue-48027.rs create mode 100644 src/test/ui/associated-item/issue-48027.stderr create mode 100644 src/test/ui/associated-item/issue-87638.fixed create mode 100644 src/test/ui/associated-item/issue-87638.rs create mode 100644 src/test/ui/associated-item/issue-87638.stderr (limited to 'src/test/ui/associated-item') diff --git a/src/test/ui/associated-item/associated-item-duplicate-bounds.rs b/src/test/ui/associated-item/associated-item-duplicate-bounds.rs new file mode 100644 index 000000000..242a02353 --- /dev/null +++ b/src/test/ui/associated-item/associated-item-duplicate-bounds.rs @@ -0,0 +1,11 @@ +trait Adapter { + const LINKS: usize; +} + +struct Foo { + adapter: A, + links: [u32; A::LINKS], // Shouldn't suggest bounds already there. + //~^ ERROR generic parameters may not be used in const operations +} + +fn main() {} diff --git a/src/test/ui/associated-item/associated-item-duplicate-bounds.stderr b/src/test/ui/associated-item/associated-item-duplicate-bounds.stderr new file mode 100644 index 000000000..f2e4ca524 --- /dev/null +++ b/src/test/ui/associated-item/associated-item-duplicate-bounds.stderr @@ -0,0 +1,11 @@ +error: generic parameters may not be used in const operations + --> $DIR/associated-item-duplicate-bounds.rs:7:18 + | +LL | links: [u32; A::LINKS], // Shouldn't suggest bounds already there. + | ^^^^^^^^ cannot perform const operation using `A` + | + = note: type parameters may not be used in const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions + +error: aborting due to previous error + diff --git a/src/test/ui/associated-item/associated-item-duplicate-names-2.rs b/src/test/ui/associated-item/associated-item-duplicate-names-2.rs new file mode 100644 index 000000000..550c7ae39 --- /dev/null +++ b/src/test/ui/associated-item/associated-item-duplicate-names-2.rs @@ -0,0 +1,8 @@ +struct Foo; + +impl Foo { + const bar: bool = true; + fn bar() {} //~ ERROR duplicate definitions +} + +fn main() {} diff --git a/src/test/ui/associated-item/associated-item-duplicate-names-2.stderr b/src/test/ui/associated-item/associated-item-duplicate-names-2.stderr new file mode 100644 index 000000000..f4efd1312 --- /dev/null +++ b/src/test/ui/associated-item/associated-item-duplicate-names-2.stderr @@ -0,0 +1,11 @@ +error[E0201]: duplicate definitions with name `bar`: + --> $DIR/associated-item-duplicate-names-2.rs:5:5 + | +LL | const bar: bool = true; + | --------------- previous definition of `bar` here +LL | fn bar() {} + | ^^^^^^^^ duplicate definition + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0201`. diff --git a/src/test/ui/associated-item/associated-item-duplicate-names-3.rs b/src/test/ui/associated-item/associated-item-duplicate-names-3.rs new file mode 100644 index 000000000..6aa1b483e --- /dev/null +++ b/src/test/ui/associated-item/associated-item-duplicate-names-3.rs @@ -0,0 +1,19 @@ +// +// Before the introduction of the "duplicate associated type" error, the +// program below used to result in the "ambiguous associated type" error E0223, +// which is unexpected. + +trait Foo { + type Bar; +} + +struct Baz; + +impl Foo for Baz { + type Bar = i16; + type Bar = u16; //~ ERROR duplicate definitions +} + +fn main() { + let x: Baz::Bar = 5; +} diff --git a/src/test/ui/associated-item/associated-item-duplicate-names-3.stderr b/src/test/ui/associated-item/associated-item-duplicate-names-3.stderr new file mode 100644 index 000000000..03782f663 --- /dev/null +++ b/src/test/ui/associated-item/associated-item-duplicate-names-3.stderr @@ -0,0 +1,11 @@ +error[E0201]: duplicate definitions with name `Bar`: + --> $DIR/associated-item-duplicate-names-3.rs:14:5 + | +LL | type Bar = i16; + | -------- previous definition of `Bar` here +LL | type Bar = u16; + | ^^^^^^^^ duplicate definition + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0201`. diff --git a/src/test/ui/associated-item/associated-item-duplicate-names.rs b/src/test/ui/associated-item/associated-item-duplicate-names.rs new file mode 100644 index 000000000..6677fad68 --- /dev/null +++ b/src/test/ui/associated-item/associated-item-duplicate-names.rs @@ -0,0 +1,19 @@ +// Test for issue #23969 + + +trait Foo { + type Ty; + const BAR: u32; +} + +impl Foo for () { + type Ty = (); + type Ty = usize; //~ ERROR duplicate definitions + const BAR: u32 = 7; + const BAR: u32 = 8; //~ ERROR duplicate definitions +} + +fn main() { + let _: <() as Foo>::Ty = (); + let _: u32 = <() as Foo>::BAR; +} diff --git a/src/test/ui/associated-item/associated-item-duplicate-names.stderr b/src/test/ui/associated-item/associated-item-duplicate-names.stderr new file mode 100644 index 000000000..c9119c102 --- /dev/null +++ b/src/test/ui/associated-item/associated-item-duplicate-names.stderr @@ -0,0 +1,19 @@ +error[E0201]: duplicate definitions with name `Ty`: + --> $DIR/associated-item-duplicate-names.rs:11:5 + | +LL | type Ty = (); + | ------- previous definition of `Ty` here +LL | type Ty = usize; + | ^^^^^^^ duplicate definition + +error[E0201]: duplicate definitions with name `BAR`: + --> $DIR/associated-item-duplicate-names.rs:13:5 + | +LL | const BAR: u32 = 7; + | -------------- previous definition of `BAR` here +LL | const BAR: u32 = 8; + | ^^^^^^^^^^^^^^ duplicate definition + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0201`. diff --git a/src/test/ui/associated-item/associated-item-enum.rs b/src/test/ui/associated-item/associated-item-enum.rs new file mode 100644 index 000000000..30ba25815 --- /dev/null +++ b/src/test/ui/associated-item/associated-item-enum.rs @@ -0,0 +1,20 @@ +enum Enum { Variant } + +impl Enum { + const MISSPELLABLE: i32 = 0; + fn misspellable() {} +} + +trait Trait { + fn misspellable_trait() {} +} + +impl Trait for Enum { + fn misspellable_trait() {} +} + +fn main() { + Enum::mispellable(); //~ ERROR no variant or associated item + Enum::mispellable_trait(); //~ ERROR no variant or associated item + Enum::MISPELLABLE; //~ ERROR no variant or associated item +} diff --git a/src/test/ui/associated-item/associated-item-enum.stderr b/src/test/ui/associated-item/associated-item-enum.stderr new file mode 100644 index 000000000..ebf3c5499 --- /dev/null +++ b/src/test/ui/associated-item/associated-item-enum.stderr @@ -0,0 +1,39 @@ +error[E0599]: no variant or associated item named `mispellable` found for enum `Enum` in the current scope + --> $DIR/associated-item-enum.rs:17:11 + | +LL | enum Enum { Variant } + | --------- variant or associated item `mispellable` not found for this enum +... +LL | Enum::mispellable(); + | ^^^^^^^^^^^ + | | + | variant or associated item not found in `Enum` + | help: there is an associated function with a similar name: `misspellable` + +error[E0599]: no variant or associated item named `mispellable_trait` found for enum `Enum` in the current scope + --> $DIR/associated-item-enum.rs:18:11 + | +LL | enum Enum { Variant } + | --------- variant or associated item `mispellable_trait` not found for this enum +... +LL | Enum::mispellable_trait(); + | ^^^^^^^^^^^^^^^^^ + | | + | variant or associated item not found in `Enum` + | help: there is an associated function with a similar name: `misspellable` + +error[E0599]: no variant or associated item named `MISPELLABLE` found for enum `Enum` in the current scope + --> $DIR/associated-item-enum.rs:19:11 + | +LL | enum Enum { Variant } + | --------- variant or associated item `MISPELLABLE` not found for this enum +... +LL | Enum::MISPELLABLE; + | ^^^^^^^^^^^ + | | + | variant or associated item not found in `Enum` + | help: there is an associated constant with a similar name: `MISSPELLABLE` + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0599`. diff --git a/src/test/ui/associated-item/associated-item-two-bounds.rs b/src/test/ui/associated-item/associated-item-two-bounds.rs new file mode 100644 index 000000000..25b0d5a56 --- /dev/null +++ b/src/test/ui/associated-item/associated-item-two-bounds.rs @@ -0,0 +1,16 @@ +// This test is a regression test for #34792 + +// check-pass + +pub struct A; +pub struct B; + +pub trait Foo { + type T: PartialEq + PartialEq; +} + +pub fn generic(t: F::T, a: A, b: B) -> bool { + t == a && t == b +} + +pub fn main() {} diff --git a/src/test/ui/associated-item/issue-48027.rs b/src/test/ui/associated-item/issue-48027.rs new file mode 100644 index 000000000..d2b51184c --- /dev/null +++ b/src/test/ui/associated-item/issue-48027.rs @@ -0,0 +1,8 @@ +trait Bar { + const X: usize; + fn return_n(&self) -> [u8; Bar::X]; //~ ERROR: E0790 +} + +impl dyn Bar {} //~ ERROR: the trait `Bar` cannot be made into an object + +fn main() {} diff --git a/src/test/ui/associated-item/issue-48027.stderr b/src/test/ui/associated-item/issue-48027.stderr new file mode 100644 index 000000000..45ea41933 --- /dev/null +++ b/src/test/ui/associated-item/issue-48027.stderr @@ -0,0 +1,27 @@ +error[E0038]: the trait `Bar` cannot be made into an object + --> $DIR/issue-48027.rs:6:6 + | +LL | impl dyn Bar {} + | ^^^^^^^ `Bar` cannot be made into an object + | +note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit + --> $DIR/issue-48027.rs:2:11 + | +LL | trait Bar { + | --- this trait cannot be made into an object... +LL | const X: usize; + | ^ ...because it contains this associated `const` + = help: consider moving `X` to another trait + +error[E0790]: cannot refer to the associated constant on trait without specifying the corresponding `impl` type + --> $DIR/issue-48027.rs:3:32 + | +LL | const X: usize; + | --------------- `Bar::X` defined here +LL | fn return_n(&self) -> [u8; Bar::X]; + | ^^^^^^ cannot refer to the associated constant of trait + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0038, E0790. +For more information about an error, try `rustc --explain E0038`. diff --git a/src/test/ui/associated-item/issue-87638.fixed b/src/test/ui/associated-item/issue-87638.fixed new file mode 100644 index 000000000..b68977768 --- /dev/null +++ b/src/test/ui/associated-item/issue-87638.fixed @@ -0,0 +1,22 @@ +// run-rustfix + +trait Trait { + const FOO: usize; + + type Target; +} + +struct S; + +impl Trait for S { + const FOO: usize = 0; + type Target = (); +} + +fn main() { + let _: ::Target; //~ ERROR cannot find associated type `Output` in trait `Trait` + //~^ HELP maybe you meant this associated type + + let _ = ::FOO; //~ ERROR cannot find method or associated constant `BAR` in trait `Trait` + //~^ HELP maybe you meant this associated constant +} diff --git a/src/test/ui/associated-item/issue-87638.rs b/src/test/ui/associated-item/issue-87638.rs new file mode 100644 index 000000000..5a60b20fd --- /dev/null +++ b/src/test/ui/associated-item/issue-87638.rs @@ -0,0 +1,22 @@ +// run-rustfix + +trait Trait { + const FOO: usize; + + type Target; +} + +struct S; + +impl Trait for S { + const FOO: usize = 0; + type Target = (); +} + +fn main() { + let _: ::Output; //~ ERROR cannot find associated type `Output` in trait `Trait` + //~^ HELP maybe you meant this associated type + + let _ = ::BAR; //~ ERROR cannot find method or associated constant `BAR` in trait `Trait` + //~^ HELP maybe you meant this associated constant +} diff --git a/src/test/ui/associated-item/issue-87638.stderr b/src/test/ui/associated-item/issue-87638.stderr new file mode 100644 index 000000000..cf6083444 --- /dev/null +++ b/src/test/ui/associated-item/issue-87638.stderr @@ -0,0 +1,27 @@ +error[E0576]: cannot find associated type `Output` in trait `Trait` + --> $DIR/issue-87638.rs:17:26 + | +LL | type Target; + | ------------ associated type `Target` defined here +... +LL | let _: ::Output; + | ^^^^^^ + | | + | not found in `Trait` + | help: maybe you meant this associated type: `Target` + +error[E0576]: cannot find method or associated constant `BAR` in trait `Trait` + --> $DIR/issue-87638.rs:20:27 + | +LL | const FOO: usize; + | ----------------- associated constant `FOO` defined here +... +LL | let _ = ::BAR; + | ^^^ + | | + | not found in `Trait` + | help: maybe you meant this associated constant: `FOO` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0576`. -- cgit v1.2.3