Skip to content

Commit e500dcb

Browse files
authored
Rollup merge of #103223 - compiler-errors:deref-sugg-slow, r=wesleywiser
Use already checked RHS ty for LHS deref suggestions There's no reason to do the `check_lhs_assignable` and RHS `check_expr_with_hint` in that order, so invert them and use the typeck results to avoid exponential blowup on error. Fixes #103219
2 parents 433f736 + d38dc68 commit e500dcb

File tree

3 files changed

+219
-5
lines changed

3 files changed

+219
-5
lines changed

compiler/rustc_hir_analysis/src/check/expr.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,11 +1130,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11301130
}
11311131
};
11321132

1133-
self.check_lhs_assignable(lhs, "E0070", span, |err| {
1134-
let rhs_ty = self.check_expr(&rhs);
1135-
suggest_deref_binop(err, rhs_ty);
1136-
});
1137-
11381133
// This is (basically) inlined `check_expr_coercable_to_type`, but we want
11391134
// to suggest an additional fixup here in `suggest_deref_binop`.
11401135
let rhs_ty = self.check_expr_with_hint(&rhs, lhs_ty);
@@ -1145,6 +1140,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11451140
diag.emit();
11461141
}
11471142

1143+
self.check_lhs_assignable(lhs, "E0070", span, |err| {
1144+
if let Some(rhs_ty) = self.typeck_results.borrow().expr_ty_opt(rhs) {
1145+
suggest_deref_binop(err, rhs_ty);
1146+
}
1147+
});
1148+
11481149
self.require_type_is_sized(lhs_ty, lhs.span, traits::AssignmentLhsSized);
11491150

11501151
if lhs_ty.references_error() || rhs_ty.references_error() {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
fn main() {
2+
1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
3+
//~^ ERROR invalid left-hand side of assignment
4+
//~| ERROR invalid left-hand side of assignment
5+
//~| ERROR invalid left-hand side of assignment
6+
//~| ERROR invalid left-hand side of assignment
7+
//~| ERROR invalid left-hand side of assignment
8+
//~| ERROR invalid left-hand side of assignment
9+
//~| ERROR invalid left-hand side of assignment
10+
//~| ERROR invalid left-hand side of assignment
11+
//~| ERROR invalid left-hand side of assignment
12+
//~| ERROR invalid left-hand side of assignment
13+
//~| ERROR invalid left-hand side of assignment
14+
//~| ERROR invalid left-hand side of assignment
15+
//~| ERROR invalid left-hand side of assignment
16+
//~| ERROR invalid left-hand side of assignment
17+
//~| ERROR invalid left-hand side of assignment
18+
//~| ERROR invalid left-hand side of assignment
19+
//~| ERROR invalid left-hand side of assignment
20+
//~| ERROR invalid left-hand side of assignment
21+
//~| ERROR invalid left-hand side of assignment
22+
//~| ERROR invalid left-hand side of assignment
23+
//~| ERROR invalid left-hand side of assignment
24+
//~| ERROR invalid left-hand side of assignment
25+
//~| ERROR invalid left-hand side of assignment
26+
}
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
error[E0070]: invalid left-hand side of assignment
2+
--> $DIR/slow-lhs-suggestion.rs:2:95
3+
|
4+
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;
5+
| - ^
6+
| |
7+
| cannot assign to this expression
8+
9+
error[E0070]: invalid left-hand side of assignment
10+
--> $DIR/slow-lhs-suggestion.rs:2:91
11+
|
12+
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;
13+
| - ^
14+
| |
15+
| cannot assign to this expression
16+
17+
error[E0070]: invalid left-hand side of assignment
18+
--> $DIR/slow-lhs-suggestion.rs:2:87
19+
|
20+
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;
21+
| - ^
22+
| |
23+
| cannot assign to this expression
24+
25+
error[E0070]: invalid left-hand side of assignment
26+
--> $DIR/slow-lhs-suggestion.rs:2:83
27+
|
28+
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;
29+
| - ^
30+
| |
31+
| cannot assign to this expression
32+
33+
error[E0070]: invalid left-hand side of assignment
34+
--> $DIR/slow-lhs-suggestion.rs:2:79
35+
|
36+
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;
37+
| - ^
38+
| |
39+
| cannot assign to this expression
40+
41+
error[E0070]: invalid left-hand side of assignment
42+
--> $DIR/slow-lhs-suggestion.rs:2:75
43+
|
44+
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;
45+
| - ^
46+
| |
47+
| cannot assign to this expression
48+
49+
error[E0070]: invalid left-hand side of assignment
50+
--> $DIR/slow-lhs-suggestion.rs:2:71
51+
|
52+
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;
53+
| - ^
54+
| |
55+
| cannot assign to this expression
56+
57+
error[E0070]: invalid left-hand side of assignment
58+
--> $DIR/slow-lhs-suggestion.rs:2:67
59+
|
60+
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;
61+
| - ^
62+
| |
63+
| cannot assign to this expression
64+
65+
error[E0070]: invalid left-hand side of assignment
66+
--> $DIR/slow-lhs-suggestion.rs:2:63
67+
|
68+
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;
69+
| - ^
70+
| |
71+
| cannot assign to this expression
72+
73+
error[E0070]: invalid left-hand side of assignment
74+
--> $DIR/slow-lhs-suggestion.rs:2:59
75+
|
76+
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;
77+
| - ^
78+
| |
79+
| cannot assign to this expression
80+
81+
error[E0070]: invalid left-hand side of assignment
82+
--> $DIR/slow-lhs-suggestion.rs:2:55
83+
|
84+
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;
85+
| - ^
86+
| |
87+
| cannot assign to this expression
88+
89+
error[E0070]: invalid left-hand side of assignment
90+
--> $DIR/slow-lhs-suggestion.rs:2:51
91+
|
92+
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;
93+
| - ^
94+
| |
95+
| cannot assign to this expression
96+
97+
error[E0070]: invalid left-hand side of assignment
98+
--> $DIR/slow-lhs-suggestion.rs:2:47
99+
|
100+
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;
101+
| - ^
102+
| |
103+
| cannot assign to this expression
104+
105+
error[E0070]: invalid left-hand side of assignment
106+
--> $DIR/slow-lhs-suggestion.rs:2:43
107+
|
108+
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;
109+
| - ^
110+
| |
111+
| cannot assign to this expression
112+
113+
error[E0070]: invalid left-hand side of assignment
114+
--> $DIR/slow-lhs-suggestion.rs:2:39
115+
|
116+
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;
117+
| - ^
118+
| |
119+
| cannot assign to this expression
120+
121+
error[E0070]: invalid left-hand side of assignment
122+
--> $DIR/slow-lhs-suggestion.rs:2:35
123+
|
124+
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;
125+
| - ^
126+
| |
127+
| cannot assign to this expression
128+
129+
error[E0070]: invalid left-hand side of assignment
130+
--> $DIR/slow-lhs-suggestion.rs:2:31
131+
|
132+
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;
133+
| - ^
134+
| |
135+
| cannot assign to this expression
136+
137+
error[E0070]: invalid left-hand side of assignment
138+
--> $DIR/slow-lhs-suggestion.rs:2:27
139+
|
140+
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;
141+
| - ^
142+
| |
143+
| cannot assign to this expression
144+
145+
error[E0070]: invalid left-hand side of assignment
146+
--> $DIR/slow-lhs-suggestion.rs:2:23
147+
|
148+
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;
149+
| - ^
150+
| |
151+
| cannot assign to this expression
152+
153+
error[E0070]: invalid left-hand side of assignment
154+
--> $DIR/slow-lhs-suggestion.rs:2:19
155+
|
156+
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;
157+
| - ^
158+
| |
159+
| cannot assign to this expression
160+
161+
error[E0070]: invalid left-hand side of assignment
162+
--> $DIR/slow-lhs-suggestion.rs:2:15
163+
|
164+
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;
165+
| - ^
166+
| |
167+
| cannot assign to this expression
168+
169+
error[E0070]: invalid left-hand side of assignment
170+
--> $DIR/slow-lhs-suggestion.rs:2:11
171+
|
172+
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;
173+
| - ^
174+
| |
175+
| cannot assign to this expression
176+
177+
error[E0070]: invalid left-hand side of assignment
178+
--> $DIR/slow-lhs-suggestion.rs:2:7
179+
|
180+
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;
181+
| - ^
182+
| |
183+
| cannot assign to this expression
184+
185+
error: aborting due to 23 previous errors
186+
187+
For more information about this error, try `rustc --explain E0070`.

0 commit comments

Comments
 (0)