Skip to content

Commit f16d62c

Browse files
authored
Rollup merge of rust-lang#73674 - estebank:op-trait-bound-suggestion, r=davidtwco
Tweak binop errors * Suggest potentially missing binop trait bound (fix rust-lang#73416) * Use structured suggestion for dereference in binop
2 parents d51c959 + 8f40dae commit f16d62c

14 files changed

+328
-254
lines changed

src/librustc_typeck/check/method/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
295295
opt_input_types: Option<&[Ty<'tcx>]>,
296296
) -> Option<InferOk<'tcx, MethodCallee<'tcx>>> {
297297
debug!(
298-
"lookup_in_trait_adjusted(self_ty={:?}, \
299-
m_name={}, trait_def_id={:?})",
298+
"lookup_in_trait_adjusted(self_ty={:?}, m_name={}, trait_def_id={:?})",
300299
self_ty, m_name, trait_def_id
301300
);
302301

src/librustc_typeck/check/method/probe.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
380380
self.tcx.sess,
381381
span,
382382
E0699,
383-
"the type of this value must be known \
384-
to call a method on a raw pointer on it"
383+
"the type of this value must be known to call a method on a raw pointer on \
384+
it"
385385
)
386386
.emit();
387387
} else {

src/librustc_typeck/check/op.rs

+248-246
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// run-rustfix
2+
fn main() {
3+
let v = vec![1, 2, 3, 4, 5, 6, 7, 8, 9];
4+
let vr = v.iter().filter(|x| {
5+
*x % 2 == 0
6+
//~^ ERROR cannot mod `&&{integer}` by `{integer}`
7+
});
8+
println!("{:?}", vr);
9+
}

src/test/ui/binary-op-on-double-ref.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// run-rustfix
12
fn main() {
23
let v = vec![1, 2, 3, 4, 5, 6, 7, 8, 9];
34
let vr = v.iter().filter(|x| {

src/test/ui/binary-op-on-double-ref.stderr

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
error[E0369]: cannot mod `&&{integer}` by `{integer}`
2-
--> $DIR/binary-op-on-double-ref.rs:4:11
2+
--> $DIR/binary-op-on-double-ref.rs:5:11
33
|
44
LL | x % 2 == 0
55
| - ^ - {integer}
66
| |
77
| &&{integer}
88
|
9-
= help: `%` can be used on '{integer}', you can dereference `x`: `*x`
9+
help: `%` can be used on `{integer}`, you can dereference `x`
10+
|
11+
LL | *x % 2 == 0
12+
| ^
1013

1114
error: aborting due to previous error
1215

src/test/ui/issues/issue-35668.stderr

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ LL | a.iter().map(|a| a*a)
55
| -^- &T
66
| |
77
| &T
8+
|
9+
help: consider restricting type parameter `T`
10+
|
11+
LL | fn func<'a, T: std::ops::Mul<Output = &T>>(a: &'a [T]) -> impl Iterator<Item=&'a T> {
12+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
813

914
error: aborting due to previous error
1015

src/test/ui/issues/issue-5239-1.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ LL | let x = |ref x: isize| { x += 1; };
66
| |
77
| cannot use `+=` on type `&isize`
88
|
9-
help: `+=` can be used on 'isize', you can dereference `x`
9+
help: `+=` can be used on `isize`, you can dereference `x`
1010
|
1111
LL | let x = |ref x: isize| { *x += 1; };
12-
| ^^
12+
| ^
1313

1414
error: aborting due to previous error
1515

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pub fn foo<T>(s: S<T>, t: S<T>) {
2+
let _ = s == t; //~ ERROR binary operation `==` cannot be applied to type `S<T>`
3+
}
4+
5+
struct S<T>(T);
6+
7+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0369]: binary operation `==` cannot be applied to type `S<T>`
2+
--> $DIR/invalid-bin-op.rs:2:15
3+
|
4+
LL | let _ = s == t;
5+
| - ^^ - S<T>
6+
| |
7+
| S<T>
8+
|
9+
= note: the trait `std::cmp::PartialEq` is not implemented for `S<T>`
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0369`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// run-rustfix
2+
3+
pub fn foo<T: std::cmp::PartialEq>(s: &[T], t: &[T]) {
4+
let _ = s == t; //~ ERROR binary operation `==` cannot be applied to type `&[T]`
5+
}
6+
7+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// run-rustfix
2+
3+
pub fn foo<T>(s: &[T], t: &[T]) {
4+
let _ = s == t; //~ ERROR binary operation `==` cannot be applied to type `&[T]`
5+
}
6+
7+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0369]: binary operation `==` cannot be applied to type `&[T]`
2+
--> $DIR/missing-trait-bound-for-op.rs:4:15
3+
|
4+
LL | let _ = s == t;
5+
| - ^^ - &[T]
6+
| |
7+
| &[T]
8+
|
9+
help: consider restricting type parameter `T`
10+
|
11+
LL | pub fn foo<T: std::cmp::PartialEq>(s: &[T], t: &[T]) {
12+
| ^^^^^^^^^^^^^^^^^^^^^
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0369`.

src/test/ui/traits/trait-resolution-in-overloaded-op.stderr

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ LL | a * b
55
| - ^ - f64
66
| |
77
| &T
8+
|
9+
help: consider further restricting this bound
10+
|
11+
LL | fn foo<T: MyMul<f64, f64> + std::ops::Mul<Output = f64>>(a: &T, b: f64) -> f64 {
12+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
813

914
error: aborting due to previous error
1015

0 commit comments

Comments
 (0)