Added InitLocation to encode Location or Local depending on source of Init
This commit is contained in:
parent
685fb54317
commit
ef6851cdb2
4 changed files with 28 additions and 8 deletions
|
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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> {
|
||||
|
|
@ -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 {:?}",
|
||||
|
|
@ -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,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue