Skip to content

Commit

Permalink
Added InitLocation to encode Location or Local depending on source of…
Browse files Browse the repository at this point in the history
… Init
  • Loading branch information
davidtwco committed Aug 30, 2018
1 parent 685fb54 commit ef6851c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/librustc_mir/borrow_check/mod.rs
Expand Up @@ -1601,7 +1601,9 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
if let Some(&init_index) = first_init_index {
// And, if so, report an error.
let init = &self.move_data.inits[init_index];
self.report_illegal_reassignment(context, place_span, init.span, place_span.0);
self.report_illegal_reassignment(
context, place_span, init.span(&self.mir), place_span.0
);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/librustc_mir/borrow_check/mutability_errors.rs
Expand Up @@ -16,6 +16,7 @@ use rustc::ty::{self, TyCtxt};
use rustc_data_structures::indexed_vec::Idx;
use syntax_pos::Span;

use dataflow::move_paths::InitLocation;
use borrow_check::MirBorrowckCtxt;
use util::borrowck_errors::{BorrowckErrors, Origin};
use util::collect_writes::FindAssignments;
Expand Down
7 changes: 3 additions & 4 deletions src/librustc_mir/dataflow/move_paths/builder.rs
Expand Up @@ -20,7 +20,7 @@ use std::mem;
use super::abs_domain::Lift;

use super::{LocationMap, MoveData, MovePath, MovePathLookup, MovePathIndex, MoveOut, MoveOutIndex};
use super::{MoveError, InitIndex, Init, LookupResult, InitKind};
use super::{MoveError, InitIndex, Init, InitLocation, LookupResult, InitKind};
use super::IllegalMoveOriginKind::*;

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

let init = self.data.inits.push(Init {
path, span, kind: InitKind::Deep
path, kind: InitKind::Deep, location: InitLocation::Argument(arg),
});

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

if let LookupResult::Exact(path) = self.builder.data.rev_lookup.find(place) {
let init = self.builder.data.inits.push(Init {
span: self.builder.mir.source_info(self.loc).span,
location: InitLocation::Statement(self.loc),
path,
kind,
});
Expand Down
24 changes: 21 additions & 3 deletions src/librustc_mir/dataflow/move_paths/mod.rs
Expand Up @@ -196,12 +196,21 @@ impl fmt::Debug for MoveOut {
pub struct Init {
/// path being initialized
pub path: MovePathIndex,
/// span of initialization
pub span: Span,
/// location of initialization
pub location: InitLocation,
/// Extra information about this initialization
pub kind: InitKind,
}


/// Initializations can be from an argument or from a statement. Arguments
/// do not have locations, in those cases the `Local` is kept..
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum InitLocation {
Argument(Local),
Statement(Location),
}

/// Additional information about the initialization.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum InitKind {
Expand All @@ -215,7 +224,16 @@ pub enum InitKind {

impl fmt::Debug for Init {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{:?}@{:?} ({:?})", self.path, self.span, self.kind)
write!(fmt, "{:?}@{:?} ({:?})", self.path, self.location, self.kind)
}
}

impl Init {
crate fn span<'gcx>(&self, mir: &Mir<'gcx>) -> Span {
match self.location {
InitLocation::Argument(local) => mir.local_decls[local].source_info.span,
InitLocation::Statement(location) => mir.source_info(location).span,
}
}
}

Expand Down

0 comments on commit ef6851c

Please sign in to comment.