about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-02-17 06:29:59 +0100
committerGitHub <noreply@github.com>2022-02-17 06:29:59 +0100
commit351aa1b5dabe51ae4fcdfc23db51ce60f6699cf0 (patch)
tree6b74c442c2d009ddb4420aca2924db45c8d78161 /src
parentd855121a44afd0fc9a5f1c2d263af48e9857a5f4 (diff)
parent1973f277a3e79861df2f5bff88aedaf127d833c8 (diff)
downloadrust-351aa1b5dabe51ae4fcdfc23db51ce60f6699cf0.tar.gz
rust-351aa1b5dabe51ae4fcdfc23db51ce60f6699cf0.zip
Rollup merge of #93693 - rukai:91550, r=davidtwco
Suggest deriving required supertraits

closes https://github.com/rust-lang/rust/issues/91550

I chose to just hardcode handling for PartialOrd and PartialEq because that should be robust enough and I dont know how to go about doing it generically

r? rust-lang/diagnostics
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/binop/issue-28837.stderr16
-rw-r--r--src/test/ui/derives/issue-91550.rs29
-rw-r--r--src/test/ui/derives/issue-91550.stderr84
-rw-r--r--src/test/ui/union/union-derive-clone.mirunsafeck.stderr4
-rw-r--r--src/test/ui/union/union-derive-clone.thirunsafeck.stderr4
5 files changed, 125 insertions, 12 deletions
diff --git a/src/test/ui/binop/issue-28837.stderr b/src/test/ui/binop/issue-28837.stderr
index 10f243bab15..1875ea06a06 100644
--- a/src/test/ui/binop/issue-28837.stderr
+++ b/src/test/ui/binop/issue-28837.stderr
@@ -272,9 +272,9 @@ note: an implementation of `PartialOrd<_>` might be missing for `A`
    |
 LL | struct A;
    | ^^^^^^^^^ must implement `PartialOrd<_>`
-help: consider annotating `A` with `#[derive(PartialOrd)]`
+help: consider annotating `A` with `#[derive(PartialEq, PartialOrd)]`
    |
-LL | #[derive(PartialOrd)]
+LL | #[derive(PartialEq, PartialOrd)]
    |
 
 error[E0369]: binary operation `<=` cannot be applied to type `A`
@@ -290,9 +290,9 @@ note: an implementation of `PartialOrd<_>` might be missing for `A`
    |
 LL | struct A;
    | ^^^^^^^^^ must implement `PartialOrd<_>`
-help: consider annotating `A` with `#[derive(PartialOrd)]`
+help: consider annotating `A` with `#[derive(PartialEq, PartialOrd)]`
    |
-LL | #[derive(PartialOrd)]
+LL | #[derive(PartialEq, PartialOrd)]
    |
 
 error[E0369]: binary operation `>` cannot be applied to type `A`
@@ -308,9 +308,9 @@ note: an implementation of `PartialOrd<_>` might be missing for `A`
    |
 LL | struct A;
    | ^^^^^^^^^ must implement `PartialOrd<_>`
-help: consider annotating `A` with `#[derive(PartialOrd)]`
+help: consider annotating `A` with `#[derive(PartialEq, PartialOrd)]`
    |
-LL | #[derive(PartialOrd)]
+LL | #[derive(PartialEq, PartialOrd)]
    |
 
 error[E0369]: binary operation `>=` cannot be applied to type `A`
@@ -326,9 +326,9 @@ note: an implementation of `PartialOrd<_>` might be missing for `A`
    |
 LL | struct A;
    | ^^^^^^^^^ must implement `PartialOrd<_>`
-help: consider annotating `A` with `#[derive(PartialOrd)]`
+help: consider annotating `A` with `#[derive(PartialEq, PartialOrd)]`
    |
-LL | #[derive(PartialOrd)]
+LL | #[derive(PartialEq, PartialOrd)]
    |
 
 error: aborting due to 15 previous errors
diff --git a/src/test/ui/derives/issue-91550.rs b/src/test/ui/derives/issue-91550.rs
new file mode 100644
index 00000000000..56fd5ffa89e
--- /dev/null
+++ b/src/test/ui/derives/issue-91550.rs
@@ -0,0 +1,29 @@
+use std::collections::HashSet;
+
+/// natural case from the issue
+struct Value(u32);
+
+fn main() {
+    let hs = HashSet::<Value>::new();
+    hs.insert(Value(0)); //~ ERROR
+}
+
+/// synthetic cases
+pub struct NoDerives;
+
+struct Object<T>(T);
+impl<T: Eq> Object<T> {
+    fn use_eq(&self) {}
+}
+impl<T: Ord> Object<T> {
+    fn use_ord(&self) {}
+}
+impl<T: Ord + PartialOrd> Object<T> {
+    fn use_ord_and_partial_ord(&self) {}
+}
+
+fn function(foo: Object<NoDerives>) {
+    foo.use_eq(); //~ ERROR
+    foo.use_ord(); //~ ERROR
+    foo.use_ord_and_partial_ord(); //~ ERROR
+}
diff --git a/src/test/ui/derives/issue-91550.stderr b/src/test/ui/derives/issue-91550.stderr
new file mode 100644
index 00000000000..bf4b7c7da0d
--- /dev/null
+++ b/src/test/ui/derives/issue-91550.stderr
@@ -0,0 +1,84 @@
+error[E0599]: the method `insert` exists for struct `HashSet<Value>`, but its trait bounds were not satisfied
+  --> $DIR/issue-91550.rs:8:8
+   |
+LL | struct Value(u32);
+   | ------------------
+   | |
+   | doesn't satisfy `Value: Eq`
+   | doesn't satisfy `Value: Hash`
+...
+LL |     hs.insert(Value(0));
+   |        ^^^^^^ method cannot be called on `HashSet<Value>` due to unsatisfied trait bounds
+   |
+   = note: the following trait bounds were not satisfied:
+           `Value: Eq`
+           `Value: Hash`
+help: consider annotating `Value` with `#[derive(Eq, Hash, PartialEq)]`
+   |
+LL | #[derive(Eq, Hash, PartialEq)]
+   |
+
+error[E0599]: the method `use_eq` exists for struct `Object<NoDerives>`, but its trait bounds were not satisfied
+  --> $DIR/issue-91550.rs:26:9
+   |
+LL | pub struct NoDerives;
+   | --------------------- doesn't satisfy `NoDerives: Eq`
+LL | 
+LL | struct Object<T>(T);
+   | -------------------- method `use_eq` not found for this
+...
+LL |     foo.use_eq();
+   |         ^^^^^^ method cannot be called on `Object<NoDerives>` due to unsatisfied trait bounds
+   |
+   = note: the following trait bounds were not satisfied:
+           `NoDerives: Eq`
+help: consider annotating `NoDerives` with `#[derive(Eq, PartialEq)]`
+   |
+LL | #[derive(Eq, PartialEq)]
+   |
+
+error[E0599]: the method `use_ord` exists for struct `Object<NoDerives>`, but its trait bounds were not satisfied
+  --> $DIR/issue-91550.rs:27:9
+   |
+LL | pub struct NoDerives;
+   | --------------------- doesn't satisfy `NoDerives: Ord`
+LL | 
+LL | struct Object<T>(T);
+   | -------------------- method `use_ord` not found for this
+...
+LL |     foo.use_ord();
+   |         ^^^^^^^ method cannot be called on `Object<NoDerives>` due to unsatisfied trait bounds
+   |
+   = note: the following trait bounds were not satisfied:
+           `NoDerives: Ord`
+help: consider annotating `NoDerives` with `#[derive(Eq, Ord, PartialEq, PartialOrd)]`
+   |
+LL | #[derive(Eq, Ord, PartialEq, PartialOrd)]
+   |
+
+error[E0599]: the method `use_ord_and_partial_ord` exists for struct `Object<NoDerives>`, but its trait bounds were not satisfied
+  --> $DIR/issue-91550.rs:28:9
+   |
+LL | pub struct NoDerives;
+   | ---------------------
+   | |
+   | doesn't satisfy `NoDerives: Ord`
+   | doesn't satisfy `NoDerives: PartialOrd`
+LL | 
+LL | struct Object<T>(T);
+   | -------------------- method `use_ord_and_partial_ord` not found for this
+...
+LL |     foo.use_ord_and_partial_ord();
+   |         ^^^^^^^^^^^^^^^^^^^^^^^ method cannot be called on `Object<NoDerives>` due to unsatisfied trait bounds
+   |
+   = note: the following trait bounds were not satisfied:
+           `NoDerives: Ord`
+           `NoDerives: PartialOrd`
+help: consider annotating `NoDerives` with `#[derive(Eq, Ord, PartialEq, PartialOrd)]`
+   |
+LL | #[derive(Eq, Ord, PartialEq, PartialOrd)]
+   |
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0599`.
diff --git a/src/test/ui/union/union-derive-clone.mirunsafeck.stderr b/src/test/ui/union/union-derive-clone.mirunsafeck.stderr
index 146a627bcde..e8e65fe5d1d 100644
--- a/src/test/ui/union/union-derive-clone.mirunsafeck.stderr
+++ b/src/test/ui/union/union-derive-clone.mirunsafeck.stderr
@@ -16,9 +16,9 @@ LL |     let w = u.clone();
    = note: the following trait bounds were not satisfied:
            `CloneNoCopy: Copy`
            which is required by `U5<CloneNoCopy>: Clone`
-help: consider annotating `CloneNoCopy` with `#[derive(Copy)]`
+help: consider annotating `CloneNoCopy` with `#[derive(Clone, Copy)]`
    |
-LL | #[derive(Copy)]
+LL | #[derive(Clone, Copy)]
    |
 
 error[E0277]: the trait bound `U1: Copy` is not satisfied
diff --git a/src/test/ui/union/union-derive-clone.thirunsafeck.stderr b/src/test/ui/union/union-derive-clone.thirunsafeck.stderr
index 146a627bcde..e8e65fe5d1d 100644
--- a/src/test/ui/union/union-derive-clone.thirunsafeck.stderr
+++ b/src/test/ui/union/union-derive-clone.thirunsafeck.stderr
@@ -16,9 +16,9 @@ LL |     let w = u.clone();
    = note: the following trait bounds were not satisfied:
            `CloneNoCopy: Copy`
            which is required by `U5<CloneNoCopy>: Clone`
-help: consider annotating `CloneNoCopy` with `#[derive(Copy)]`
+help: consider annotating `CloneNoCopy` with `#[derive(Clone, Copy)]`
    |
-LL | #[derive(Copy)]
+LL | #[derive(Clone, Copy)]
    |
 
 error[E0277]: the trait bound `U1: Copy` is not satisfied