Skip to content

Commit 388df82

Browse files
committed
Auto merge of #50161 - rizakrko:impl_note, r=estebank
added missing implementation hint Fixes [#50151](#50151). Actually, i don't know, should following code `let x = |ref x: isize| { x += 1; };` emit `note: an implementation of std::ops::AddAssign might be missing for &isize` or `note: this is a reference to a type that + can be applied to; you need to dereference this variable once for this operation to work` or both
2 parents 0cd4650 + 17c56d4 commit 388df82

11 files changed

+201
-80
lines changed

src/librustc_typeck/check/op.rs

+165-70
Large diffs are not rendered by default.

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ error[E0369]: binary operation `%` cannot be applied to type `&&{integer}`
44
LL | x % 2 == 0
55
| ^^^^^
66
|
7-
= note: this is a reference to a type that `%` can be applied to; you need to dereference this variable once for this operation to work
8-
= note: an implementation of `std::ops::Rem` might be missing for `&&{integer}`
7+
= help: `%` can be used on '{integer}', you can dereference `x`: `*x`
98

109
error: aborting due to previous error
1110

src/test/ui/codemap_tests/issue-28308.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0600]: cannot apply unary operator `!` to type `&'static str`
22
--> $DIR/issue-28308.rs:12:5
33
|
44
LL | assert!("foo");
5-
| ^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^ cannot apply unary operator `!`
66

77
error: aborting due to previous error
88

src/test/ui/error-codes/E0067.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ LL | LinkedList::new() += 1; //~ ERROR E0368
55
| -----------------^^^^^
66
| |
77
| cannot use `+=` on type `std::collections::LinkedList<_>`
8+
|
9+
= note: an implementation of `std::ops::AddAssign` might be missing for `std::collections::LinkedList<_>`
810

911
error[E0067]: invalid left-hand side expression
1012
--> $DIR/E0067.rs:14:5

src/test/ui/error-codes/E0600.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0600]: cannot apply unary operator `!` to type `&'static str`
22
--> $DIR/E0600.rs:12:5
33
|
44
LL | !"a"; //~ ERROR E0600
5-
| ^^^^
5+
| ^^^^ cannot apply unary operator `!`
66

77
error: aborting due to previous error
88

src/test/ui/error-festival.stderr

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ LL | x += 2;
1717
| -^^^^^
1818
| |
1919
| cannot use `+=` on type `&str`
20+
|
21+
= note: an implementation of `std::ops::AddAssign` might be missing for `&str`
2022

2123
error[E0599]: no method named `z` found for type `&str` in the current scope
2224
--> $DIR/error-festival.rs:26:7
@@ -28,7 +30,9 @@ error[E0600]: cannot apply unary operator `!` to type `Question`
2830
--> $DIR/error-festival.rs:29:5
2931
|
3032
LL | !Question::Yes;
31-
| ^^^^^^^^^^^^^^
33+
| ^^^^^^^^^^^^^^ cannot apply unary operator `!`
34+
|
35+
= note: an implementation of `std::ops::Not` might be missing for `Question`
3236

3337
error[E0604]: only `u8` can be cast as `char`, not `u32`
3438
--> $DIR/error-festival.rs:35:5

src/test/ui/feature-gate-negate-unsigned.stderr

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ error[E0600]: cannot apply unary operator `-` to type `usize`
22
--> $DIR/feature-gate-negate-unsigned.rs:20:23
33
|
44
LL | let _max: usize = -1;
5-
| ^^
5+
| ^^ cannot apply unary operator `-`
6+
|
7+
= note: unsigned values cannot be negated
68

79
error[E0600]: cannot apply unary operator `-` to type `u8`
810
--> $DIR/feature-gate-negate-unsigned.rs:24:14
911
|
1012
LL | let _y = -x;
11-
| ^^
13+
| ^^ cannot apply unary operator `-`
14+
|
15+
= note: unsigned values cannot be negated
1216

1317
error: aborting due to 2 previous errors
1418

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

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

911
error: aborting due to previous error
1012

src/test/ui/reachable/expr_unary.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0600]: cannot apply unary operator `!` to type `!`
22
--> $DIR/expr_unary.rs:17:16
33
|
44
LL | let x: ! = ! { return; }; //~ ERROR unreachable
5-
| ^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^ cannot apply unary operator `!`
66

77
error: unreachable expression
88
--> $DIR/expr_unary.rs:17:16

src/test/ui/type-check/missing_trait_impl.rs

+4
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ fn main() {
1414
fn foo<T>(x: T, y: T) {
1515
let z = x + y; //~ ERROR binary operation `+` cannot be applied to type `T`
1616
}
17+
18+
fn bar<T>(x: T) {
19+
x += x; //~ ERROR binary assignment operation `+=` cannot be applied to type `T`
20+
}

src/test/ui/type-check/missing_trait_impl.stderr

+13-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ LL | let z = x + y; //~ ERROR binary operation `+` cannot be applied to type
66
|
77
= note: `T` might need a bound for `std::ops::Add`
88

9-
error: aborting due to previous error
9+
error[E0368]: binary assignment operation `+=` cannot be applied to type `T`
10+
--> $DIR/missing_trait_impl.rs:19:5
11+
|
12+
LL | x += x; //~ ERROR binary assignment operation `+=` cannot be applied to type `T`
13+
| -^^^^^
14+
| |
15+
| cannot use `+=` on type `T`
16+
|
17+
= note: `T` might need a bound for `std::ops::AddAssign`
18+
19+
error: aborting due to 2 previous errors
1020

11-
For more information about this error, try `rustc --explain E0369`.
21+
Some errors occurred: E0368, E0369.
22+
For more information about an error, try `rustc --explain E0368`.

0 commit comments

Comments
 (0)