Skip to content

Commit eab6d54

Browse files
csmoespastorino
authored andcommitted
add helper method to get base of place without projections
1 parent f8a9a1f commit eab6d54

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/librustc/mir/tcx.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,13 @@ impl<'tcx> NeoPlace<'tcx> {
299299
}
300300
}
301301

302-
pub fn has_no_projection(&self) -> bool {
303-
self.elems.is_empty()
302+
// Return the base of place without projections
303+
pub fn bare_place(&self) -> Option<&PlaceBase<'tcx>>{
304+
if self.elems.is_empty() {
305+
Some(&self.base)
306+
} else {
307+
None
308+
}
304309
}
305310
}
306311

src/librustc_mir/borrow_check/borrow_set.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -346,15 +346,14 @@ impl<'a, 'gcx, 'tcx> GatherBorrows<'a, 'gcx, 'tcx> {
346346
//
347347
// so extract `temp`.
348348
let neo_place = self.tcx.as_new_place(assigned_place);
349-
let temp = match neo_place.base {
350-
mir::PlaceBase::Local(temp) if neo_place.has_no_projection() => temp,
351-
_ => {
352-
span_bug!(
353-
self.mir.source_info(start_location).span,
354-
"expected 2-phase borrow to assign to a local, not `{:?}`",
355-
assigned_place,
356-
);
357-
}
349+
let temp = if let Some(mir::PlaceBase::Local(temp)) = neo_place.bare_place() {
350+
*temp
351+
} else {
352+
span_bug!(
353+
self.mir.source_info(start_location).span,
354+
"expected 2-phase borrow to assign to a local, not `{:?}`",
355+
assigned_place,
356+
);
358357
};
359358

360359
// Consider the borrow not activated to start. When we find an activation, we'll update

0 commit comments

Comments
 (0)