Do not report errors from move path builder.
This commit is contained in:
parent
a8e56d0b0b
commit
8d535070a2
11 changed files with 305 additions and 172 deletions
|
@ -46,6 +46,7 @@ mod mutability_errors;
|
||||||
mod region_errors;
|
mod region_errors;
|
||||||
|
|
||||||
pub(crate) use bound_region_errors::{ToUniverseInfo, UniverseInfo};
|
pub(crate) use bound_region_errors::{ToUniverseInfo, UniverseInfo};
|
||||||
|
pub(crate) use move_errors::MoveError;
|
||||||
pub(crate) use mutability_errors::AccessKind;
|
pub(crate) use mutability_errors::AccessKind;
|
||||||
pub(crate) use outlives_suggestion::OutlivesSuggestionBuilder;
|
pub(crate) use outlives_suggestion::OutlivesSuggestionBuilder;
|
||||||
pub(crate) use region_errors::{ErrorConstraintInfo, RegionErrorKind, RegionErrors};
|
pub(crate) use region_errors::{ErrorConstraintInfo, RegionErrorKind, RegionErrors};
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed};
|
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed};
|
||||||
use rustc_middle::mir::*;
|
use rustc_middle::mir::*;
|
||||||
use rustc_middle::ty;
|
use rustc_middle::ty;
|
||||||
use rustc_mir_dataflow::move_paths::{
|
use rustc_mir_dataflow::move_paths::{IllegalMoveOriginKind, LookupResult, MovePathIndex};
|
||||||
IllegalMoveOrigin, IllegalMoveOriginKind, LookupResult, MoveError, MovePathIndex,
|
|
||||||
};
|
|
||||||
use rustc_span::{BytePos, Span};
|
use rustc_span::{BytePos, Span};
|
||||||
|
|
||||||
use crate::diagnostics::CapturedMessageOpt;
|
use crate::diagnostics::CapturedMessageOpt;
|
||||||
|
@ -11,6 +9,23 @@ use crate::diagnostics::{DescribePlaceOpt, UseSpans};
|
||||||
use crate::prefixes::PrefixSet;
|
use crate::prefixes::PrefixSet;
|
||||||
use crate::MirBorrowckCtxt;
|
use crate::MirBorrowckCtxt;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub(crate) struct MoveError<'tcx> {
|
||||||
|
place: Place<'tcx>,
|
||||||
|
location: Location,
|
||||||
|
kind: IllegalMoveOriginKind<'tcx>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'tcx> MoveError<'tcx> {
|
||||||
|
pub(crate) fn new(
|
||||||
|
place: Place<'tcx>,
|
||||||
|
location: Location,
|
||||||
|
kind: IllegalMoveOriginKind<'tcx>,
|
||||||
|
) -> Self {
|
||||||
|
MoveError { place, location, kind }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Often when desugaring a pattern match we may have many individual moves in
|
// Often when desugaring a pattern match we may have many individual moves in
|
||||||
// MIR that are all part of one operation from the user's point-of-view. For
|
// MIR that are all part of one operation from the user's point-of-view. For
|
||||||
// example:
|
// example:
|
||||||
|
@ -53,20 +68,18 @@ enum GroupedMoveError<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
pub(crate) fn report_move_errors(&mut self, move_errors: Vec<(Place<'tcx>, MoveError<'tcx>)>) {
|
pub(crate) fn report_move_errors(&mut self) {
|
||||||
let grouped_errors = self.group_move_errors(move_errors);
|
let grouped_errors = self.group_move_errors();
|
||||||
for error in grouped_errors {
|
for error in grouped_errors {
|
||||||
self.report(error);
|
self.report(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn group_move_errors(
|
fn group_move_errors(&mut self) -> Vec<GroupedMoveError<'tcx>> {
|
||||||
&self,
|
|
||||||
errors: Vec<(Place<'tcx>, MoveError<'tcx>)>,
|
|
||||||
) -> Vec<GroupedMoveError<'tcx>> {
|
|
||||||
let mut grouped_errors = Vec::new();
|
let mut grouped_errors = Vec::new();
|
||||||
for (original_path, error) in errors {
|
let errors = std::mem::take(&mut self.move_errors);
|
||||||
self.append_to_grouped_errors(&mut grouped_errors, original_path, error);
|
for error in errors {
|
||||||
|
self.append_to_grouped_errors(&mut grouped_errors, error);
|
||||||
}
|
}
|
||||||
grouped_errors
|
grouped_errors
|
||||||
}
|
}
|
||||||
|
@ -74,22 +87,16 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
fn append_to_grouped_errors(
|
fn append_to_grouped_errors(
|
||||||
&self,
|
&self,
|
||||||
grouped_errors: &mut Vec<GroupedMoveError<'tcx>>,
|
grouped_errors: &mut Vec<GroupedMoveError<'tcx>>,
|
||||||
original_path: Place<'tcx>,
|
|
||||||
error: MoveError<'tcx>,
|
error: MoveError<'tcx>,
|
||||||
) {
|
) {
|
||||||
match error {
|
let MoveError { place: original_path, location, kind } = error;
|
||||||
MoveError::UnionMove { .. } => {
|
|
||||||
unimplemented!("don't know how to report union move errors yet.")
|
|
||||||
}
|
|
||||||
MoveError::IllegalMove { cannot_move_out_of: IllegalMoveOrigin { location, kind } } => {
|
|
||||||
// Note: that the only time we assign a place isn't a temporary
|
// Note: that the only time we assign a place isn't a temporary
|
||||||
// to a user variable is when initializing it.
|
// to a user variable is when initializing it.
|
||||||
// If that ever stops being the case, then the ever initialized
|
// If that ever stops being the case, then the ever initialized
|
||||||
// flow could be used.
|
// flow could be used.
|
||||||
if let Some(StatementKind::Assign(box (
|
if let Some(StatementKind::Assign(box (place, Rvalue::Use(Operand::Move(move_from))))) =
|
||||||
place,
|
self.body.basic_blocks[location.block]
|
||||||
Rvalue::Use(Operand::Move(move_from)),
|
|
||||||
))) = self.body.basic_blocks[location.block]
|
|
||||||
.statements
|
.statements
|
||||||
.get(location.statement_index)
|
.get(location.statement_index)
|
||||||
.map(|stmt| &stmt.kind)
|
.map(|stmt| &stmt.kind)
|
||||||
|
@ -133,8 +140,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
kind,
|
kind,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn append_binding_error(
|
fn append_binding_error(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -31,13 +31,8 @@ use rustc_index::{IndexSlice, IndexVec};
|
||||||
use rustc_infer::infer::{
|
use rustc_infer::infer::{
|
||||||
InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin, TyCtxtInferExt,
|
InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin, TyCtxtInferExt,
|
||||||
};
|
};
|
||||||
use rustc_middle::mir::{
|
use rustc_middle::mir::tcx::PlaceTy;
|
||||||
traversal, Body, ClearCrossCrate, Local, Location, MutBorrowKind, Mutability,
|
use rustc_middle::mir::*;
|
||||||
NonDivergingIntrinsic, Operand, Place, PlaceElem, PlaceRef, VarDebugInfoContents,
|
|
||||||
};
|
|
||||||
use rustc_middle::mir::{AggregateKind, BasicBlock, BorrowCheckResult, BorrowKind};
|
|
||||||
use rustc_middle::mir::{InlineAsmOperand, Terminator, TerminatorKind};
|
|
||||||
use rustc_middle::mir::{ProjectionElem, Promoted, Rvalue, Statement, StatementKind};
|
|
||||||
use rustc_middle::query::Providers;
|
use rustc_middle::query::Providers;
|
||||||
use rustc_middle::traits::DefiningAnchor;
|
use rustc_middle::traits::DefiningAnchor;
|
||||||
use rustc_middle::ty::{self, CapturedPlace, ParamEnv, RegionVid, TyCtxt};
|
use rustc_middle::ty::{self, CapturedPlace, ParamEnv, RegionVid, TyCtxt};
|
||||||
|
@ -54,14 +49,16 @@ use std::rc::Rc;
|
||||||
use rustc_mir_dataflow::impls::{
|
use rustc_mir_dataflow::impls::{
|
||||||
EverInitializedPlaces, MaybeInitializedPlaces, MaybeUninitializedPlaces,
|
EverInitializedPlaces, MaybeInitializedPlaces, MaybeUninitializedPlaces,
|
||||||
};
|
};
|
||||||
use rustc_mir_dataflow::move_paths::{InitIndex, MoveOutIndex, MovePathIndex};
|
use rustc_mir_dataflow::move_paths::{
|
||||||
use rustc_mir_dataflow::move_paths::{InitLocation, LookupResult, MoveData, MoveError};
|
IllegalMoveOriginKind, InitIndex, MoveOutIndex, MovePathIndex,
|
||||||
|
};
|
||||||
|
use rustc_mir_dataflow::move_paths::{InitLocation, LookupResult, MoveData};
|
||||||
use rustc_mir_dataflow::Analysis;
|
use rustc_mir_dataflow::Analysis;
|
||||||
use rustc_mir_dataflow::MoveDataParamEnv;
|
use rustc_mir_dataflow::MoveDataParamEnv;
|
||||||
|
|
||||||
use crate::session_diagnostics::VarNeedNotMut;
|
use crate::session_diagnostics::VarNeedNotMut;
|
||||||
|
|
||||||
use self::diagnostics::{AccessKind, RegionName};
|
use self::diagnostics::{AccessKind, MoveError, RegionName};
|
||||||
use self::location::LocationTable;
|
use self::location::LocationTable;
|
||||||
use self::prefixes::PrefixSet;
|
use self::prefixes::PrefixSet;
|
||||||
use consumers::{BodyWithBorrowckFacts, ConsumerOptions};
|
use consumers::{BodyWithBorrowckFacts, ConsumerOptions};
|
||||||
|
@ -224,12 +221,8 @@ fn do_mir_borrowck<'tcx>(
|
||||||
let location_table_owned = LocationTable::new(body);
|
let location_table_owned = LocationTable::new(body);
|
||||||
let location_table = &location_table_owned;
|
let location_table = &location_table_owned;
|
||||||
|
|
||||||
let (move_data, move_errors): (MoveData<'tcx>, Vec<(Place<'tcx>, MoveError<'tcx>)>) =
|
let move_data = MoveData::gather_moves(&body, tcx, param_env);
|
||||||
match MoveData::gather_moves(&body, tcx, param_env) {
|
let promoted_move_data = promoted
|
||||||
Ok(move_data) => (move_data, Vec::new()),
|
|
||||||
Err((move_data, move_errors)) => (move_data, move_errors),
|
|
||||||
};
|
|
||||||
let promoted_errors = promoted
|
|
||||||
.iter_enumerated()
|
.iter_enumerated()
|
||||||
.map(|(idx, body)| (idx, MoveData::gather_moves(&body, tcx, param_env)));
|
.map(|(idx, body)| (idx, MoveData::gather_moves(&body, tcx, param_env)));
|
||||||
|
|
||||||
|
@ -313,10 +306,10 @@ fn do_mir_borrowck<'tcx>(
|
||||||
true
|
true
|
||||||
};
|
};
|
||||||
|
|
||||||
for (idx, move_data_results) in promoted_errors {
|
for (idx, move_data) in promoted_move_data {
|
||||||
let promoted_body = &promoted[idx];
|
use rustc_middle::mir::visit::Visitor;
|
||||||
|
|
||||||
if let Err((move_data, move_errors)) = move_data_results {
|
let promoted_body = &promoted[idx];
|
||||||
let mut promoted_mbcx = MirBorrowckCtxt {
|
let mut promoted_mbcx = MirBorrowckCtxt {
|
||||||
infcx: &infcx,
|
infcx: &infcx,
|
||||||
param_env,
|
param_env,
|
||||||
|
@ -338,11 +331,24 @@ fn do_mir_borrowck<'tcx>(
|
||||||
region_names: RefCell::default(),
|
region_names: RefCell::default(),
|
||||||
next_region_name: RefCell::new(1),
|
next_region_name: RefCell::new(1),
|
||||||
polonius_output: None,
|
polonius_output: None,
|
||||||
|
move_errors: Vec::new(),
|
||||||
errors,
|
errors,
|
||||||
};
|
};
|
||||||
promoted_mbcx.report_move_errors(move_errors);
|
MoveVisitor { ctxt: &mut promoted_mbcx }.visit_body(promoted_body);
|
||||||
|
promoted_mbcx.report_move_errors();
|
||||||
errors = promoted_mbcx.errors;
|
errors = promoted_mbcx.errors;
|
||||||
};
|
|
||||||
|
struct MoveVisitor<'a, 'cx, 'tcx> {
|
||||||
|
ctxt: &'a mut MirBorrowckCtxt<'cx, 'tcx>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'tcx> Visitor<'tcx> for MoveVisitor<'_, '_, 'tcx> {
|
||||||
|
fn visit_operand(&mut self, operand: &Operand<'tcx>, location: Location) {
|
||||||
|
if let Operand::Move(place) = operand {
|
||||||
|
self.ctxt.check_movable_place(location, *place);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut mbcx = MirBorrowckCtxt {
|
let mut mbcx = MirBorrowckCtxt {
|
||||||
|
@ -366,6 +372,7 @@ fn do_mir_borrowck<'tcx>(
|
||||||
region_names: RefCell::default(),
|
region_names: RefCell::default(),
|
||||||
next_region_name: RefCell::new(1),
|
next_region_name: RefCell::new(1),
|
||||||
polonius_output,
|
polonius_output,
|
||||||
|
move_errors: Vec::new(),
|
||||||
errors,
|
errors,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -378,8 +385,6 @@ fn do_mir_borrowck<'tcx>(
|
||||||
borrows: flow_borrows,
|
borrows: flow_borrows,
|
||||||
};
|
};
|
||||||
|
|
||||||
mbcx.report_move_errors(move_errors);
|
|
||||||
|
|
||||||
rustc_mir_dataflow::visit_results(
|
rustc_mir_dataflow::visit_results(
|
||||||
body,
|
body,
|
||||||
traversal::reverse_postorder(body).map(|(bb, _)| bb),
|
traversal::reverse_postorder(body).map(|(bb, _)| bb),
|
||||||
|
@ -387,6 +392,8 @@ fn do_mir_borrowck<'tcx>(
|
||||||
&mut mbcx,
|
&mut mbcx,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
mbcx.report_move_errors();
|
||||||
|
|
||||||
// For each non-user used mutable variable, check if it's been assigned from
|
// For each non-user used mutable variable, check if it's been assigned from
|
||||||
// a user-declared local. If so, then put that local into the used_mut set.
|
// a user-declared local. If so, then put that local into the used_mut set.
|
||||||
// Note that this set is expected to be small - only upvars from closures
|
// Note that this set is expected to be small - only upvars from closures
|
||||||
|
@ -595,6 +602,7 @@ struct MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
polonius_output: Option<Rc<PoloniusOutput>>,
|
polonius_output: Option<Rc<PoloniusOutput>>,
|
||||||
|
|
||||||
errors: error::BorrowckErrors<'tcx>,
|
errors: error::BorrowckErrors<'tcx>,
|
||||||
|
move_errors: Vec<MoveError<'tcx>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that:
|
// Check that:
|
||||||
|
@ -725,7 +733,6 @@ impl<'cx, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx, R> for MirBorro
|
||||||
}
|
}
|
||||||
TerminatorKind::Assert { cond, expected: _, msg, target: _, unwind: _ } => {
|
TerminatorKind::Assert { cond, expected: _, msg, target: _, unwind: _ } => {
|
||||||
self.consume_operand(loc, (cond, span), flow_state);
|
self.consume_operand(loc, (cond, span), flow_state);
|
||||||
use rustc_middle::mir::AssertKind;
|
|
||||||
if let AssertKind::BoundsCheck { len, index } = &**msg {
|
if let AssertKind::BoundsCheck { len, index } = &**msg {
|
||||||
self.consume_operand(loc, (len, span), flow_state);
|
self.consume_operand(loc, (len, span), flow_state);
|
||||||
self.consume_operand(loc, (index, span), flow_state);
|
self.consume_operand(loc, (index, span), flow_state);
|
||||||
|
@ -1469,6 +1476,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Operand::Move(place) => {
|
Operand::Move(place) => {
|
||||||
|
// Check if moving from this place makes sense.
|
||||||
|
self.check_movable_place(location, place);
|
||||||
|
|
||||||
// move of place: check if this is move of already borrowed path
|
// move of place: check if this is move of already borrowed path
|
||||||
self.access_place(
|
self.access_place(
|
||||||
location,
|
location,
|
||||||
|
@ -1590,6 +1600,145 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn check_movable_place(&mut self, location: Location, place: Place<'tcx>) {
|
||||||
|
use IllegalMoveOriginKind::*;
|
||||||
|
|
||||||
|
let body = self.body;
|
||||||
|
let tcx = self.infcx.tcx;
|
||||||
|
let mut place_ty = PlaceTy::from_ty(body.local_decls[place.local].ty);
|
||||||
|
for (place_ref, elem) in place.iter_projections() {
|
||||||
|
match elem {
|
||||||
|
ProjectionElem::Deref => match place_ty.ty.kind() {
|
||||||
|
ty::Ref(..) | ty::RawPtr(..) => {
|
||||||
|
self.move_errors.push(MoveError::new(
|
||||||
|
place,
|
||||||
|
location,
|
||||||
|
BorrowedContent {
|
||||||
|
target_place: place_ref.project_deeper(&[elem], tcx),
|
||||||
|
},
|
||||||
|
));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ty::Adt(adt, _) => {
|
||||||
|
if !adt.is_box() {
|
||||||
|
bug!("Adt should be a box type when Place is deref");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ty::Bool
|
||||||
|
| ty::Char
|
||||||
|
| ty::Int(_)
|
||||||
|
| ty::Uint(_)
|
||||||
|
| ty::Float(_)
|
||||||
|
| ty::Foreign(_)
|
||||||
|
| ty::Str
|
||||||
|
| ty::Array(_, _)
|
||||||
|
| ty::Slice(_)
|
||||||
|
| ty::FnDef(_, _)
|
||||||
|
| ty::FnPtr(_)
|
||||||
|
| ty::Dynamic(_, _, _)
|
||||||
|
| ty::Closure(_, _)
|
||||||
|
| ty::Coroutine(_, _, _)
|
||||||
|
| ty::CoroutineWitness(..)
|
||||||
|
| ty::Never
|
||||||
|
| ty::Tuple(_)
|
||||||
|
| ty::Alias(_, _)
|
||||||
|
| ty::Param(_)
|
||||||
|
| ty::Bound(_, _)
|
||||||
|
| ty::Infer(_)
|
||||||
|
| ty::Error(_)
|
||||||
|
| ty::Placeholder(_) => {
|
||||||
|
bug!("When Place is Deref it's type shouldn't be {place_ty:#?}")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
ProjectionElem::Field(_, _) => match place_ty.ty.kind() {
|
||||||
|
ty::Adt(adt, _) => {
|
||||||
|
if adt.has_dtor(tcx) {
|
||||||
|
self.move_errors.push(MoveError::new(
|
||||||
|
place,
|
||||||
|
location,
|
||||||
|
InteriorOfTypeWithDestructor { container_ty: place_ty.ty },
|
||||||
|
));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ty::Closure(_, _) | ty::Coroutine(_, _, _) | ty::Tuple(_) => (),
|
||||||
|
ty::Bool
|
||||||
|
| ty::Char
|
||||||
|
| ty::Int(_)
|
||||||
|
| ty::Uint(_)
|
||||||
|
| ty::Float(_)
|
||||||
|
| ty::Foreign(_)
|
||||||
|
| ty::Str
|
||||||
|
| ty::Array(_, _)
|
||||||
|
| ty::Slice(_)
|
||||||
|
| ty::RawPtr(_)
|
||||||
|
| ty::Ref(_, _, _)
|
||||||
|
| ty::FnDef(_, _)
|
||||||
|
| ty::FnPtr(_)
|
||||||
|
| ty::Dynamic(_, _, _)
|
||||||
|
| ty::CoroutineWitness(..)
|
||||||
|
| ty::Never
|
||||||
|
| ty::Alias(_, _)
|
||||||
|
| ty::Param(_)
|
||||||
|
| ty::Bound(_, _)
|
||||||
|
| ty::Infer(_)
|
||||||
|
| ty::Error(_)
|
||||||
|
| ty::Placeholder(_) => bug!(
|
||||||
|
"When Place contains ProjectionElem::Field it's type shouldn't be {place_ty:#?}"
|
||||||
|
),
|
||||||
|
},
|
||||||
|
ProjectionElem::ConstantIndex { .. } | ProjectionElem::Subslice { .. } => {
|
||||||
|
match place_ty.ty.kind() {
|
||||||
|
ty::Slice(_) => {
|
||||||
|
self.move_errors.push(MoveError::new(
|
||||||
|
place,
|
||||||
|
location,
|
||||||
|
InteriorOfSliceOrArray {
|
||||||
|
ty: place_ty.ty,
|
||||||
|
is_index: matches!(elem, ProjectionElem::Index(..)),
|
||||||
|
},
|
||||||
|
));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ty::Array(_, _) => (),
|
||||||
|
_ => bug!("Unexpected type {:#?}", place_ty.ty),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ProjectionElem::Index(_) => match place_ty.ty.kind() {
|
||||||
|
ty::Array(..) => {
|
||||||
|
self.move_errors.push(MoveError::new(
|
||||||
|
place,
|
||||||
|
location,
|
||||||
|
InteriorOfSliceOrArray { ty: place_ty.ty, is_index: true },
|
||||||
|
));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ty::Slice(_) => {
|
||||||
|
self.move_errors.push(MoveError::new(
|
||||||
|
place,
|
||||||
|
location,
|
||||||
|
InteriorOfSliceOrArray {
|
||||||
|
ty: place_ty.ty,
|
||||||
|
is_index: matches!(elem, ProjectionElem::Index(..)),
|
||||||
|
},
|
||||||
|
));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_ => bug!("Unexpected type {place_ty:#?}"),
|
||||||
|
},
|
||||||
|
// `OpaqueCast`: only transmutes the type, so no moves there.
|
||||||
|
// `Downcast` : only changes information about a `Place` without moving.
|
||||||
|
// `Subtype` : only transmutes the type, so no moves.
|
||||||
|
// So it's safe to skip these.
|
||||||
|
ProjectionElem::OpaqueCast(_)
|
||||||
|
| ProjectionElem::Subtype(_)
|
||||||
|
| ProjectionElem::Downcast(_, _) => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
place_ty = place_ty.projection_ty(tcx, elem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn check_if_full_path_is_moved(
|
fn check_if_full_path_is_moved(
|
||||||
&mut self,
|
&mut self,
|
||||||
location: Location,
|
location: Location,
|
||||||
|
|
|
@ -18,7 +18,6 @@ struct MoveDataBuilder<'a, 'tcx> {
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
data: MoveData<'tcx>,
|
data: MoveData<'tcx>,
|
||||||
errors: Vec<(Place<'tcx>, MoveError<'tcx>)>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> MoveDataBuilder<'a, 'tcx> {
|
impl<'a, 'tcx> MoveDataBuilder<'a, 'tcx> {
|
||||||
|
@ -31,7 +30,6 @@ impl<'a, 'tcx> MoveDataBuilder<'a, 'tcx> {
|
||||||
body,
|
body,
|
||||||
tcx,
|
tcx,
|
||||||
param_env,
|
param_env,
|
||||||
errors: Vec::new(),
|
|
||||||
data: MoveData {
|
data: MoveData {
|
||||||
moves: IndexVec::new(),
|
moves: IndexVec::new(),
|
||||||
loc_map: LocationMap::new(body),
|
loc_map: LocationMap::new(body),
|
||||||
|
@ -287,11 +285,8 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type MoveDat<'tcx> =
|
|
||||||
Result<MoveData<'tcx>, (MoveData<'tcx>, Vec<(Place<'tcx>, MoveError<'tcx>)>)>;
|
|
||||||
|
|
||||||
impl<'a, 'tcx> MoveDataBuilder<'a, 'tcx> {
|
impl<'a, 'tcx> MoveDataBuilder<'a, 'tcx> {
|
||||||
fn finalize(self) -> MoveDat<'tcx> {
|
fn finalize(self) -> MoveData<'tcx> {
|
||||||
debug!("{}", {
|
debug!("{}", {
|
||||||
debug!("moves for {:?}:", self.body.span);
|
debug!("moves for {:?}:", self.body.span);
|
||||||
for (j, mo) in self.data.moves.iter_enumerated() {
|
for (j, mo) in self.data.moves.iter_enumerated() {
|
||||||
|
@ -304,7 +299,7 @@ impl<'a, 'tcx> MoveDataBuilder<'a, 'tcx> {
|
||||||
"done dumping moves"
|
"done dumping moves"
|
||||||
});
|
});
|
||||||
|
|
||||||
if self.errors.is_empty() { Ok(self.data) } else { Err((self.data, self.errors)) }
|
self.data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,7 +307,7 @@ pub(super) fn gather_moves<'tcx>(
|
||||||
body: &Body<'tcx>,
|
body: &Body<'tcx>,
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
) -> MoveDat<'tcx> {
|
) -> MoveData<'tcx> {
|
||||||
let mut builder = MoveDataBuilder::new(body, tcx, param_env);
|
let mut builder = MoveDataBuilder::new(body, tcx, param_env);
|
||||||
|
|
||||||
builder.gather_args();
|
builder.gather_args();
|
||||||
|
@ -551,8 +546,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
|
||||||
self.record_move(place, path);
|
self.record_move(place, path);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Err(error @ MoveError::IllegalMove { .. }) => {
|
Err(MoveError::IllegalMove { .. }) => {
|
||||||
self.builder.errors.push((base_place, error));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -573,9 +567,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
|
||||||
} else {
|
} else {
|
||||||
match self.move_path_for(place) {
|
match self.move_path_for(place) {
|
||||||
Ok(path) | Err(MoveError::UnionMove { path }) => self.record_move(place, path),
|
Ok(path) | Err(MoveError::UnionMove { path }) => self.record_move(place, path),
|
||||||
Err(error @ MoveError::IllegalMove { .. }) => {
|
Err(MoveError::IllegalMove { .. }) => {}
|
||||||
self.builder.errors.push((place, error));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use crate::move_paths::builder::MoveDat;
|
|
||||||
use crate::un_derefer::UnDerefer;
|
use crate::un_derefer::UnDerefer;
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_index::{IndexSlice, IndexVec};
|
use rustc_index::{IndexSlice, IndexVec};
|
||||||
|
@ -377,7 +376,7 @@ pub enum MoveError<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> MoveError<'tcx> {
|
impl<'tcx> MoveError<'tcx> {
|
||||||
fn cannot_move_out_of(location: Location, kind: IllegalMoveOriginKind<'tcx>) -> Self {
|
pub fn cannot_move_out_of(location: Location, kind: IllegalMoveOriginKind<'tcx>) -> Self {
|
||||||
let origin = IllegalMoveOrigin { location, kind };
|
let origin = IllegalMoveOrigin { location, kind };
|
||||||
MoveError::IllegalMove { cannot_move_out_of: origin }
|
MoveError::IllegalMove { cannot_move_out_of: origin }
|
||||||
}
|
}
|
||||||
|
@ -388,7 +387,7 @@ impl<'tcx> MoveData<'tcx> {
|
||||||
body: &Body<'tcx>,
|
body: &Body<'tcx>,
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
param_env: ParamEnv<'tcx>,
|
param_env: ParamEnv<'tcx>,
|
||||||
) -> MoveDat<'tcx> {
|
) -> MoveData<'tcx> {
|
||||||
builder::gather_moves(body, tcx, param_env)
|
builder::gather_moves(body, tcx, param_env)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ impl<'tcx> MirPass<'tcx> for SanityCheck {
|
||||||
}
|
}
|
||||||
|
|
||||||
let param_env = tcx.param_env(def_id);
|
let param_env = tcx.param_env(def_id);
|
||||||
let move_data = MoveData::gather_moves(body, tcx, param_env).unwrap();
|
let move_data = MoveData::gather_moves(body, tcx, param_env);
|
||||||
let mdpe = MoveDataParamEnv { move_data, param_env };
|
let mdpe = MoveDataParamEnv { move_data, param_env };
|
||||||
|
|
||||||
if has_rustc_mir_with(tcx, def_id, sym::rustc_peek_maybe_init).is_some() {
|
if has_rustc_mir_with(tcx, def_id, sym::rustc_peek_maybe_init).is_some() {
|
||||||
|
|
|
@ -54,16 +54,7 @@ impl<'tcx> MirPass<'tcx> for ElaborateDrops {
|
||||||
|
|
||||||
let def_id = body.source.def_id();
|
let def_id = body.source.def_id();
|
||||||
let param_env = tcx.param_env_reveal_all_normalized(def_id);
|
let param_env = tcx.param_env_reveal_all_normalized(def_id);
|
||||||
let move_data = match MoveData::gather_moves(body, tcx, param_env) {
|
let move_data = MoveData::gather_moves(body, tcx, param_env);
|
||||||
Ok(move_data) => move_data,
|
|
||||||
Err((move_data, _)) => {
|
|
||||||
tcx.sess.delay_span_bug(
|
|
||||||
body.span,
|
|
||||||
"No `move_errors` should be allowed in MIR borrowck",
|
|
||||||
);
|
|
||||||
move_data
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let elaborate_patch = {
|
let elaborate_patch = {
|
||||||
let env = MoveDataParamEnv { move_data, param_env };
|
let env = MoveDataParamEnv { move_data, param_env };
|
||||||
|
|
||||||
|
|
|
@ -24,11 +24,7 @@ pub struct RemoveUninitDrops;
|
||||||
impl<'tcx> MirPass<'tcx> for RemoveUninitDrops {
|
impl<'tcx> MirPass<'tcx> for RemoveUninitDrops {
|
||||||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||||
let param_env = tcx.param_env(body.source.def_id());
|
let param_env = tcx.param_env(body.source.def_id());
|
||||||
let Ok(move_data) = MoveData::gather_moves(body, tcx, param_env) else {
|
let move_data = MoveData::gather_moves(body, tcx, param_env);
|
||||||
// We could continue if there are move errors, but there's not much point since our
|
|
||||||
// init data isn't complete.
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
let mdpe = MoveDataParamEnv { move_data, param_env };
|
let mdpe = MoveDataParamEnv { move_data, param_env };
|
||||||
let mut maybe_inits = MaybeInitializedPlaces::new(tcx, body, &mdpe)
|
let mut maybe_inits = MaybeInitializedPlaces::new(tcx, body, &mdpe)
|
||||||
|
|
|
@ -1,25 +1,3 @@
|
||||||
error[E0508]: cannot move out of type `[T]`, a non-copy slice
|
|
||||||
--> $DIR/issue-12567.rs:2:11
|
|
||||||
|
|
|
||||||
LL | match (l1, l2) {
|
|
||||||
| ^^^^^^^^ cannot move out of here
|
|
||||||
...
|
|
||||||
LL | (&[], &[hd, ..]) | (&[hd, ..], &[])
|
|
||||||
| -- data moved here
|
|
||||||
LL | => println!("one empty"),
|
|
||||||
LL | (&[hd1, ..], &[hd2, ..])
|
|
||||||
| --- ...and here
|
|
||||||
|
|
|
||||||
= note: move occurs because these variables have types that don't implement the `Copy` trait
|
|
||||||
help: consider borrowing the pattern binding
|
|
||||||
|
|
|
||||||
LL | (&[], &[ref hd, ..]) | (&[hd, ..], &[])
|
|
||||||
| +++
|
|
||||||
help: consider borrowing the pattern binding
|
|
||||||
|
|
|
||||||
LL | (&[ref hd1, ..], &[hd2, ..])
|
|
||||||
| +++
|
|
||||||
|
|
||||||
error[E0508]: cannot move out of type `[T]`, a non-copy slice
|
error[E0508]: cannot move out of type `[T]`, a non-copy slice
|
||||||
--> $DIR/issue-12567.rs:2:11
|
--> $DIR/issue-12567.rs:2:11
|
||||||
|
|
|
|
||||||
|
@ -42,6 +20,28 @@ help: consider borrowing the pattern binding
|
||||||
LL | (&[hd1, ..], &[ref hd2, ..])
|
LL | (&[hd1, ..], &[ref hd2, ..])
|
||||||
| +++
|
| +++
|
||||||
|
|
||||||
|
error[E0508]: cannot move out of type `[T]`, a non-copy slice
|
||||||
|
--> $DIR/issue-12567.rs:2:11
|
||||||
|
|
|
||||||
|
LL | match (l1, l2) {
|
||||||
|
| ^^^^^^^^ cannot move out of here
|
||||||
|
...
|
||||||
|
LL | (&[], &[hd, ..]) | (&[hd, ..], &[])
|
||||||
|
| -- data moved here
|
||||||
|
LL | => println!("one empty"),
|
||||||
|
LL | (&[hd1, ..], &[hd2, ..])
|
||||||
|
| --- ...and here
|
||||||
|
|
|
||||||
|
= note: move occurs because these variables have types that don't implement the `Copy` trait
|
||||||
|
help: consider borrowing the pattern binding
|
||||||
|
|
|
||||||
|
LL | (&[], &[ref hd, ..]) | (&[hd, ..], &[])
|
||||||
|
| +++
|
||||||
|
help: consider borrowing the pattern binding
|
||||||
|
|
|
||||||
|
LL | (&[ref hd1, ..], &[hd2, ..])
|
||||||
|
| +++
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0508`.
|
For more information about this error, try `rustc --explain E0508`.
|
||||||
|
|
|
@ -186,7 +186,7 @@ help: consider borrowing the pattern binding
|
||||||
LL | F(s, ref mut t) => (),
|
LL | F(s, ref mut t) => (),
|
||||||
| +++
|
| +++
|
||||||
|
|
||||||
error[E0507]: cannot move out of `x` as enum variant `Err` which is behind a shared reference
|
error[E0507]: cannot move out of `x` as enum variant `Ok` which is behind a shared reference
|
||||||
--> $DIR/move-errors.rs:110:11
|
--> $DIR/move-errors.rs:110:11
|
||||||
|
|
|
|
||||||
LL | match *x {
|
LL | match *x {
|
||||||
|
|
|
@ -43,7 +43,7 @@ LL - while let Either::One(_t) = *r { }
|
||||||
LL + while let Either::One(_t) = r { }
|
LL + while let Either::One(_t) = r { }
|
||||||
|
|
|
|
||||||
|
|
||||||
error[E0507]: cannot move out of `r` as enum variant `Two` which is behind a shared reference
|
error[E0507]: cannot move out of `r` as enum variant `One` which is behind a shared reference
|
||||||
--> $DIR/simple.rs:47:11
|
--> $DIR/simple.rs:47:11
|
||||||
|
|
|
|
||||||
LL | match *r {
|
LL | match *r {
|
||||||
|
@ -124,7 +124,7 @@ LL - while let Either::One(_t) = *rm { }
|
||||||
LL + while let Either::One(_t) = rm { }
|
LL + while let Either::One(_t) = rm { }
|
||||||
|
|
|
|
||||||
|
|
||||||
error[E0507]: cannot move out of `rm` as enum variant `Two` which is behind a mutable reference
|
error[E0507]: cannot move out of `rm` as enum variant `One` which is behind a mutable reference
|
||||||
--> $DIR/simple.rs:70:11
|
--> $DIR/simple.rs:70:11
|
||||||
|
|
|
|
||||||
LL | match *rm {
|
LL | match *rm {
|
||||||
|
@ -392,7 +392,7 @@ LL - while let &Either::One(_t) = r { }
|
||||||
LL + while let Either::One(_t) = r { }
|
LL + while let Either::One(_t) = r { }
|
||||||
|
|
|
|
||||||
|
|
||||||
error[E0507]: cannot move out of `r` as enum variant `Two` which is behind a shared reference
|
error[E0507]: cannot move out of `r` as enum variant `One` which is behind a shared reference
|
||||||
--> $DIR/simple.rs:155:11
|
--> $DIR/simple.rs:155:11
|
||||||
|
|
|
|
||||||
LL | match r {
|
LL | match r {
|
||||||
|
@ -491,7 +491,7 @@ LL - while let &mut Either::One(_t) = rm { }
|
||||||
LL + while let Either::One(_t) = rm { }
|
LL + while let Either::One(_t) = rm { }
|
||||||
|
|
|
|
||||||
|
|
||||||
error[E0507]: cannot move out of `rm` as enum variant `Two` which is behind a mutable reference
|
error[E0507]: cannot move out of `rm` as enum variant `One` which is behind a mutable reference
|
||||||
--> $DIR/simple.rs:187:11
|
--> $DIR/simple.rs:187:11
|
||||||
|
|
|
|
||||||
LL | match rm {
|
LL | match rm {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue