Skip to content

Commit d5b7205

Browse files
committed
Count copies of locals as borrowed temporaries
1 parent 577bf0f commit d5b7205

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,13 @@ impl<'tcx> expr_use_visitor::Delegate<'tcx> for ExprUseDelegate<'tcx> {
171171
.insert(TrackedValue::from_place_with_projections_allowed(place_with_id));
172172

173173
// For copied we treat this mostly like a borrow except that we don't add the place
174-
// to borrowed_temporaries because the copy is consumed.
174+
// to borrowed_temporaries if it is not a local because the copy is consumed.
175+
match place_with_id.place.base {
176+
PlaceBase::Rvalue | PlaceBase::StaticItem | PlaceBase::Upvar(_) => (),
177+
PlaceBase::Local(_) => {
178+
self.places.borrowed_temporaries.insert(place_with_id.hir_id);
179+
}
180+
}
175181
}
176182

177183
fn mutate(

src/test/ui/generator/drop-tracking-yielding-in-match-guards.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,20 @@
1414
#![feature(generators)]
1515

1616
fn main() {
17-
let _ = static |x: u8| match x {
17+
let _a = static |x: u8| match x {
1818
y if { yield } == y + 1 => (),
1919
_ => (),
2020
};
21+
22+
static STATIC: u8 = 42;
23+
let _b = static |x: u8| match x {
24+
y if { yield } == STATIC + 1 => (),
25+
_ => (),
26+
};
27+
28+
let upvar = 42u8;
29+
let _c = static |x: u8| match x {
30+
y if { yield } == upvar + 1 => (),
31+
_ => (),
32+
};
2133
}

0 commit comments

Comments
 (0)