Skip to content

Commit ef6851c

Browse files
committed
Added InitLocation to encode Location or Local depending on source of Init
1 parent 685fb54 commit ef6851c

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

src/librustc_mir/borrow_check/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,9 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
16011601
if let Some(&init_index) = first_init_index {
16021602
// And, if so, report an error.
16031603
let init = &self.move_data.inits[init_index];
1604-
self.report_illegal_reassignment(context, place_span, init.span, place_span.0);
1604+
self.report_illegal_reassignment(
1605+
context, place_span, init.span(&self.mir), place_span.0
1606+
);
16051607
}
16061608
}
16071609

src/librustc_mir/borrow_check/mutability_errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rustc::ty::{self, TyCtxt};
1616
use rustc_data_structures::indexed_vec::Idx;
1717
use syntax_pos::Span;
1818

19+
use dataflow::move_paths::InitLocation;
1920
use borrow_check::MirBorrowckCtxt;
2021
use util::borrowck_errors::{BorrowckErrors, Origin};
2122
use util::collect_writes::FindAssignments;

src/librustc_mir/dataflow/move_paths/builder.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::mem;
2020
use super::abs_domain::Lift;
2121

2222
use super::{LocationMap, MoveData, MovePath, MovePathLookup, MovePathIndex, MoveOut, MoveOutIndex};
23-
use super::{MoveError, InitIndex, Init, LookupResult, InitKind};
23+
use super::{MoveError, InitIndex, Init, InitLocation, LookupResult, InitKind};
2424
use super::IllegalMoveOriginKind::*;
2525

2626
struct MoveDataBuilder<'a, 'gcx: 'tcx, 'tcx: 'a> {
@@ -237,10 +237,9 @@ impl<'a, 'gcx, 'tcx> MoveDataBuilder<'a, 'gcx, 'tcx> {
237237
fn gather_args(&mut self) {
238238
for arg in self.mir.args_iter() {
239239
let path = self.data.rev_lookup.locals[arg];
240-
let span = self.mir.local_decls[arg].source_info.span;
241240

242241
let init = self.data.inits.push(Init {
243-
path, span, kind: InitKind::Deep
242+
path, kind: InitKind::Deep, location: InitLocation::Argument(arg),
244243
});
245244

246245
debug!("gather_args: adding init {:?} of {:?} for argument {:?}",
@@ -428,7 +427,7 @@ impl<'b, 'a, 'gcx, 'tcx> Gatherer<'b, 'a, 'gcx, 'tcx> {
428427

429428
if let LookupResult::Exact(path) = self.builder.data.rev_lookup.find(place) {
430429
let init = self.builder.data.inits.push(Init {
431-
span: self.builder.mir.source_info(self.loc).span,
430+
location: InitLocation::Statement(self.loc),
432431
path,
433432
kind,
434433
});

src/librustc_mir/dataflow/move_paths/mod.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,21 @@ impl fmt::Debug for MoveOut {
196196
pub struct Init {
197197
/// path being initialized
198198
pub path: MovePathIndex,
199-
/// span of initialization
200-
pub span: Span,
199+
/// location of initialization
200+
pub location: InitLocation,
201201
/// Extra information about this initialization
202202
pub kind: InitKind,
203203
}
204204

205+
206+
/// Initializations can be from an argument or from a statement. Arguments
207+
/// do not have locations, in those cases the `Local` is kept..
208+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
209+
pub enum InitLocation {
210+
Argument(Local),
211+
Statement(Location),
212+
}
213+
205214
/// Additional information about the initialization.
206215
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
207216
pub enum InitKind {
@@ -215,7 +224,16 @@ pub enum InitKind {
215224

216225
impl fmt::Debug for Init {
217226
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
218-
write!(fmt, "{:?}@{:?} ({:?})", self.path, self.span, self.kind)
227+
write!(fmt, "{:?}@{:?} ({:?})", self.path, self.location, self.kind)
228+
}
229+
}
230+
231+
impl Init {
232+
crate fn span<'gcx>(&self, mir: &Mir<'gcx>) -> Span {
233+
match self.location {
234+
InitLocation::Argument(local) => mir.local_decls[local].source_info.span,
235+
InitLocation::Statement(location) => mir.source_info(location).span,
236+
}
219237
}
220238
}
221239

0 commit comments

Comments
 (0)