Skip to content

Use already checked RHS ty for LHS deref suggestions #103223

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

Merged
merged 1 commit into from
Oct 20, 2022
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
11 changes: 6 additions & 5 deletions compiler/rustc_hir_analysis/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1130,11 +1130,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
};

self.check_lhs_assignable(lhs, "E0070", span, |err| {
let rhs_ty = self.check_expr(&rhs);
suggest_deref_binop(err, rhs_ty);
});

// This is (basically) inlined `check_expr_coercable_to_type`, but we want
// to suggest an additional fixup here in `suggest_deref_binop`.
let rhs_ty = self.check_expr_with_hint(&rhs, lhs_ty);
Expand All @@ -1145,6 +1140,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
diag.emit();
}

self.check_lhs_assignable(lhs, "E0070", span, |err| {
if let Some(rhs_ty) = self.typeck_results.borrow().expr_ty_opt(rhs) {
suggest_deref_binop(err, rhs_ty);
}
});

self.require_type_is_sized(lhs_ty, lhs.span, traits::AssignmentLhsSized);

if lhs_ty.references_error() || rhs_ty.references_error() {
Expand Down
26 changes: 26 additions & 0 deletions src/test/ui/typeck/slow-lhs-suggestion.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
fn main() {
1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
//~^ ERROR invalid left-hand side of assignment
//~| ERROR invalid left-hand side of assignment
//~| ERROR invalid left-hand side of assignment
//~| ERROR invalid left-hand side of assignment
//~| ERROR invalid left-hand side of assignment
//~| ERROR invalid left-hand side of assignment
//~| ERROR invalid left-hand side of assignment
//~| ERROR invalid left-hand side of assignment
//~| ERROR invalid left-hand side of assignment
//~| ERROR invalid left-hand side of assignment
//~| ERROR invalid left-hand side of assignment
//~| ERROR invalid left-hand side of assignment
//~| ERROR invalid left-hand side of assignment
//~| ERROR invalid left-hand side of assignment
//~| ERROR invalid left-hand side of assignment
//~| ERROR invalid left-hand side of assignment
//~| ERROR invalid left-hand side of assignment
//~| ERROR invalid left-hand side of assignment
//~| ERROR invalid left-hand side of assignment
//~| ERROR invalid left-hand side of assignment
//~| ERROR invalid left-hand side of assignment
//~| ERROR invalid left-hand side of assignment
//~| ERROR invalid left-hand side of assignment
}
187 changes: 187 additions & 0 deletions src/test/ui/typeck/slow-lhs-suggestion.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
error[E0070]: invalid left-hand side of assignment
--> $DIR/slow-lhs-suggestion.rs:2:95
|
LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
| - ^
| |
| cannot assign to this expression

error[E0070]: invalid left-hand side of assignment
--> $DIR/slow-lhs-suggestion.rs:2:91
|
LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
| - ^
| |
| cannot assign to this expression

error[E0070]: invalid left-hand side of assignment
--> $DIR/slow-lhs-suggestion.rs:2:87
|
LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
| - ^
| |
| cannot assign to this expression

error[E0070]: invalid left-hand side of assignment
--> $DIR/slow-lhs-suggestion.rs:2:83
|
LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
| - ^
| |
| cannot assign to this expression

error[E0070]: invalid left-hand side of assignment
--> $DIR/slow-lhs-suggestion.rs:2:79
|
LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
| - ^
| |
| cannot assign to this expression

error[E0070]: invalid left-hand side of assignment
--> $DIR/slow-lhs-suggestion.rs:2:75
|
LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
| - ^
| |
| cannot assign to this expression

error[E0070]: invalid left-hand side of assignment
--> $DIR/slow-lhs-suggestion.rs:2:71
|
LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
| - ^
| |
| cannot assign to this expression

error[E0070]: invalid left-hand side of assignment
--> $DIR/slow-lhs-suggestion.rs:2:67
|
LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
| - ^
| |
| cannot assign to this expression

error[E0070]: invalid left-hand side of assignment
--> $DIR/slow-lhs-suggestion.rs:2:63
|
LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
| - ^
| |
| cannot assign to this expression

error[E0070]: invalid left-hand side of assignment
--> $DIR/slow-lhs-suggestion.rs:2:59
|
LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
| - ^
| |
| cannot assign to this expression

error[E0070]: invalid left-hand side of assignment
--> $DIR/slow-lhs-suggestion.rs:2:55
|
LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
| - ^
| |
| cannot assign to this expression

error[E0070]: invalid left-hand side of assignment
--> $DIR/slow-lhs-suggestion.rs:2:51
|
LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
| - ^
| |
| cannot assign to this expression

error[E0070]: invalid left-hand side of assignment
--> $DIR/slow-lhs-suggestion.rs:2:47
|
LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
| - ^
| |
| cannot assign to this expression

error[E0070]: invalid left-hand side of assignment
--> $DIR/slow-lhs-suggestion.rs:2:43
|
LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
| - ^
| |
| cannot assign to this expression

error[E0070]: invalid left-hand side of assignment
--> $DIR/slow-lhs-suggestion.rs:2:39
|
LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
| - ^
| |
| cannot assign to this expression

error[E0070]: invalid left-hand side of assignment
--> $DIR/slow-lhs-suggestion.rs:2:35
|
LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
| - ^
| |
| cannot assign to this expression

error[E0070]: invalid left-hand side of assignment
--> $DIR/slow-lhs-suggestion.rs:2:31
|
LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
| - ^
| |
| cannot assign to this expression

error[E0070]: invalid left-hand side of assignment
--> $DIR/slow-lhs-suggestion.rs:2:27
|
LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
| - ^
| |
| cannot assign to this expression

error[E0070]: invalid left-hand side of assignment
--> $DIR/slow-lhs-suggestion.rs:2:23
|
LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
| - ^
| |
| cannot assign to this expression

error[E0070]: invalid left-hand side of assignment
--> $DIR/slow-lhs-suggestion.rs:2:19
|
LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
| - ^
| |
| cannot assign to this expression

error[E0070]: invalid left-hand side of assignment
--> $DIR/slow-lhs-suggestion.rs:2:15
|
LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
| - ^
| |
| cannot assign to this expression

error[E0070]: invalid left-hand side of assignment
--> $DIR/slow-lhs-suggestion.rs:2:11
|
LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
| - ^
| |
| cannot assign to this expression

error[E0070]: invalid left-hand side of assignment
--> $DIR/slow-lhs-suggestion.rs:2:7
|
LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
| - ^
| |
| cannot assign to this expression

error: aborting due to 23 previous errors

For more information about this error, try `rustc --explain E0070`.