Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak binop errors #73674

Merged
merged 3 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -296,8 +296,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 @@ -379,8 +379,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