about summary refs log tree commit diff
path: root/tests/ui/missing-trait-bounds
diff options
context:
space:
mode:
authorAlbert Larsan <74931857+albertlarsan68@users.noreply.github.com>2023-01-05 09:13:28 +0100
committerAlbert Larsan <74931857+albertlarsan68@users.noreply.github.com>2023-01-11 09:32:08 +0000
commitcf2dff2b1e3fa55fa5415d524200070d0d7aacfe (patch)
tree40a88d9a46aaf3e8870676eb2538378b75a263eb /tests/ui/missing-trait-bounds
parentca855e6e42787ecd062d81d53336fe6788ef51a9 (diff)
downloadrust-cf2dff2b1e3fa55fa5415d524200070d0d7aacfe.tar.gz
rust-cf2dff2b1e3fa55fa5415d524200070d0d7aacfe.zip
Move /src/test to /tests
Diffstat (limited to 'tests/ui/missing-trait-bounds')
-rw-r--r--tests/ui/missing-trait-bounds/auxiliary/issue-69725.rs8
-rw-r--r--tests/ui/missing-trait-bounds/issue-35677.fixed11
-rw-r--r--tests/ui/missing-trait-bounds/issue-35677.rs11
-rw-r--r--tests/ui/missing-trait-bounds/issue-35677.stderr17
-rw-r--r--tests/ui/missing-trait-bounds/issue-69725.fixed13
-rw-r--r--tests/ui/missing-trait-bounds/issue-69725.rs13
-rw-r--r--tests/ui/missing-trait-bounds/issue-69725.stderr22
-rw-r--r--tests/ui/missing-trait-bounds/missing-trait-bound-for-op.fixed7
-rw-r--r--tests/ui/missing-trait-bounds/missing-trait-bound-for-op.rs7
-rw-r--r--tests/ui/missing-trait-bounds/missing-trait-bound-for-op.stderr16
-rw-r--r--tests/ui/missing-trait-bounds/missing-trait-bounds-for-method-call.rs31
-rw-r--r--tests/ui/missing-trait-bounds/missing-trait-bounds-for-method-call.stderr52
12 files changed, 208 insertions, 0 deletions
diff --git a/tests/ui/missing-trait-bounds/auxiliary/issue-69725.rs b/tests/ui/missing-trait-bounds/auxiliary/issue-69725.rs
new file mode 100644
index 00000000000..13606e498ef
--- /dev/null
+++ b/tests/ui/missing-trait-bounds/auxiliary/issue-69725.rs
@@ -0,0 +1,8 @@
+#[derive(Clone)]
+pub struct Struct<A>(A);
+
+impl<A> Struct<A> {
+    pub fn new() -> Self {
+        todo!()
+    }
+}
diff --git a/tests/ui/missing-trait-bounds/issue-35677.fixed b/tests/ui/missing-trait-bounds/issue-35677.fixed
new file mode 100644
index 00000000000..08174d8d8d5
--- /dev/null
+++ b/tests/ui/missing-trait-bounds/issue-35677.fixed
@@ -0,0 +1,11 @@
+// run-rustfix
+#![allow(dead_code)]
+use std::collections::HashSet;
+use std::hash::Hash;
+
+fn is_subset<T>(this: &HashSet<T>, other: &HashSet<T>) -> bool where T: Eq, T: Hash {
+    this.is_subset(other)
+    //~^ ERROR the method
+}
+
+fn main() {}
diff --git a/tests/ui/missing-trait-bounds/issue-35677.rs b/tests/ui/missing-trait-bounds/issue-35677.rs
new file mode 100644
index 00000000000..2cb394386b8
--- /dev/null
+++ b/tests/ui/missing-trait-bounds/issue-35677.rs
@@ -0,0 +1,11 @@
+// run-rustfix
+#![allow(dead_code)]
+use std::collections::HashSet;
+use std::hash::Hash;
+
+fn is_subset<T>(this: &HashSet<T>, other: &HashSet<T>) -> bool {
+    this.is_subset(other)
+    //~^ ERROR the method
+}
+
+fn main() {}
diff --git a/tests/ui/missing-trait-bounds/issue-35677.stderr b/tests/ui/missing-trait-bounds/issue-35677.stderr
new file mode 100644
index 00000000000..a2201b946a6
--- /dev/null
+++ b/tests/ui/missing-trait-bounds/issue-35677.stderr
@@ -0,0 +1,17 @@
+error[E0599]: the method `is_subset` exists for reference `&HashSet<T>`, but its trait bounds were not satisfied
+  --> $DIR/issue-35677.rs:7:10
+   |
+LL |     this.is_subset(other)
+   |          ^^^^^^^^^ method cannot be called on `&HashSet<T>` due to unsatisfied trait bounds
+   |
+   = note: the following trait bounds were not satisfied:
+           `T: Eq`
+           `T: Hash`
+help: consider restricting the type parameters to satisfy the trait bounds
+   |
+LL | fn is_subset<T>(this: &HashSet<T>, other: &HashSet<T>) -> bool where T: Eq, T: Hash {
+   |                                                                ++++++++++++++++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0599`.
diff --git a/tests/ui/missing-trait-bounds/issue-69725.fixed b/tests/ui/missing-trait-bounds/issue-69725.fixed
new file mode 100644
index 00000000000..d57badcfd8c
--- /dev/null
+++ b/tests/ui/missing-trait-bounds/issue-69725.fixed
@@ -0,0 +1,13 @@
+// run-rustfix
+// aux-build:issue-69725.rs
+#![allow(dead_code)]
+
+extern crate issue_69725;
+use issue_69725::Struct;
+
+fn crash<A>() where A: Clone {
+    let _ = Struct::<A>::new().clone();
+    //~^ ERROR: the method
+}
+
+fn main() {}
diff --git a/tests/ui/missing-trait-bounds/issue-69725.rs b/tests/ui/missing-trait-bounds/issue-69725.rs
new file mode 100644
index 00000000000..9c88969c5cf
--- /dev/null
+++ b/tests/ui/missing-trait-bounds/issue-69725.rs
@@ -0,0 +1,13 @@
+// run-rustfix
+// aux-build:issue-69725.rs
+#![allow(dead_code)]
+
+extern crate issue_69725;
+use issue_69725::Struct;
+
+fn crash<A>() {
+    let _ = Struct::<A>::new().clone();
+    //~^ ERROR: the method
+}
+
+fn main() {}
diff --git a/tests/ui/missing-trait-bounds/issue-69725.stderr b/tests/ui/missing-trait-bounds/issue-69725.stderr
new file mode 100644
index 00000000000..980d9dd167d
--- /dev/null
+++ b/tests/ui/missing-trait-bounds/issue-69725.stderr
@@ -0,0 +1,22 @@
+error[E0599]: the method `clone` exists for struct `Struct<A>`, but its trait bounds were not satisfied
+  --> $DIR/issue-69725.rs:9:32
+   |
+LL |     let _ = Struct::<A>::new().clone();
+   |                                ^^^^^ method cannot be called on `Struct<A>` due to unsatisfied trait bounds
+   |
+  ::: $DIR/auxiliary/issue-69725.rs:2:1
+   |
+LL | pub struct Struct<A>(A);
+   | -------------------- doesn't satisfy `Struct<A>: Clone`
+   |
+   = note: the following trait bounds were not satisfied:
+           `A: Clone`
+           which is required by `Struct<A>: Clone`
+help: consider restricting the type parameter to satisfy the trait bound
+   |
+LL | fn crash<A>() where A: Clone {
+   |               ++++++++++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0599`.
diff --git a/tests/ui/missing-trait-bounds/missing-trait-bound-for-op.fixed b/tests/ui/missing-trait-bounds/missing-trait-bound-for-op.fixed
new file mode 100644
index 00000000000..6b24375e415
--- /dev/null
+++ b/tests/ui/missing-trait-bounds/missing-trait-bound-for-op.fixed
@@ -0,0 +1,7 @@
+// run-rustfix
+
+pub fn foo<T: std::cmp::PartialEq>(s: &[T], t: &[T]) {
+    let _ = s == t; //~ ERROR binary operation `==` cannot be applied to type `&[T]`
+}
+
+fn main() {}
diff --git a/tests/ui/missing-trait-bounds/missing-trait-bound-for-op.rs b/tests/ui/missing-trait-bounds/missing-trait-bound-for-op.rs
new file mode 100644
index 00000000000..df47be070c9
--- /dev/null
+++ b/tests/ui/missing-trait-bounds/missing-trait-bound-for-op.rs
@@ -0,0 +1,7 @@
+// run-rustfix
+
+pub fn foo<T>(s: &[T], t: &[T]) {
+    let _ = s == t; //~ ERROR binary operation `==` cannot be applied to type `&[T]`
+}
+
+fn main() {}
diff --git a/tests/ui/missing-trait-bounds/missing-trait-bound-for-op.stderr b/tests/ui/missing-trait-bounds/missing-trait-bound-for-op.stderr
new file mode 100644
index 00000000000..cde07550125
--- /dev/null
+++ b/tests/ui/missing-trait-bounds/missing-trait-bound-for-op.stderr
@@ -0,0 +1,16 @@
+error[E0369]: binary operation `==` cannot be applied to type `&[T]`
+  --> $DIR/missing-trait-bound-for-op.rs:4:15
+   |
+LL |     let _ = s == t;
+   |             - ^^ - &[T]
+   |             |
+   |             &[T]
+   |
+help: consider restricting type parameter `T`
+   |
+LL | pub fn foo<T: std::cmp::PartialEq>(s: &[T], t: &[T]) {
+   |             +++++++++++++++++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0369`.
diff --git a/tests/ui/missing-trait-bounds/missing-trait-bounds-for-method-call.rs b/tests/ui/missing-trait-bounds/missing-trait-bounds-for-method-call.rs
new file mode 100644
index 00000000000..afd47f71c2c
--- /dev/null
+++ b/tests/ui/missing-trait-bounds/missing-trait-bounds-for-method-call.rs
@@ -0,0 +1,31 @@
+#[derive(Default, PartialEq)]
+struct Foo<T> {
+    bar: Box<[T]>,
+}
+
+trait Bar {
+    fn foo(&self) {}
+}
+
+impl<T: Default + Bar> Bar for Foo<T> {}
+
+impl<T> Foo<T> {
+    fn bar(&self) {
+        self.foo();
+        //~^ ERROR the method
+    }
+}
+
+struct Fin<T> where T: Bar {
+    bar: Box<[T]>,
+}
+
+impl<T: Default + Bar> Bar for Fin<T> {}
+
+impl<T: Bar> Fin<T> {
+    fn bar(&self) {
+        self.foo();
+        //~^ ERROR the method
+    }
+}
+fn main() {}
diff --git a/tests/ui/missing-trait-bounds/missing-trait-bounds-for-method-call.stderr b/tests/ui/missing-trait-bounds/missing-trait-bounds-for-method-call.stderr
new file mode 100644
index 00000000000..9e94aa2c7b3
--- /dev/null
+++ b/tests/ui/missing-trait-bounds/missing-trait-bounds-for-method-call.stderr
@@ -0,0 +1,52 @@
+error[E0599]: the method `foo` exists for reference `&Foo<T>`, but its trait bounds were not satisfied
+  --> $DIR/missing-trait-bounds-for-method-call.rs:14:14
+   |
+LL | struct Foo<T> {
+   | ------------- doesn't satisfy `Foo<T>: Bar`
+...
+LL |         self.foo();
+   |              ^^^ method cannot be called on `&Foo<T>` due to unsatisfied trait bounds
+   |
+note: trait bound `T: Default` was not satisfied
+  --> $DIR/missing-trait-bounds-for-method-call.rs:10:9
+   |
+LL | impl<T: Default + Bar> Bar for Foo<T> {}
+   |         ^^^^^^^        ---     ------
+   |         |
+   |         unsatisfied trait bound introduced here
+note: trait bound `T: Bar` was not satisfied
+  --> $DIR/missing-trait-bounds-for-method-call.rs:10:19
+   |
+LL | impl<T: Default + Bar> Bar for Foo<T> {}
+   |                   ^^^  ---     ------
+   |                   |
+   |                   unsatisfied trait bound introduced here
+help: consider restricting the type parameters to satisfy the trait bounds
+   |
+LL | struct Foo<T> where T: Bar, T: Default {
+   |               ++++++++++++++++++++++++
+
+error[E0599]: the method `foo` exists for reference `&Fin<T>`, but its trait bounds were not satisfied
+  --> $DIR/missing-trait-bounds-for-method-call.rs:27:14
+   |
+LL | struct Fin<T> where T: Bar {
+   | ------------- doesn't satisfy `Fin<T>: Bar`
+...
+LL |         self.foo();
+   |              ^^^ method cannot be called on `&Fin<T>` due to unsatisfied trait bounds
+   |
+note: trait bound `T: Default` was not satisfied
+  --> $DIR/missing-trait-bounds-for-method-call.rs:23:9
+   |
+LL | impl<T: Default + Bar> Bar for Fin<T> {}
+   |         ^^^^^^^        ---     ------
+   |         |
+   |         unsatisfied trait bound introduced here
+help: consider restricting the type parameter to satisfy the trait bound
+   |
+LL | struct Fin<T> where T: Bar, T: Default {
+   |                           ++++++++++++
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0599`.