summaryrefslogtreecommitdiffstats
path: root/tests/ui/associated-item
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/associated-item
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/associated-item')
-rw-r--r--tests/ui/associated-item/ambiguous-associated-type-with-generics.fixed14
-rw-r--r--tests/ui/associated-item/ambiguous-associated-type-with-generics.rs14
-rw-r--r--tests/ui/associated-item/ambiguous-associated-type-with-generics.stderr9
-rw-r--r--tests/ui/associated-item/associated-item-duplicate-bounds.rs11
-rw-r--r--tests/ui/associated-item/associated-item-duplicate-bounds.stderr11
-rw-r--r--tests/ui/associated-item/associated-item-duplicate-names-2.rs8
-rw-r--r--tests/ui/associated-item/associated-item-duplicate-names-2.stderr11
-rw-r--r--tests/ui/associated-item/associated-item-duplicate-names-3.rs20
-rw-r--r--tests/ui/associated-item/associated-item-duplicate-names-3.stderr21
-rw-r--r--tests/ui/associated-item/associated-item-duplicate-names.rs19
-rw-r--r--tests/ui/associated-item/associated-item-duplicate-names.stderr25
-rw-r--r--tests/ui/associated-item/associated-item-enum.rs20
-rw-r--r--tests/ui/associated-item/associated-item-enum.stderr39
-rw-r--r--tests/ui/associated-item/associated-item-two-bounds.rs16
-rw-r--r--tests/ui/associated-item/impl-duplicate-methods.rs9
-rw-r--r--tests/ui/associated-item/impl-duplicate-methods.stderr11
-rw-r--r--tests/ui/associated-item/issue-105449.rs59
-rw-r--r--tests/ui/associated-item/issue-48027.rs8
-rw-r--r--tests/ui/associated-item/issue-48027.stderr27
-rw-r--r--tests/ui/associated-item/issue-87638.fixed22
-rw-r--r--tests/ui/associated-item/issue-87638.rs22
-rw-r--r--tests/ui/associated-item/issue-87638.stderr27
22 files changed, 423 insertions, 0 deletions
diff --git a/tests/ui/associated-item/ambiguous-associated-type-with-generics.fixed b/tests/ui/associated-item/ambiguous-associated-type-with-generics.fixed
new file mode 100644
index 000000000..23f715200
--- /dev/null
+++ b/tests/ui/associated-item/ambiguous-associated-type-with-generics.fixed
@@ -0,0 +1,14 @@
+// run-rustfix
+trait Trait<A> {}
+
+trait Assoc {
+ type Ty;
+}
+
+impl<A> Assoc for dyn Trait<A> {
+ type Ty = i32;
+}
+
+fn main() {
+ let _x: <dyn Trait<i32> as Assoc>::Ty; //~ ERROR ambiguous associated type
+}
diff --git a/tests/ui/associated-item/ambiguous-associated-type-with-generics.rs b/tests/ui/associated-item/ambiguous-associated-type-with-generics.rs
new file mode 100644
index 000000000..9c26e339a
--- /dev/null
+++ b/tests/ui/associated-item/ambiguous-associated-type-with-generics.rs
@@ -0,0 +1,14 @@
+// run-rustfix
+trait Trait<A> {}
+
+trait Assoc {
+ type Ty;
+}
+
+impl<A> Assoc for dyn Trait<A> {
+ type Ty = i32;
+}
+
+fn main() {
+ let _x: <dyn Trait<i32>>::Ty; //~ ERROR ambiguous associated type
+}
diff --git a/tests/ui/associated-item/ambiguous-associated-type-with-generics.stderr b/tests/ui/associated-item/ambiguous-associated-type-with-generics.stderr
new file mode 100644
index 000000000..97088b79f
--- /dev/null
+++ b/tests/ui/associated-item/ambiguous-associated-type-with-generics.stderr
@@ -0,0 +1,9 @@
+error[E0223]: ambiguous associated type
+ --> $DIR/ambiguous-associated-type-with-generics.rs:13:13
+ |
+LL | let _x: <dyn Trait<i32>>::Ty;
+ | ^^^^^^^^^^^^^^^^^^^^ help: use the fully-qualified path: `<dyn Trait<i32> as Assoc>::Ty`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0223`.
diff --git a/tests/ui/associated-item/associated-item-duplicate-bounds.rs b/tests/ui/associated-item/associated-item-duplicate-bounds.rs
new file mode 100644
index 000000000..242a02353
--- /dev/null
+++ b/tests/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/tests/ui/associated-item/associated-item-duplicate-bounds.stderr b/tests/ui/associated-item/associated-item-duplicate-bounds.stderr
new file mode 100644
index 000000000..f2e4ca524
--- /dev/null
+++ b/tests/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/tests/ui/associated-item/associated-item-duplicate-names-2.rs b/tests/ui/associated-item/associated-item-duplicate-names-2.rs
new file mode 100644
index 000000000..550c7ae39
--- /dev/null
+++ b/tests/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/tests/ui/associated-item/associated-item-duplicate-names-2.stderr b/tests/ui/associated-item/associated-item-duplicate-names-2.stderr
new file mode 100644
index 000000000..0b96a6bd7
--- /dev/null
+++ b/tests/ui/associated-item/associated-item-duplicate-names-2.stderr
@@ -0,0 +1,11 @@
+error[E0592]: duplicate definitions with name `bar`
+ --> $DIR/associated-item-duplicate-names-2.rs:5:5
+ |
+LL | const bar: bool = true;
+ | --------------- other definition for `bar`
+LL | fn bar() {}
+ | ^^^^^^^^ duplicate definitions for `bar`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0592`.
diff --git a/tests/ui/associated-item/associated-item-duplicate-names-3.rs b/tests/ui/associated-item/associated-item-duplicate-names-3.rs
new file mode 100644
index 000000000..3a70a2f94
--- /dev/null
+++ b/tests/ui/associated-item/associated-item-duplicate-names-3.rs
@@ -0,0 +1,20 @@
+//
+// 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;
+ //~^ ERROR ambiguous associated type
+}
diff --git a/tests/ui/associated-item/associated-item-duplicate-names-3.stderr b/tests/ui/associated-item/associated-item-duplicate-names-3.stderr
new file mode 100644
index 000000000..d0c170620
--- /dev/null
+++ b/tests/ui/associated-item/associated-item-duplicate-names-3.stderr
@@ -0,0 +1,21 @@
+error[E0201]: duplicate definitions with name `Bar`:
+ --> $DIR/associated-item-duplicate-names-3.rs:14:5
+ |
+LL | type Bar;
+ | --------- item in trait
+...
+LL | type Bar = i16;
+ | --------------- previous definition here
+LL | type Bar = u16;
+ | ^^^^^^^^^^^^^^^ duplicate definition
+
+error[E0223]: ambiguous associated type
+ --> $DIR/associated-item-duplicate-names-3.rs:18:12
+ |
+LL | let x: Baz::Bar = 5;
+ | ^^^^^^^^ help: use the fully-qualified path: `<Baz as Foo>::Bar`
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0201, E0223.
+For more information about an error, try `rustc --explain E0201`.
diff --git a/tests/ui/associated-item/associated-item-duplicate-names.rs b/tests/ui/associated-item/associated-item-duplicate-names.rs
new file mode 100644
index 000000000..6677fad68
--- /dev/null
+++ b/tests/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/tests/ui/associated-item/associated-item-duplicate-names.stderr b/tests/ui/associated-item/associated-item-duplicate-names.stderr
new file mode 100644
index 000000000..f89ea6e57
--- /dev/null
+++ b/tests/ui/associated-item/associated-item-duplicate-names.stderr
@@ -0,0 +1,25 @@
+error[E0201]: duplicate definitions with name `Ty`:
+ --> $DIR/associated-item-duplicate-names.rs:11:5
+ |
+LL | type Ty;
+ | -------- item in trait
+...
+LL | type Ty = ();
+ | ------------- previous definition 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;
+ | --------------- item in trait
+...
+LL | const BAR: u32 = 7;
+ | ------------------- previous definition 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/tests/ui/associated-item/associated-item-enum.rs b/tests/ui/associated-item/associated-item-enum.rs
new file mode 100644
index 000000000..30ba25815
--- /dev/null
+++ b/tests/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/tests/ui/associated-item/associated-item-enum.stderr b/tests/ui/associated-item/associated-item-enum.stderr
new file mode 100644
index 000000000..ebf3c5499
--- /dev/null
+++ b/tests/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/tests/ui/associated-item/associated-item-two-bounds.rs b/tests/ui/associated-item/associated-item-two-bounds.rs
new file mode 100644
index 000000000..25b0d5a56
--- /dev/null
+++ b/tests/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/tests/ui/associated-item/impl-duplicate-methods.rs b/tests/ui/associated-item/impl-duplicate-methods.rs
new file mode 100644
index 000000000..328d54d5a
--- /dev/null
+++ b/tests/ui/associated-item/impl-duplicate-methods.rs
@@ -0,0 +1,9 @@
+struct Foo;
+
+impl Foo {
+ fn orange(&self) {}
+ fn orange(&self) {}
+ //~^ ERROR duplicate definitions with name `orange` [E0592]
+}
+
+fn main() {}
diff --git a/tests/ui/associated-item/impl-duplicate-methods.stderr b/tests/ui/associated-item/impl-duplicate-methods.stderr
new file mode 100644
index 000000000..6f753845a
--- /dev/null
+++ b/tests/ui/associated-item/impl-duplicate-methods.stderr
@@ -0,0 +1,11 @@
+error[E0592]: duplicate definitions with name `orange`
+ --> $DIR/impl-duplicate-methods.rs:5:5
+ |
+LL | fn orange(&self) {}
+ | ---------------- other definition for `orange`
+LL | fn orange(&self) {}
+ | ^^^^^^^^^^^^^^^^ duplicate definitions for `orange`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0592`.
diff --git a/tests/ui/associated-item/issue-105449.rs b/tests/ui/associated-item/issue-105449.rs
new file mode 100644
index 000000000..dd14e05fd
--- /dev/null
+++ b/tests/ui/associated-item/issue-105449.rs
@@ -0,0 +1,59 @@
+// check-pass
+// compile-flags: -C debug_assertions=yes -Zunstable-options
+
+#[allow(dead_code)]
+fn problematic_function<Space>()
+where
+ DefaultAlloc: FinAllok<R1, Space>,
+{
+ let e = Edge2dElement;
+ let _ = Into::<Point>::into(e.map_reference_coords());
+}
+impl<N> Allocator<N, R0> for DefaultAlloc {
+ type Buffer = MStorage;
+}
+impl<N> Allocator<N, R1> for DefaultAlloc {
+ type Buffer = MStorage;
+}
+impl<N, D> From<VectorN<N, D>> for Point
+where
+ DefaultAlloc: Allocator<N, D>,
+{
+ fn from(_: VectorN<N, D>) -> Self {
+ unimplemented!()
+ }
+}
+impl<GeometryDim, NodalDim> FinAllok<GeometryDim, NodalDim> for DefaultAlloc
+where
+ DefaultAlloc: Allocator<Ure, GeometryDim>,
+ DefaultAlloc: Allocator<Ure, NodalDim>
+{
+}
+impl FiniteElement<R1> for Edge2dElement {
+ fn map_reference_coords(&self) -> VectorN<Ure, R1> {
+ unimplemented!()
+ }
+}
+type VectorN<N, R> = (N, R, <DefaultAlloc as Allocator<N, R>>::Buffer);
+struct DefaultAlloc;
+struct R0;
+struct R1;
+struct MStorage;
+struct Point;
+struct Edge2dElement;
+struct Ure;
+trait Allocator<N, R> {
+ type Buffer;
+}
+trait FinAllok<GeometryDim, NodalDim>:
+ Allocator<Ure, GeometryDim> +
+ Allocator<Ure, NodalDim> +
+{
+}
+trait FiniteElement<Rau>
+where
+ DefaultAlloc: FinAllok<Rau, Rau>,
+{
+ fn map_reference_coords(&self) -> VectorN<Ure, Rau>;
+}
+fn main() {}
diff --git a/tests/ui/associated-item/issue-48027.rs b/tests/ui/associated-item/issue-48027.rs
new file mode 100644
index 000000000..d2b51184c
--- /dev/null
+++ b/tests/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/tests/ui/associated-item/issue-48027.stderr b/tests/ui/associated-item/issue-48027.stderr
new file mode 100644
index 000000000..45ea41933
--- /dev/null
+++ b/tests/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/tests/ui/associated-item/issue-87638.fixed b/tests/ui/associated-item/issue-87638.fixed
new file mode 100644
index 000000000..b68977768
--- /dev/null
+++ b/tests/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/tests/ui/associated-item/issue-87638.rs b/tests/ui/associated-item/issue-87638.rs
new file mode 100644
index 000000000..5a60b20fd
--- /dev/null
+++ b/tests/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/tests/ui/associated-item/issue-87638.stderr b/tests/ui/associated-item/issue-87638.stderr
new file mode 100644
index 000000000..cf6083444
--- /dev/null
+++ b/tests/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`.