Skip to content

Commit 66a1800

Browse files
committed
Remove Place::local & Place::base_local and use NeoPlace::base_local instead
1 parent 42479d3 commit 66a1800

File tree

4 files changed

+44
-39
lines changed

4 files changed

+44
-39
lines changed

src/librustc/mir/mod.rs

+9-24
Original file line numberDiff line numberDiff line change
@@ -2110,30 +2110,6 @@ impl<'tcx> Place<'tcx> {
21102110
pub fn elem(self, elem: PlaceElem<'tcx>) -> Place<'tcx> {
21112111
Place::Projection(Box::new(PlaceProjection { base: self, elem }))
21122112
}
2113-
2114-
/// Find the innermost `Local` from this `Place`, *if* it is either a local itself or
2115-
/// a single deref of a local.
2116-
///
2117-
/// FIXME: can we safely swap the semantics of `fn base_local` below in here instead?
2118-
pub fn local(&self) -> Option<Local> {
2119-
match self {
2120-
Place::Local(local) |
2121-
Place::Projection(box Projection {
2122-
base: Place::Local(local),
2123-
elem: ProjectionElem::Deref,
2124-
}) => Some(*local),
2125-
_ => None,
2126-
}
2127-
}
2128-
2129-
/// Find the innermost `Local` from this `Place`.
2130-
pub fn base_local(&self) -> Option<Local> {
2131-
match self {
2132-
Place::Local(local) => Some(*local),
2133-
Place::Projection(box Projection { base, elem: _ }) => base.base_local(),
2134-
Place::Promoted(..) | Place::Static(..) => None,
2135-
}
2136-
}
21372113
}
21382114

21392115
impl<'tcx> NeoPlace<'tcx> {
@@ -2184,6 +2160,15 @@ impl<'tcx> NeoPlace<'tcx> {
21842160
self.elem(tcx, ProjectionElem::Index(index))
21852161
}
21862162

2163+
/// Find the innermost `Local` from this `Place`.
2164+
pub fn base_local(&self) -> Option<Local> {
2165+
if let PlaceBase::Local(local) = self.base {
2166+
Some(local)
2167+
} else {
2168+
None
2169+
}
2170+
}
2171+
21872172
pub fn constant_index(
21882173
self,
21892174
tcx: TyCtxt<'_, '_, 'tcx>,

src/librustc_mir/borrow_check/error_reporting.rs

+27-11
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
579579
// is a union.
580580
let is_union = |place: &Place<'tcx>| -> bool {
581581
let neo_place = self.infcx.tcx.as_new_place(place);
582-
neo_place.ty(self.mir, self.infcx.tcx)
582+
neo_place
583+
.ty(self.mir, self.infcx.tcx)
583584
.to_ty(self.infcx.tcx)
584585
.ty_adt_def()
585586
.map(|adt| adt.is_union())
@@ -1481,15 +1482,22 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
14811482
diag: &mut DiagnosticBuilder<'_>,
14821483
) {
14831484
debug!("add_moved_or_invoked_closure_note: location={:?} place={:?}", location, place);
1484-
let mut target = place.local();
1485+
let neo_place = self.infcx.tcx.as_new_place(place);
1486+
let mut target = neo_place.base_local();
14851487
for stmt in &self.mir[location.block].statements[location.statement_index..] {
14861488
debug!("add_moved_or_invoked_closure_note: stmt={:?} target={:?}", stmt, target);
14871489
if let StatementKind::Assign(into, box Rvalue::Use(from)) = &stmt.kind {
14881490
debug!("add_fnonce_closure_note: into={:?} from={:?}", into, from);
14891491
match from {
1490-
Operand::Copy(ref place) |
1491-
Operand::Move(ref place) if target == place.local() =>
1492-
target = into.local(),
1492+
Operand::Copy(ref place) | Operand::Move(ref place)
1493+
if {
1494+
let neo_place = self.infcx.tcx.as_new_place(place);
1495+
target == neo_place.base_local()
1496+
} =>
1497+
{
1498+
let neo_into = self.infcx.tcx.as_new_place(into);
1499+
target = neo_into.base_local();
1500+
}
14931501
_ => {},
14941502
}
14951503
}
@@ -1512,9 +1520,14 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
15121520
debug!("add_moved_or_invoked_closure_note: id={:?}", id);
15131521
if self.infcx.tcx.parent(id) == self.infcx.tcx.lang_items().fn_once_trait() {
15141522
let closure = match args.first() {
1515-
Some(Operand::Copy(ref place)) |
1516-
Some(Operand::Move(ref place)) if target == place.local() =>
1517-
place.local().unwrap(),
1523+
Some(Operand::Copy(ref place)) | Some(Operand::Move(ref place))
1524+
if {
1525+
let neo_place = self.infcx.tcx.as_new_place(place);
1526+
target == neo_place.base_local()
1527+
} =>
1528+
{
1529+
neo_place.base_local().unwrap()
1530+
}
15181531
_ => return,
15191532
};
15201533

@@ -1949,7 +1962,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
19491962
);
19501963

19511964
// Find the local from the operand.
1952-
let assigned_from_local = match assigned_from.local() {
1965+
let neo_assigned_from = self.infcx.tcx.as_new_place(assigned_from);
1966+
let assigned_from_local = match neo_assigned_from.base_local() {
19531967
Some(local) => local,
19541968
None => continue,
19551969
};
@@ -2005,7 +2019,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
20052019
);
20062020

20072021
// Find the local from the rvalue.
2008-
let assigned_from_local = match assigned_from.local() {
2022+
let neo_assigned_from = self.infcx.tcx.as_new_place(assigned_from);
2023+
let assigned_from_local = match neo_assigned_from.base_local() {
20092024
Some(local) => local,
20102025
None => continue,
20112026
};
@@ -2068,7 +2083,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
20682083
assigned_from,
20692084
);
20702085

2071-
if let Some(assigned_from_local) = assigned_from.local() {
2086+
let neo_assigned_from = self.infcx.tcx.as_new_place(assigned_from);
2087+
if let Some(assigned_from_local) = neo_assigned_from.base_local() {
20722088
debug!(
20732089
"annotate_argument_and_return_for_borrow: assigned_from_local={:?}",
20742090
assigned_from_local,

src/librustc_mir/borrow_check/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1680,7 +1680,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
16801680
ty::Adt(..) | ty::Tuple(..) => {
16811681
check_parent_of_field(self, context, base, span, flow_state);
16821682

1683-
if let Some(local) = place.base_local() {
1683+
let neo_place = tcx.as_new_place(place);
1684+
if let Some(local) = neo_place.base_local() {
16841685
// rust-lang/rust#21232,
16851686
// #54499, #54986: during
16861687
// period where we reject
@@ -1814,7 +1815,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
18141815
// partial initialization, do not complain about mutability
18151816
// errors except for actual mutation (as opposed to an attempt
18161817
// to do a partial initialization).
1817-
let previously_initialized = if let Some(local) = place.base_local() {
1818+
let neo_place = self.infcx.tcx.as_new_place(place);
1819+
let previously_initialized = if let Some(local) = neo_place.base_local() {
18181820
self.is_local_ever_initialized(local, flow_state).is_some()
18191821
} else {
18201822
true

src/librustc_mir/borrow_check/used_muts.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ impl<'visit, 'cx, 'gcx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'c
6161
debug!("visit_terminator_kind: kind={:?}", kind);
6262
match &kind {
6363
TerminatorKind::Call { destination: Some((into, _)), .. } => {
64-
if let Some(local) = into.base_local() {
64+
let neo_into = self.mbcx.infcx.tcx.as_new_place(into);
65+
if let Some(local) = neo_into.base_local() {
6566
debug!(
6667
"visit_terminator_kind: kind={:?} local={:?} \
6768
never_initialized_mut_locals={:?}",
@@ -87,7 +88,8 @@ impl<'visit, 'cx, 'gcx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'c
8788
// be those that were never initialized - we will consider those as being used as
8889
// they will either have been removed by unreachable code optimizations; or linted
8990
// as unused variables.
90-
if let Some(local) = into.base_local() {
91+
let neo_into = self.mbcx.infcx.tcx.as_new_place(into);
92+
if let Some(local) = neo_into.base_local() {
9193
debug!(
9294
"visit_statement: statement={:?} local={:?} \
9395
never_initialized_mut_locals={:?}",

0 commit comments

Comments
 (0)