diff options
| author | Will Crichton <wcrichto@cs.stanford.edu> | 2022-02-15 14:49:16 -0800 |
|---|---|---|
| committer | Will Crichton <wcrichto@cs.stanford.edu> | 2022-04-25 18:12:15 -0700 |
| commit | 4d0fe27896294fd22854fdc76357bcef96e2005a (patch) | |
| tree | 3f210a441871a9cd8174768b90ded20e1e59bdc2 /src | |
| parent | 18b53cefdf7456bf68937b08e377b7e622a115c2 (diff) | |
| download | rust-4d0fe27896294fd22854fdc76357bcef96e2005a.tar.gz rust-4d0fe27896294fd22854fdc76357bcef96e2005a.zip | |
Replace suggest_constraining_param with suggest_restricting_param_bound
to fix incorrect suggestion for trait bounds involving binary operators. Fixes #93927, #92347, #93744.
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/binop/issue-93927.rs | 20 | ||||
| -rw-r--r-- | src/test/ui/binop/issue-93927.stderr | 16 | ||||
| -rw-r--r-- | src/test/ui/generic-associated-types/missing-bounds.fixed | 2 | ||||
| -rw-r--r-- | src/test/ui/generic-associated-types/missing-bounds.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-35668.stderr | 6 | ||||
| -rw-r--r-- | src/test/ui/suggestions/invalid-bin-op.stderr | 5 | ||||
| -rw-r--r-- | src/test/ui/traits/resolution-in-overloaded-op.stderr | 6 | ||||
| -rw-r--r-- | src/test/ui/type/type-check/missing_trait_impl.stderr | 4 |
8 files changed, 51 insertions, 12 deletions
diff --git a/src/test/ui/binop/issue-93927.rs b/src/test/ui/binop/issue-93927.rs new file mode 100644 index 00000000000..de27c9785e6 --- /dev/null +++ b/src/test/ui/binop/issue-93927.rs @@ -0,0 +1,20 @@ +// Regression test for #93927: suggested trait bound for T should be Eq, not PartialEq +struct MyType<T>(T); + +impl<T> PartialEq for MyType<T> +where + T: Eq, +{ + fn eq(&self, other: &Self) -> bool { + true + } +} + +fn cond<T: PartialEq>(val: MyType<T>) -> bool { + val == val + //~^ ERROR binary operation `==` cannot be applied to type `MyType<T>` +} + +fn main() { + cond(MyType(0)); +} diff --git a/src/test/ui/binop/issue-93927.stderr b/src/test/ui/binop/issue-93927.stderr new file mode 100644 index 00000000000..75558b502f9 --- /dev/null +++ b/src/test/ui/binop/issue-93927.stderr @@ -0,0 +1,16 @@ +error[E0369]: binary operation `==` cannot be applied to type `MyType<T>` + --> $DIR/issue-93927.rs:14:9 + | +LL | val == val + | --- ^^ --- MyType<T> + | | + | MyType<T> + | +help: consider further restricting this bound + | +LL | fn cond<T: PartialEq + std::cmp::Eq>(val: MyType<T>) -> bool { + | ++++++++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0369`. diff --git a/src/test/ui/generic-associated-types/missing-bounds.fixed b/src/test/ui/generic-associated-types/missing-bounds.fixed index 0e234120a51..8eddfe21e30 100644 --- a/src/test/ui/generic-associated-types/missing-bounds.fixed +++ b/src/test/ui/generic-associated-types/missing-bounds.fixed @@ -24,7 +24,7 @@ impl<B: Add + Add<Output = B>> Add for C<B> { struct D<B>(B); -impl<B: std::ops::Add<Output = B>> Add for D<B> { +impl<B: std::ops::Add> Add for D<B> { type Output = Self; fn add(self, rhs: Self) -> Self { diff --git a/src/test/ui/generic-associated-types/missing-bounds.stderr b/src/test/ui/generic-associated-types/missing-bounds.stderr index 240be93cf96..25db8461098 100644 --- a/src/test/ui/generic-associated-types/missing-bounds.stderr +++ b/src/test/ui/generic-associated-types/missing-bounds.stderr @@ -66,8 +66,8 @@ LL | Self(self.0 + rhs.0) | help: consider restricting type parameter `B` | -LL | impl<B: std::ops::Add<Output = B>> Add for D<B> { - | +++++++++++++++++++++++++++ +LL | impl<B: std::ops::Add> Add for D<B> { + | +++++++++++++++ error[E0308]: mismatched types --> $DIR/missing-bounds.rs:42:14 diff --git a/src/test/ui/issues/issue-35668.stderr b/src/test/ui/issues/issue-35668.stderr index 04faea9008a..07409e9834a 100644 --- a/src/test/ui/issues/issue-35668.stderr +++ b/src/test/ui/issues/issue-35668.stderr @@ -6,10 +6,10 @@ LL | a.iter().map(|a| a*a) | | | &T | -help: consider restricting type parameter `T` +help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement | -LL | fn func<'a, T: std::ops::Mul<Output = &T>>(a: &'a [T]) -> impl Iterator<Item=&'a T> { - | ++++++++++++++++++++++++++++ +LL | fn func<'a, T>(a: &'a [T]) -> impl Iterator<Item=&'a T> where &T: Mul<&T> { + | +++++++++++++++++ error: aborting due to previous error diff --git a/src/test/ui/suggestions/invalid-bin-op.stderr b/src/test/ui/suggestions/invalid-bin-op.stderr index d18c24e53d0..fe5e2b5816f 100644 --- a/src/test/ui/suggestions/invalid-bin-op.stderr +++ b/src/test/ui/suggestions/invalid-bin-op.stderr @@ -11,11 +11,14 @@ note: an implementation of `PartialEq<_>` might be missing for `S<T>` | LL | struct S<T>(T); | ^^^^^^^^^^^^^^^ must implement `PartialEq<_>` - = note: the trait `std::cmp::PartialEq` is not implemented for `S<T>` help: consider annotating `S<T>` with `#[derive(PartialEq)]` | LL | #[derive(PartialEq)] | +help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement + | +LL | pub fn foo<T>(s: S<T>, t: S<T>) where S<T>: PartialEq { + | +++++++++++++++++++++ error: aborting due to previous error diff --git a/src/test/ui/traits/resolution-in-overloaded-op.stderr b/src/test/ui/traits/resolution-in-overloaded-op.stderr index 049fffe165a..3ae6bf130cc 100644 --- a/src/test/ui/traits/resolution-in-overloaded-op.stderr +++ b/src/test/ui/traits/resolution-in-overloaded-op.stderr @@ -6,10 +6,10 @@ LL | a * b | | | &T | -help: consider further restricting this bound +help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement | -LL | fn foo<T: MyMul<f64, f64> + std::ops::Mul<Output = f64>>(a: &T, b: f64) -> f64 { - | +++++++++++++++++++++++++++++ +LL | fn foo<T: MyMul<f64, f64>>(a: &T, b: f64) -> f64 where &T: Mul<f64> { + | ++++++++++++++++++ error: aborting due to previous error diff --git a/src/test/ui/type/type-check/missing_trait_impl.stderr b/src/test/ui/type/type-check/missing_trait_impl.stderr index 59b8692dd4d..fe156a88453 100644 --- a/src/test/ui/type/type-check/missing_trait_impl.stderr +++ b/src/test/ui/type/type-check/missing_trait_impl.stderr @@ -8,8 +8,8 @@ LL | let z = x + y; | help: consider restricting type parameter `T` | -LL | fn foo<T: std::ops::Add<Output = T>>(x: T, y: T) { - | +++++++++++++++++++++++++++ +LL | fn foo<T: std::ops::Add>(x: T, y: T) { + | +++++++++++++++ error[E0368]: binary assignment operation `+=` cannot be applied to type `T` --> $DIR/missing_trait_impl.rs:9:5 |
