diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/associated-item | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/associated-item')
16 files changed, 290 insertions, 0 deletions
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<A: Adapter> { + 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<A> + PartialEq<B>; +} + +pub fn generic<F: Foo>(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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety> + --> $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 _: <S as Trait>::Target; //~ ERROR cannot find associated type `Output` in trait `Trait` + //~^ HELP maybe you meant this associated type + + let _ = <S as Trait>::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 _: <S as Trait>::Output; //~ ERROR cannot find associated type `Output` in trait `Trait` + //~^ HELP maybe you meant this associated type + + let _ = <S as Trait>::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 _: <S as Trait>::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 _ = <S as Trait>::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`. |