Skip to content

Commit

Permalink
Rollup merge of rust-lang#73674 - estebank:op-trait-bound-suggestion,…
Browse files Browse the repository at this point in the history
… r=davidtwco

Tweak binop errors

* Suggest potentially missing binop trait bound (fix rust-lang#73416)
* Use structured suggestion for dereference in binop
  • Loading branch information
Manishearth authored Jun 26, 2020
2 parents d51c959 + 8f40dae commit f16d62c
Show file tree
Hide file tree
Showing 14 changed files with 328 additions and 254 deletions.
3 changes: 1 addition & 2 deletions src/librustc_typeck/check/method/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
opt_input_types: Option<&[Ty<'tcx>]>,
) -> Option<InferOk<'tcx, MethodCallee<'tcx>>> {
debug!(
"lookup_in_trait_adjusted(self_ty={:?}, \
m_name={}, trait_def_id={:?})",
"lookup_in_trait_adjusted(self_ty={:?}, m_name={}, trait_def_id={:?})",
self_ty, m_name, trait_def_id
);

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.tcx.sess,
span,
E0699,
"the type of this value must be known \
to call a method on a raw pointer on it"
"the type of this value must be known to call a method on a raw pointer on \
it"
)
.emit();
} else {
Expand Down
494 changes: 248 additions & 246 deletions src/librustc_typeck/check/op.rs

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions src/test/ui/binary-op-on-double-ref.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// run-rustfix
fn main() {
let v = vec![1, 2, 3, 4, 5, 6, 7, 8, 9];
let vr = v.iter().filter(|x| {
*x % 2 == 0
//~^ ERROR cannot mod `&&{integer}` by `{integer}`
});
println!("{:?}", vr);
}
1 change: 1 addition & 0 deletions src/test/ui/binary-op-on-double-ref.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// run-rustfix
fn main() {
let v = vec![1, 2, 3, 4, 5, 6, 7, 8, 9];
let vr = v.iter().filter(|x| {
Expand Down
7 changes: 5 additions & 2 deletions src/test/ui/binary-op-on-double-ref.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
error[E0369]: cannot mod `&&{integer}` by `{integer}`
--> $DIR/binary-op-on-double-ref.rs:4:11
--> $DIR/binary-op-on-double-ref.rs:5:11
|
LL | x % 2 == 0
| - ^ - {integer}
| |
| &&{integer}
|
= help: `%` can be used on '{integer}', you can dereference `x`: `*x`
help: `%` can be used on `{integer}`, you can dereference `x`
|
LL | *x % 2 == 0
| ^

error: aborting due to previous error

Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/issues/issue-35668.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ LL | a.iter().map(|a| a*a)
| -^- &T
| |
| &T
|
help: consider restricting type parameter `T`
|
LL | fn func<'a, T: std::ops::Mul<Output = &T>>(a: &'a [T]) -> impl Iterator<Item=&'a T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-5239-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ LL | let x = |ref x: isize| { x += 1; };
| |
| cannot use `+=` on type `&isize`
|
help: `+=` can be used on 'isize', you can dereference `x`
help: `+=` can be used on `isize`, you can dereference `x`
|
LL | let x = |ref x: isize| { *x += 1; };
| ^^
| ^

error: aborting due to previous error

Expand Down
7 changes: 7 additions & 0 deletions src/test/ui/suggestions/invalid-bin-op.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub fn foo<T>(s: S<T>, t: S<T>) {
let _ = s == t; //~ ERROR binary operation `==` cannot be applied to type `S<T>`
}

struct S<T>(T);

fn main() {}
13 changes: 13 additions & 0 deletions src/test/ui/suggestions/invalid-bin-op.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0369]: binary operation `==` cannot be applied to type `S<T>`
--> $DIR/invalid-bin-op.rs:2:15
|
LL | let _ = s == t;
| - ^^ - S<T>
| |
| S<T>
|
= note: the trait `std::cmp::PartialEq` is not implemented for `S<T>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0369`.
7 changes: 7 additions & 0 deletions src/test/ui/suggestions/missing-trait-bound-for-op.fixed
Original file line number Diff line number Diff line change
@@ -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() {}
7 changes: 7 additions & 0 deletions src/test/ui/suggestions/missing-trait-bound-for-op.rs
Original file line number Diff line number Diff line change
@@ -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() {}
16 changes: 16 additions & 0 deletions src/test/ui/suggestions/missing-trait-bound-for-op.stderr
Original file line number Diff line number Diff line change
@@ -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`.
5 changes: 5 additions & 0 deletions src/test/ui/traits/trait-resolution-in-overloaded-op.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ LL | a * b
| - ^ - f64
| |
| &T
|
help: consider further restricting this bound
|
LL | fn foo<T: MyMul<f64, f64> + std::ops::Mul<Output = f64>>(a: &T, b: f64) -> f64 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

Expand Down

0 comments on commit f16d62c

Please sign in to comment.