Skip to content

Commit e239fd2

Browse files
authored
Rollup merge of #97031 - eholk:drop-tracking-type-error, r=compiler-errors
Drop tracking: handle invalid assignments better Previously this test case was crashing with an index out of bounds error deep in the call to `needs_drop`. We avoid this by detecting clearly invalid assignees in the `mutate` callback and ignoring these.
2 parents ec14d94 + 6665a43 commit e239fd2

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

compiler/rustc_typeck/src/check/generator_interior/drop_ranges/record_consumed_borrow.rs

+9
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,15 @@ impl<'tcx> expr_use_visitor::Delegate<'tcx> for ExprUseDelegate<'tcx> {
180180
diag_expr_id: HirId,
181181
) {
182182
debug!("mutate {assignee_place:?}; diag_expr_id={diag_expr_id:?}");
183+
184+
if assignee_place.place.base == PlaceBase::Rvalue
185+
&& assignee_place.place.projections.is_empty()
186+
{
187+
// Assigning to an Rvalue is illegal unless done through a dereference. We would have
188+
// already gotten a type error, so we will just return here.
189+
return;
190+
}
191+
183192
// If the type being assigned needs dropped, then the mutation counts as a borrow
184193
// since it is essentially doing `Drop::drop(&mut x); x = new_value;`.
185194
if assignee_place.place.base_ty.needs_drop(self.tcx, self.param_env) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// edition:2018
2+
// compile-flags: -Zdrop-tracking
3+
// Regression test for issue #73741
4+
// Ensures that we don't emit spurious errors when
5+
// a type error ocurrs in an `async fn`
6+
7+
async fn weird() {
8+
1 = 2; //~ ERROR invalid left-hand side
9+
10+
let mut loop_count = 0;
11+
async {}.await
12+
}
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0070]: invalid left-hand side of assignment
2+
--> $DIR/issue-73741-type-err-drop-tracking.rs:8:7
3+
|
4+
LL | 1 = 2;
5+
| - ^
6+
| |
7+
| cannot assign to this expression
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0070`.

0 commit comments

Comments
 (0)