Rollup merge of #105192 - estebank:point-at-lhs-on-binop, r=fee1-dead

Point at LHS on binop type err if relevant
This commit is contained in:
Matthias Krüger 2022-12-10 15:01:43 +01:00 committed by GitHub
commit 7e1857db1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 571 additions and 187 deletions

View File

@ -189,7 +189,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&self,
err: &mut Diagnostic,
expr: &hir::Expr<'_>,
error: Option<TypeError<'_>>,
error: Option<TypeError<'tcx>>,
) {
let parent = self.tcx.hir().get_parent_node(expr.hir_id);
match (self.tcx.hir().find(parent), error) {
@ -286,6 +286,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err.downgrade_to_delayed_bug();
}
}
(
Some(hir::Node::Expr(hir::Expr {
kind: hir::ExprKind::Binary(_, lhs, rhs), ..
})),
Some(TypeError::Sorts(ExpectedFound { expected, .. })),
) if rhs.hir_id == expr.hir_id
&& self.typeck_results.borrow().expr_ty_adjusted_opt(lhs) == Some(expected) =>
{
err.span_label(lhs.span, &format!("expected because this is `{expected}`"));
}
_ => {}
}
}

View File

@ -2,7 +2,9 @@ error[E0308]: mismatched types
--> $DIR/issue-79518-default_trait_method_normalization.rs:16:32
|
LL | Self::AssocInstance == [(); std::mem::size_of::<Self::Assoc>()];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found array `[(); _]`
| ------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found array `[(); _]`
| |
| expected because this is `<Self as Foo>::Assoc`
|
= note: expected associated type `<Self as Foo>::Assoc`
found array `[(); _]`

View File

@ -87,7 +87,10 @@ error[E0308]: mismatched types
--> $DIR/deref-suggestion.rs:37:5
|
LL | assert_eq!(3i32, &3i32);
| ^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `&i32`
| ^^^^^^^^^^^^^^^^^^^^^^^
| |
| expected `i32`, found `&i32`
| expected because this is `i32`
|
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@ -2,7 +2,9 @@ error[E0308]: mismatched types
--> $DIR/issue-47486.rs:2:10
|
LL | () < std::mem::size_of::<_>();
| ^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `usize`
| -- ^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `usize`
| |
| expected because this is `()`
error[E0282]: type annotations needed
--> $DIR/issue-47486.rs:3:11

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:10:15
|
LL | x_usize > -1_isize;
| ^^^^^^^^ expected `usize`, found `isize`
| ------- ^^^^^^^^ expected `usize`, found `isize`
| |
| expected because this is `usize`
|
= note: `-1_isize` cannot fit into type `usize`
@ -10,7 +12,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:12:14
|
LL | x_u128 > -1_isize;
| ^^^^^^^^ expected `u128`, found `isize`
| ------ ^^^^^^^^ expected `u128`, found `isize`
| |
| expected because this is `u128`
|
= note: `-1_isize` cannot fit into type `u128`
@ -18,7 +22,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:14:13
|
LL | x_u64 > -1_isize;
| ^^^^^^^^ expected `u64`, found `isize`
| ----- ^^^^^^^^ expected `u64`, found `isize`
| |
| expected because this is `u64`
|
= note: `-1_isize` cannot fit into type `u64`
@ -26,7 +32,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:16:13
|
LL | x_u32 > -1_isize;
| ^^^^^^^^ expected `u32`, found `isize`
| ----- ^^^^^^^^ expected `u32`, found `isize`
| |
| expected because this is `u32`
|
= note: `-1_isize` cannot fit into type `u32`
@ -34,7 +42,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:18:13
|
LL | x_u16 > -1_isize;
| ^^^^^^^^ expected `u16`, found `isize`
| ----- ^^^^^^^^ expected `u16`, found `isize`
| |
| expected because this is `u16`
|
= note: `-1_isize` cannot fit into type `u16`
@ -42,7 +52,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:20:12
|
LL | x_u8 > -1_isize;
| ^^^^^^^^ expected `u8`, found `isize`
| ---- ^^^^^^^^ expected `u8`, found `isize`
| |
| expected because this is `u8`
|
help: you can convert `x_u8` from `u8` to `isize`, matching the type of `-1_isize`
|
@ -53,7 +65,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:23:15
|
LL | x_usize > -1_i128;
| ^^^^^^^ expected `usize`, found `i128`
| ------- ^^^^^^^ expected `usize`, found `i128`
| |
| expected because this is `usize`
|
= note: `-1_i128` cannot fit into type `usize`
@ -61,7 +75,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:25:14
|
LL | x_u128 > -1_i128;
| ^^^^^^^ expected `u128`, found `i128`
| ------ ^^^^^^^ expected `u128`, found `i128`
| |
| expected because this is `u128`
|
= note: `-1_i128` cannot fit into type `u128`
@ -69,7 +85,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:27:13
|
LL | x_u64 > -1_i128;
| ^^^^^^^ expected `u64`, found `i128`
| ----- ^^^^^^^ expected `u64`, found `i128`
| |
| expected because this is `u64`
|
help: you can convert `x_u64` from `u64` to `i128`, matching the type of `-1_i128`
|
@ -80,7 +98,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:29:13
|
LL | x_u32 > -1_i128;
| ^^^^^^^ expected `u32`, found `i128`
| ----- ^^^^^^^ expected `u32`, found `i128`
| |
| expected because this is `u32`
|
help: you can convert `x_u32` from `u32` to `i128`, matching the type of `-1_i128`
|
@ -91,7 +111,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:31:13
|
LL | x_u16 > -1_i128;
| ^^^^^^^ expected `u16`, found `i128`
| ----- ^^^^^^^ expected `u16`, found `i128`
| |
| expected because this is `u16`
|
help: you can convert `x_u16` from `u16` to `i128`, matching the type of `-1_i128`
|
@ -102,7 +124,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:33:12
|
LL | x_u8 > -1_i128;
| ^^^^^^^ expected `u8`, found `i128`
| ---- ^^^^^^^ expected `u8`, found `i128`
| |
| expected because this is `u8`
|
help: you can convert `x_u8` from `u8` to `i128`, matching the type of `-1_i128`
|
@ -113,7 +137,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:36:15
|
LL | x_usize > -1_i64;
| ^^^^^^ expected `usize`, found `i64`
| ------- ^^^^^^ expected `usize`, found `i64`
| |
| expected because this is `usize`
|
= note: `-1_i64` cannot fit into type `usize`
@ -121,7 +147,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:38:14
|
LL | x_u128 > -1_i64;
| ^^^^^^ expected `u128`, found `i64`
| ------ ^^^^^^ expected `u128`, found `i64`
| |
| expected because this is `u128`
|
= note: `-1_i64` cannot fit into type `u128`
@ -129,7 +157,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:40:13
|
LL | x_u64 > -1_i64;
| ^^^^^^ expected `u64`, found `i64`
| ----- ^^^^^^ expected `u64`, found `i64`
| |
| expected because this is `u64`
|
= note: `-1_i64` cannot fit into type `u64`
@ -137,7 +167,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:42:13
|
LL | x_u32 > -1_i64;
| ^^^^^^ expected `u32`, found `i64`
| ----- ^^^^^^ expected `u32`, found `i64`
| |
| expected because this is `u32`
|
help: you can convert `x_u32` from `u32` to `i64`, matching the type of `-1_i64`
|
@ -148,7 +180,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:44:13
|
LL | x_u16 > -1_i64;
| ^^^^^^ expected `u16`, found `i64`
| ----- ^^^^^^ expected `u16`, found `i64`
| |
| expected because this is `u16`
|
help: you can convert `x_u16` from `u16` to `i64`, matching the type of `-1_i64`
|
@ -159,7 +193,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:46:12
|
LL | x_u8 > -1_i64;
| ^^^^^^ expected `u8`, found `i64`
| ---- ^^^^^^ expected `u8`, found `i64`
| |
| expected because this is `u8`
|
help: you can convert `x_u8` from `u8` to `i64`, matching the type of `-1_i64`
|
@ -170,7 +206,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:49:15
|
LL | x_usize > -1_i32;
| ^^^^^^ expected `usize`, found `i32`
| ------- ^^^^^^ expected `usize`, found `i32`
| |
| expected because this is `usize`
|
= note: `-1_i32` cannot fit into type `usize`
@ -178,7 +216,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:51:14
|
LL | x_u128 > -1_i32;
| ^^^^^^ expected `u128`, found `i32`
| ------ ^^^^^^ expected `u128`, found `i32`
| |
| expected because this is `u128`
|
= note: `-1_i32` cannot fit into type `u128`
@ -186,7 +226,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:53:13
|
LL | x_u64 > -1_i32;
| ^^^^^^ expected `u64`, found `i32`
| ----- ^^^^^^ expected `u64`, found `i32`
| |
| expected because this is `u64`
|
= note: `-1_i32` cannot fit into type `u64`
@ -194,7 +236,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:55:13
|
LL | x_u32 > -1_i32;
| ^^^^^^ expected `u32`, found `i32`
| ----- ^^^^^^ expected `u32`, found `i32`
| |
| expected because this is `u32`
|
= note: `-1_i32` cannot fit into type `u32`
@ -202,7 +246,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:57:13
|
LL | x_u16 > -1_i32;
| ^^^^^^ expected `u16`, found `i32`
| ----- ^^^^^^ expected `u16`, found `i32`
| |
| expected because this is `u16`
|
help: you can convert `x_u16` from `u16` to `i32`, matching the type of `-1_i32`
|
@ -213,7 +259,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:59:12
|
LL | x_u8 > -1_i32;
| ^^^^^^ expected `u8`, found `i32`
| ---- ^^^^^^ expected `u8`, found `i32`
| |
| expected because this is `u8`
|
help: you can convert `x_u8` from `u8` to `i32`, matching the type of `-1_i32`
|
@ -224,7 +272,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:62:15
|
LL | x_usize > -1_i16;
| ^^^^^^ expected `usize`, found `i16`
| ------- ^^^^^^ expected `usize`, found `i16`
| |
| expected because this is `usize`
|
= note: `-1_i16` cannot fit into type `usize`
@ -232,7 +282,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:64:14
|
LL | x_u128 > -1_i16;
| ^^^^^^ expected `u128`, found `i16`
| ------ ^^^^^^ expected `u128`, found `i16`
| |
| expected because this is `u128`
|
= note: `-1_i16` cannot fit into type `u128`
@ -240,7 +292,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:66:13
|
LL | x_u64 > -1_i16;
| ^^^^^^ expected `u64`, found `i16`
| ----- ^^^^^^ expected `u64`, found `i16`
| |
| expected because this is `u64`
|
= note: `-1_i16` cannot fit into type `u64`
@ -248,7 +302,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:68:13
|
LL | x_u32 > -1_i16;
| ^^^^^^ expected `u32`, found `i16`
| ----- ^^^^^^ expected `u32`, found `i16`
| |
| expected because this is `u32`
|
= note: `-1_i16` cannot fit into type `u32`
@ -256,7 +312,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:70:13
|
LL | x_u16 > -1_i16;
| ^^^^^^ expected `u16`, found `i16`
| ----- ^^^^^^ expected `u16`, found `i16`
| |
| expected because this is `u16`
|
= note: `-1_i16` cannot fit into type `u16`
@ -264,7 +322,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:72:12
|
LL | x_u8 > -1_i16;
| ^^^^^^ expected `u8`, found `i16`
| ---- ^^^^^^ expected `u8`, found `i16`
| |
| expected because this is `u8`
|
help: you can convert `x_u8` from `u8` to `i16`, matching the type of `-1_i16`
|
@ -275,7 +335,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:75:15
|
LL | x_usize > -1_i8;
| ^^^^^ expected `usize`, found `i8`
| ------- ^^^^^ expected `usize`, found `i8`
| |
| expected because this is `usize`
|
= note: `-1_i8` cannot fit into type `usize`
@ -283,7 +345,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:77:14
|
LL | x_u128 > -1_i8;
| ^^^^^ expected `u128`, found `i8`
| ------ ^^^^^ expected `u128`, found `i8`
| |
| expected because this is `u128`
|
= note: `-1_i8` cannot fit into type `u128`
@ -291,7 +355,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:79:13
|
LL | x_u64 > -1_i8;
| ^^^^^ expected `u64`, found `i8`
| ----- ^^^^^ expected `u64`, found `i8`
| |
| expected because this is `u64`
|
= note: `-1_i8` cannot fit into type `u64`
@ -299,7 +365,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:81:13
|
LL | x_u32 > -1_i8;
| ^^^^^ expected `u32`, found `i8`
| ----- ^^^^^ expected `u32`, found `i8`
| |
| expected because this is `u32`
|
= note: `-1_i8` cannot fit into type `u32`
@ -307,7 +375,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:83:13
|
LL | x_u16 > -1_i8;
| ^^^^^ expected `u16`, found `i8`
| ----- ^^^^^ expected `u16`, found `i8`
| |
| expected because this is `u16`
|
= note: `-1_i8` cannot fit into type `u16`
@ -315,7 +385,9 @@ error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:85:12
|
LL | x_u8 > -1_i8;
| ^^^^^ expected `u8`, found `i8`
| ---- ^^^^^ expected `u8`, found `i8`
| |
| expected because this is `u8`
|
= note: `-1_i8` cannot fit into type `u8`

View File

@ -34,7 +34,9 @@ error[E0308]: mismatched types
--> $DIR/bare-struct-body.rs:11:14
|
LL | x.val == 42;
| ^^ expected `()`, found integer
| ----- ^^ expected `()`, found integer
| |
| expected because this is `()`
error: aborting due to 3 previous errors

View File

@ -123,37 +123,49 @@ error[E0308]: mismatched types
--> $DIR/chained-comparison-suggestion.rs:4:14
|
LL | 1 < 2 <= 3;
| ^ expected `bool`, found integer
| ----- ^ expected `bool`, found integer
| |
| expected because this is `bool`
error[E0308]: mismatched types
--> $DIR/chained-comparison-suggestion.rs:13:14
|
LL | 1 <= 2 < 3;
| ^ expected `bool`, found integer
| ------ ^ expected `bool`, found integer
| |
| expected because this is `bool`
error[E0308]: mismatched types
--> $DIR/chained-comparison-suggestion.rs:18:15
|
LL | 1 <= 2 <= 3;
| ^ expected `bool`, found integer
| ------ ^ expected `bool`, found integer
| |
| expected because this is `bool`
error[E0308]: mismatched types
--> $DIR/chained-comparison-suggestion.rs:23:14
|
LL | 1 > 2 >= 3;
| ^ expected `bool`, found integer
| ----- ^ expected `bool`, found integer
| |
| expected because this is `bool`
error[E0308]: mismatched types
--> $DIR/chained-comparison-suggestion.rs:36:15
|
LL | 1 >= 2 >= 3;
| ^ expected `bool`, found integer
| ------ ^ expected `bool`, found integer
| |
| expected because this is `bool`
error[E0308]: mismatched types
--> $DIR/chained-comparison-suggestion.rs:49:15
|
LL | 1 == 2 == 3;
| ^ expected `bool`, found integer
| ------ ^ expected `bool`, found integer
| |
| expected because this is `bool`
error: aborting due to 17 previous errors

View File

@ -2,7 +2,9 @@ error[E0308]: mismatched types
--> $DIR/pptypedef.rs:4:37
|
LL | let_in(3u32, |i| { assert!(i == 3i32); });
| ^^^^ expected `u32`, found `i32`
| - ^^^^ expected `u32`, found `i32`
| |
| expected because this is `u32`
|
help: change the type of the numeric literal from `i32` to `u32`
|
@ -13,7 +15,9 @@ error[E0308]: mismatched types
--> $DIR/pptypedef.rs:8:37
|
LL | let_in(3i32, |i| { assert!(i == 3u32); });
| ^^^^ expected `i32`, found `u32`
| - ^^^^ expected `i32`, found `u32`
| |
| expected because this is `i32`
|
help: change the type of the numeric literal from `u32` to `i32`
|

View File

@ -2,7 +2,10 @@ error[E0308]: mismatched types
--> $DIR/dont-suggest-try_into-in-macros.rs:2:5
|
LL | assert_eq!(10u64, 10usize);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u64`, found `usize`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| expected `u64`, found `usize`
| expected because this is `u64`
|
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@ -2,7 +2,9 @@ error[E0308]: mismatched types
--> $DIR/option-to-bool.rs:4:16
|
LL | if true && x {}
| ^ expected `bool`, found enum `Option`
| ---- ^ expected `bool`, found enum `Option`
| |
| expected because this is `bool`
|
= note: expected type `bool`
found enum `Option<i32>`

View File

@ -68,7 +68,9 @@ error[E0308]: mismatched types
--> $DIR/assignment-in-if.rs:44:18
|
LL | if x == x && x = x && x == x {
| ^ expected `bool`, found `usize`
| ------ ^ expected `bool`, found `usize`
| |
| expected because this is `bool`
error[E0308]: mismatched types
--> $DIR/assignment-in-if.rs:44:22
@ -91,7 +93,9 @@ error[E0308]: mismatched types
--> $DIR/assignment-in-if.rs:51:28
|
LL | if x == x && x == x && x = x {
| ^ expected `bool`, found `usize`
| ---------------- ^ expected `bool`, found `usize`
| |
| expected because this is `bool`
error[E0308]: mismatched types
--> $DIR/assignment-in-if.rs:51:8

View File

@ -6,7 +6,9 @@ LL | trait BrokenAdd: Copy + Add<Output=Self> {
LL | fn broken_add<T>(&self, rhs: T) -> Self {
| - found type parameter
LL | *self + rhs
| ^^^ expected type parameter `Self`, found type parameter `T`
| ----- ^^^ expected type parameter `Self`, found type parameter `T`
| |
| expected because this is `Self`
|
= note: expected type parameter `Self`
found type parameter `T`

View File

@ -38,7 +38,9 @@ error[E0308]: mismatched types
--> $DIR/wrong-mul-method-signature.rs:63:45
|
LL | let x: Vec2 = Vec2 { x: 1.0, y: 2.0 } * 2.0; // trait had reversed order
| ^^^ expected struct `Vec2`, found floating-point number
| ----------------------- ^^^ expected struct `Vec2`, found floating-point number
| |
| expected because this is `Vec2`
error[E0308]: mismatched types
--> $DIR/wrong-mul-method-signature.rs:63:19