about summary refs log tree commit diff
path: root/tests/ui/associated-consts
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-06-10 10:15:37 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-06-17 10:57:52 +0000
commit94f549502f4bf6fae35f17c823924f041217c8f4 (patch)
tree4b8fa126b69cb8f5ca9004849a9aff16fce0b5eb /tests/ui/associated-consts
parente23ae72ac7a393961886ea62df065ebb6def7d51 (diff)
downloadrust-94f549502f4bf6fae35f17c823924f041217c8f4.tar.gz
rust-94f549502f4bf6fae35f17c823924f041217c8f4.zip
Use subtyping instead of equality, since method resolution also uses subtyping
Diffstat (limited to 'tests/ui/associated-consts')
-rw-r--r--tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg.rs10
-rw-r--r--tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg.stderr12
-rw-r--r--tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg2.rs17
-rw-r--r--tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg2.stderr20
4 files changed, 59 insertions, 0 deletions
diff --git a/tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg.rs b/tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg.rs
new file mode 100644
index 00000000000..e2fc2961a44
--- /dev/null
+++ b/tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg.rs
@@ -0,0 +1,10 @@
+struct Fail<T>;
+//~^ ERROR: type parameter `T` is never used
+
+impl Fail<i32> {
+    const C: () = ();
+}
+
+fn main() {
+    Fail::<()>::C
+}
diff --git a/tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg.stderr b/tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg.stderr
new file mode 100644
index 00000000000..f0a6ccf243a
--- /dev/null
+++ b/tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg.stderr
@@ -0,0 +1,12 @@
+error[E0392]: type parameter `T` is never used
+  --> $DIR/wrong-projection-self-ty-invalid-bivariant-arg.rs:1:13
+   |
+LL | struct Fail<T>;
+   |             ^ unused type parameter
+   |
+   = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
+   = help: if you intended `T` to be a const parameter, use `const T: /* Type */` instead
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0392`.
diff --git a/tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg2.rs b/tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg2.rs
new file mode 100644
index 00000000000..cb53d902ba1
--- /dev/null
+++ b/tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg2.rs
@@ -0,0 +1,17 @@
+trait Proj {
+    type Assoc;
+}
+impl<T> Proj for T {
+    type Assoc = T;
+}
+
+struct Fail<T: Proj<Assoc = U>, U>(T);
+
+impl Fail<i32, i32> {
+    const C: () = ();
+}
+
+fn main() {
+    Fail::<i32, u32>::C
+    //~^ ERROR: type mismatch
+}
diff --git a/tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg2.stderr b/tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg2.stderr
new file mode 100644
index 00000000000..0d63b7f5b29
--- /dev/null
+++ b/tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg2.stderr
@@ -0,0 +1,20 @@
+error[E0271]: type mismatch resolving `<i32 as Proj>::Assoc == u32`
+  --> $DIR/wrong-projection-self-ty-invalid-bivariant-arg2.rs:15:5
+   |
+LL |     Fail::<i32, u32>::C
+   |     ^^^^^^^^^^^^^^^^ type mismatch resolving `<i32 as Proj>::Assoc == u32`
+   |
+note: expected this to be `u32`
+  --> $DIR/wrong-projection-self-ty-invalid-bivariant-arg2.rs:5:18
+   |
+LL |     type Assoc = T;
+   |                  ^
+note: required by a bound in `Fail`
+  --> $DIR/wrong-projection-self-ty-invalid-bivariant-arg2.rs:8:21
+   |
+LL | struct Fail<T: Proj<Assoc = U>, U>(T);
+   |                     ^^^^^^^^^ required by this bound in `Fail`
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0271`.