2017-07-05 14:52:18 +02:00
|
|
|
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2017-08-21 11:31:35 +02:00
|
|
|
//! This query borrow-checks the MIR to (further) ensure it is not broken.
|
2017-07-05 14:52:18 +02:00
|
|
|
|
2017-10-21 21:15:04 +02:00
|
|
|
use rustc::hir;
|
2017-08-21 10:24:12 +02:00
|
|
|
use rustc::hir::def_id::{DefId};
|
2017-07-05 14:52:18 +02:00
|
|
|
use rustc::infer::{InferCtxt};
|
|
|
|
use rustc::ty::{self, TyCtxt, ParamEnv};
|
2017-08-21 10:24:12 +02:00
|
|
|
use rustc::ty::maps::Providers;
|
2017-12-01 14:31:47 +02:00
|
|
|
use rustc::mir::{AssertMessage, BasicBlock, BorrowKind, Location, Place, Local};
|
2017-07-05 14:52:18 +02:00
|
|
|
use rustc::mir::{Mir, Mutability, Operand, Projection, ProjectionElem, Rvalue};
|
2017-11-19 04:02:05 +05:30
|
|
|
use rustc::mir::{Field, Statement, StatementKind, Terminator, TerminatorKind};
|
2017-10-30 08:28:07 -04:00
|
|
|
use transform::nll;
|
2017-07-05 14:52:18 +02:00
|
|
|
|
2017-11-14 19:47:31 +00:00
|
|
|
use rustc_data_structures::fx::FxHashSet;
|
2017-07-05 14:52:18 +02:00
|
|
|
use rustc_data_structures::indexed_set::{self, IdxSetBuf};
|
|
|
|
use rustc_data_structures::indexed_vec::{Idx};
|
|
|
|
|
|
|
|
use syntax::ast::{self};
|
2017-11-17 17:19:57 +02:00
|
|
|
use syntax_pos::Span;
|
2017-07-05 14:52:18 +02:00
|
|
|
|
|
|
|
use dataflow::{do_dataflow};
|
|
|
|
use dataflow::{MoveDataParamEnv};
|
|
|
|
use dataflow::{BitDenotation, BlockSets, DataflowResults, DataflowResultsConsumer};
|
|
|
|
use dataflow::{MaybeInitializedLvals, MaybeUninitializedLvals};
|
2017-11-27 08:06:36 +00:00
|
|
|
use dataflow::{MovingOutStatements, EverInitializedLvals};
|
2017-07-05 14:52:18 +02:00
|
|
|
use dataflow::{Borrows, BorrowData, BorrowIndex};
|
2017-10-04 11:02:26 +02:00
|
|
|
use dataflow::move_paths::{MoveError, IllegalMoveOriginKind};
|
2017-11-08 18:32:08 +03:00
|
|
|
use dataflow::move_paths::{HasMoveData, MoveData, MovePathIndex, LookupResult, MoveOutIndex};
|
2017-07-05 14:52:18 +02:00
|
|
|
use util::borrowck_errors::{BorrowckErrors, Origin};
|
|
|
|
|
|
|
|
use self::MutateMode::{JustWrite, WriteAndRead};
|
|
|
|
|
|
|
|
|
2017-08-21 10:24:12 +02:00
|
|
|
pub fn provide(providers: &mut Providers) {
|
|
|
|
*providers = Providers {
|
|
|
|
mir_borrowck,
|
|
|
|
..*providers
|
|
|
|
};
|
|
|
|
}
|
2017-07-05 14:52:18 +02:00
|
|
|
|
2017-08-21 10:24:12 +02:00
|
|
|
fn mir_borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
|
2017-10-30 05:50:39 -04:00
|
|
|
let input_mir = tcx.mir_validated(def_id);
|
2017-11-10 19:20:35 +02:00
|
|
|
debug!("run query mir_borrowck: {}", tcx.item_path_str(def_id));
|
2017-07-05 14:52:18 +02:00
|
|
|
|
2017-10-31 11:41:54 -04:00
|
|
|
if {
|
|
|
|
!tcx.has_attr(def_id, "rustc_mir_borrowck") &&
|
2017-11-19 23:35:53 +01:00
|
|
|
!tcx.sess.opts.borrowck_mode.use_mir() &&
|
2017-10-31 11:41:54 -04:00
|
|
|
!tcx.sess.opts.debugging_opts.nll
|
|
|
|
} {
|
2017-08-21 11:31:35 +02:00
|
|
|
return;
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
|
2017-10-30 05:50:39 -04:00
|
|
|
tcx.infer_ctxt().enter(|infcx| {
|
|
|
|
let input_mir: &Mir = &input_mir.borrow();
|
2017-11-10 19:20:35 +02:00
|
|
|
do_mir_borrowck(&infcx, input_mir, def_id);
|
2017-10-30 05:50:39 -04:00
|
|
|
});
|
|
|
|
debug!("mir_borrowck done");
|
|
|
|
}
|
|
|
|
|
|
|
|
fn do_mir_borrowck<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
|
2017-10-30 08:28:07 -04:00
|
|
|
input_mir: &Mir<'gcx>,
|
2017-11-10 19:20:35 +02:00
|
|
|
def_id: DefId)
|
2017-10-30 05:50:39 -04:00
|
|
|
{
|
|
|
|
let tcx = infcx.tcx;
|
2017-07-05 14:52:18 +02:00
|
|
|
let attributes = tcx.get_attrs(def_id);
|
|
|
|
let param_env = tcx.param_env(def_id);
|
2017-11-10 19:20:35 +02:00
|
|
|
let id = tcx.hir.as_local_node_id(def_id)
|
|
|
|
.expect("do_mir_borrowck: non-local DefId");
|
2017-10-30 05:50:39 -04:00
|
|
|
|
2017-11-17 17:19:57 +02:00
|
|
|
let move_data: MoveData<'tcx> = match MoveData::gather_moves(input_mir, tcx) {
|
2017-10-30 05:50:39 -04:00
|
|
|
Ok(move_data) => move_data,
|
|
|
|
Err((move_data, move_errors)) => {
|
|
|
|
for move_error in move_errors {
|
|
|
|
let (span, kind): (Span, IllegalMoveOriginKind) = match move_error {
|
|
|
|
MoveError::UnionMove { .. } =>
|
|
|
|
unimplemented!("dont know how to report union move errors yet."),
|
|
|
|
MoveError::IllegalMove { cannot_move_out_of: o } => (o.span, o.kind),
|
|
|
|
};
|
|
|
|
let origin = Origin::Mir;
|
|
|
|
let mut err = match kind {
|
|
|
|
IllegalMoveOriginKind::Static =>
|
|
|
|
tcx.cannot_move_out_of(span, "static item", origin),
|
|
|
|
IllegalMoveOriginKind::BorrowedContent =>
|
2017-11-20 21:26:21 +05:30
|
|
|
tcx.cannot_move_out_of(span, "borrowed content", origin),
|
2017-10-30 05:50:39 -04:00
|
|
|
IllegalMoveOriginKind::InteriorOfTypeWithDestructor { container_ty: ty } =>
|
|
|
|
tcx.cannot_move_out_of_interior_of_drop(span, ty, origin),
|
2017-11-13 22:40:22 +00:00
|
|
|
IllegalMoveOriginKind::InteriorOfSliceOrArray { ty, is_index } =>
|
2017-10-30 05:50:39 -04:00
|
|
|
tcx.cannot_move_out_of_interior_noncopy(span, ty, is_index, origin),
|
|
|
|
};
|
|
|
|
err.emit();
|
2017-10-04 11:02:26 +02:00
|
|
|
}
|
2017-10-30 05:50:39 -04:00
|
|
|
move_data
|
|
|
|
}
|
|
|
|
};
|
2017-07-05 14:52:18 +02:00
|
|
|
|
2017-10-30 08:28:07 -04:00
|
|
|
// Make our own copy of the MIR. This copy will be modified (in place) to
|
|
|
|
// contain non-lexical lifetimes. It will have a lifetime tied
|
|
|
|
// to the inference context.
|
|
|
|
let mut mir: Mir<'tcx> = input_mir.clone();
|
|
|
|
let mir = &mut mir;
|
|
|
|
|
|
|
|
// If we are in non-lexical mode, compute the non-lexical lifetimes.
|
|
|
|
let opt_regioncx = if !tcx.sess.opts.debugging_opts.nll {
|
|
|
|
None
|
|
|
|
} else {
|
2017-11-06 07:26:34 -05:00
|
|
|
Some(nll::compute_regions(infcx, def_id, param_env, mir))
|
2017-10-30 08:28:07 -04:00
|
|
|
};
|
|
|
|
|
2017-10-30 05:50:39 -04:00
|
|
|
let mdpe = MoveDataParamEnv { move_data: move_data, param_env: param_env };
|
|
|
|
let dead_unwinds = IdxSetBuf::new_empty(mir.basic_blocks().len());
|
|
|
|
let flow_borrows = do_dataflow(tcx, mir, id, &attributes, &dead_unwinds,
|
2017-10-30 08:28:07 -04:00
|
|
|
Borrows::new(tcx, mir, opt_regioncx.as_ref()),
|
2017-10-30 05:50:39 -04:00
|
|
|
|bd, i| bd.location(i));
|
|
|
|
let flow_inits = do_dataflow(tcx, mir, id, &attributes, &dead_unwinds,
|
|
|
|
MaybeInitializedLvals::new(tcx, mir, &mdpe),
|
|
|
|
|bd, i| &bd.move_data().move_paths[i]);
|
|
|
|
let flow_uninits = do_dataflow(tcx, mir, id, &attributes, &dead_unwinds,
|
|
|
|
MaybeUninitializedLvals::new(tcx, mir, &mdpe),
|
|
|
|
|bd, i| &bd.move_data().move_paths[i]);
|
2017-11-08 18:32:08 +03:00
|
|
|
let flow_move_outs = do_dataflow(tcx, mir, id, &attributes, &dead_unwinds,
|
|
|
|
MovingOutStatements::new(tcx, mir, &mdpe),
|
|
|
|
|bd, i| &bd.move_data().moves[i]);
|
2017-11-27 08:06:36 +00:00
|
|
|
let flow_ever_inits = do_dataflow(tcx, mir, id, &attributes, &dead_unwinds,
|
|
|
|
EverInitializedLvals::new(tcx, mir, &mdpe),
|
|
|
|
|bd, i| &bd.move_data().inits[i]);
|
2017-10-30 05:50:39 -04:00
|
|
|
|
|
|
|
let mut mbcx = MirBorrowckCtxt {
|
|
|
|
tcx: tcx,
|
|
|
|
mir: mir,
|
|
|
|
node_id: id,
|
|
|
|
move_data: &mdpe.move_data,
|
|
|
|
param_env: param_env,
|
2017-11-21 01:50:04 +02:00
|
|
|
storage_dead_or_drop_error_reported: FxHashSet(),
|
2017-10-30 05:50:39 -04:00
|
|
|
};
|
2017-07-05 14:52:18 +02:00
|
|
|
|
2017-10-30 05:50:39 -04:00
|
|
|
let mut state = InProgress::new(flow_borrows,
|
|
|
|
flow_inits,
|
2017-11-08 18:32:08 +03:00
|
|
|
flow_uninits,
|
2017-11-27 08:06:36 +00:00
|
|
|
flow_move_outs,
|
|
|
|
flow_ever_inits);
|
2017-07-05 14:52:18 +02:00
|
|
|
|
2017-10-30 05:50:39 -04:00
|
|
|
mbcx.analyze_results(&mut state); // entry point for DataflowResultsConsumer
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
2017-11-07 04:44:41 -05:00
|
|
|
pub struct MirBorrowckCtxt<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
|
|
|
|
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
|
|
|
|
mir: &'cx Mir<'tcx>,
|
2017-07-05 14:52:18 +02:00
|
|
|
node_id: ast::NodeId,
|
2017-11-07 04:44:41 -05:00
|
|
|
move_data: &'cx MoveData<'tcx>,
|
|
|
|
param_env: ParamEnv<'gcx>,
|
2017-11-21 01:50:04 +02:00
|
|
|
/// This field keeps track of when storage dead or drop errors are reported
|
2017-11-14 19:47:31 +00:00
|
|
|
/// in order to stop duplicate error reporting and identify the conditions required
|
|
|
|
/// for a "temporary value dropped here while still borrowed" error. See #45360.
|
2017-11-21 01:50:04 +02:00
|
|
|
storage_dead_or_drop_error_reported: FxHashSet<Local>,
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// (forced to be `pub` due to its use as an associated type below.)
|
2017-10-30 05:50:39 -04:00
|
|
|
pub struct InProgress<'b, 'gcx: 'tcx, 'tcx: 'b> {
|
|
|
|
borrows: FlowInProgress<Borrows<'b, 'gcx, 'tcx>>,
|
|
|
|
inits: FlowInProgress<MaybeInitializedLvals<'b, 'gcx, 'tcx>>,
|
|
|
|
uninits: FlowInProgress<MaybeUninitializedLvals<'b, 'gcx, 'tcx>>,
|
2017-11-08 18:32:08 +03:00
|
|
|
move_outs: FlowInProgress<MovingOutStatements<'b, 'gcx, 'tcx>>,
|
2017-11-27 08:06:36 +00:00
|
|
|
ever_inits: FlowInProgress<EverInitializedLvals<'b, 'gcx, 'tcx>>,
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct FlowInProgress<BD> where BD: BitDenotation {
|
|
|
|
base_results: DataflowResults<BD>,
|
|
|
|
curr_state: IdxSetBuf<BD::Idx>,
|
|
|
|
stmt_gen: IdxSetBuf<BD::Idx>,
|
|
|
|
stmt_kill: IdxSetBuf<BD::Idx>,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that:
|
|
|
|
// 1. assignments are always made to mutable locations (FIXME: does that still really go here?)
|
|
|
|
// 2. loans made in overlapping scopes do not conflict
|
|
|
|
// 3. assignments do not affect things loaned out as immutable
|
|
|
|
// 4. moves do not affect things loaned out in any way
|
2017-11-07 04:44:41 -05:00
|
|
|
impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
|
|
|
type FlowState = InProgress<'cx, 'gcx, 'tcx>;
|
2017-07-05 14:52:18 +02:00
|
|
|
|
2017-11-07 04:44:41 -05:00
|
|
|
fn mir(&self) -> &'cx Mir<'tcx> { self.mir }
|
2017-07-05 14:52:18 +02:00
|
|
|
|
|
|
|
fn reset_to_entry_of(&mut self, bb: BasicBlock, flow_state: &mut Self::FlowState) {
|
|
|
|
flow_state.each_flow(|b| b.reset_to_entry_of(bb),
|
|
|
|
|i| i.reset_to_entry_of(bb),
|
2017-11-08 18:32:08 +03:00
|
|
|
|u| u.reset_to_entry_of(bb),
|
2017-11-27 08:06:36 +00:00
|
|
|
|m| m.reset_to_entry_of(bb),
|
|
|
|
|e| e.reset_to_entry_of(bb));
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn reconstruct_statement_effect(&mut self,
|
|
|
|
location: Location,
|
|
|
|
flow_state: &mut Self::FlowState) {
|
|
|
|
flow_state.each_flow(|b| b.reconstruct_statement_effect(location),
|
|
|
|
|i| i.reconstruct_statement_effect(location),
|
2017-11-08 18:32:08 +03:00
|
|
|
|u| u.reconstruct_statement_effect(location),
|
2017-11-27 08:06:36 +00:00
|
|
|
|m| m.reconstruct_statement_effect(location),
|
|
|
|
|e| e.reconstruct_statement_effect(location));
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn apply_local_effect(&mut self,
|
|
|
|
_location: Location,
|
|
|
|
flow_state: &mut Self::FlowState) {
|
|
|
|
flow_state.each_flow(|b| b.apply_local_effect(),
|
|
|
|
|i| i.apply_local_effect(),
|
2017-11-08 18:32:08 +03:00
|
|
|
|u| u.apply_local_effect(),
|
2017-11-27 08:06:36 +00:00
|
|
|
|m| m.apply_local_effect(),
|
|
|
|
|e| e.apply_local_effect());
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn reconstruct_terminator_effect(&mut self,
|
|
|
|
location: Location,
|
|
|
|
flow_state: &mut Self::FlowState) {
|
|
|
|
flow_state.each_flow(|b| b.reconstruct_terminator_effect(location),
|
|
|
|
|i| i.reconstruct_terminator_effect(location),
|
2017-11-08 18:32:08 +03:00
|
|
|
|u| u.reconstruct_terminator_effect(location),
|
2017-11-27 08:06:36 +00:00
|
|
|
|m| m.reconstruct_terminator_effect(location),
|
|
|
|
|e| e.reconstruct_terminator_effect(location));
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_block_entry(&mut self,
|
|
|
|
bb: BasicBlock,
|
|
|
|
flow_state: &Self::FlowState) {
|
|
|
|
let summary = flow_state.summary();
|
|
|
|
debug!("MirBorrowckCtxt::process_block({:?}): {}", bb, summary);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_statement_entry(&mut self,
|
|
|
|
location: Location,
|
2017-10-30 05:50:39 -04:00
|
|
|
stmt: &Statement<'tcx>,
|
2017-07-05 14:52:18 +02:00
|
|
|
flow_state: &Self::FlowState) {
|
|
|
|
let summary = flow_state.summary();
|
|
|
|
debug!("MirBorrowckCtxt::process_statement({:?}, {:?}): {}", location, stmt, summary);
|
|
|
|
let span = stmt.source_info.span;
|
|
|
|
match stmt.kind {
|
|
|
|
StatementKind::Assign(ref lhs, ref rhs) => {
|
2017-08-21 12:48:33 +02:00
|
|
|
// NOTE: NLL RFC calls for *shallow* write; using Deep
|
|
|
|
// for short-term compat w/ AST-borrowck. Also, switch
|
|
|
|
// to shallow requires to dataflow: "if this is an
|
|
|
|
// assignment `lv = <rvalue>`, then any loan for some
|
|
|
|
// path P of which `lv` is a prefix is killed."
|
2017-07-05 14:52:18 +02:00
|
|
|
self.mutate_lvalue(ContextKind::AssignLhs.new(location),
|
2017-08-21 12:48:33 +02:00
|
|
|
(lhs, span), Deep, JustWrite, flow_state);
|
|
|
|
|
2017-07-05 14:52:18 +02:00
|
|
|
self.consume_rvalue(ContextKind::AssignRhs.new(location),
|
|
|
|
(rhs, span), location, flow_state);
|
|
|
|
}
|
|
|
|
StatementKind::SetDiscriminant { ref lvalue, variant_index: _ } => {
|
|
|
|
self.mutate_lvalue(ContextKind::SetDiscrim.new(location),
|
2017-08-21 12:48:33 +02:00
|
|
|
(lvalue, span),
|
|
|
|
Shallow(Some(ArtificialField::Discriminant)),
|
|
|
|
JustWrite,
|
|
|
|
flow_state);
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
StatementKind::InlineAsm { ref asm, ref outputs, ref inputs } => {
|
2017-11-17 17:19:57 +02:00
|
|
|
let context = ContextKind::InlineAsm.new(location);
|
2017-07-05 14:52:18 +02:00
|
|
|
for (o, output) in asm.outputs.iter().zip(outputs) {
|
|
|
|
if o.is_indirect {
|
2017-11-17 17:19:57 +02:00
|
|
|
// FIXME(eddyb) indirect inline asm outputs should
|
|
|
|
// be encoeded through MIR lvalue derefs instead.
|
|
|
|
self.access_lvalue(context,
|
|
|
|
(output, span),
|
|
|
|
(Deep, Read(ReadKind::Copy)),
|
2017-11-16 17:44:24 +01:00
|
|
|
LocalMutationIsAllowed::No,
|
2017-11-17 17:19:57 +02:00
|
|
|
flow_state);
|
|
|
|
self.check_if_path_is_moved(context, InitializationRequiringAction::Use,
|
|
|
|
(output, span), flow_state);
|
2017-07-05 14:52:18 +02:00
|
|
|
} else {
|
2017-11-17 17:19:57 +02:00
|
|
|
self.mutate_lvalue(context,
|
2017-07-05 14:52:18 +02:00
|
|
|
(output, span),
|
2017-08-21 12:48:33 +02:00
|
|
|
Deep,
|
2017-07-05 14:52:18 +02:00
|
|
|
if o.is_rw { WriteAndRead } else { JustWrite },
|
|
|
|
flow_state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for input in inputs {
|
2017-11-17 17:19:57 +02:00
|
|
|
self.consume_operand(context, (input, span), flow_state);
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
StatementKind::EndRegion(ref _rgn) => {
|
|
|
|
// ignored when consuming results (update to
|
|
|
|
// flow_state already handled).
|
|
|
|
}
|
|
|
|
StatementKind::Nop |
|
|
|
|
StatementKind::Validate(..) |
|
2017-08-14 14:42:17 +02:00
|
|
|
StatementKind::StorageLive(..) => {
|
2017-08-21 12:48:33 +02:00
|
|
|
// `Nop`, `Validate`, and `StorageLive` are irrelevant
|
|
|
|
// to borrow check.
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
2017-08-14 14:42:17 +02:00
|
|
|
|
2017-09-04 08:01:46 +03:00
|
|
|
StatementKind::StorageDead(local) => {
|
2017-11-21 01:50:04 +02:00
|
|
|
self.access_lvalue(ContextKind::StorageDead.new(location),
|
2017-12-01 14:31:47 +02:00
|
|
|
(&Place::Local(local), span),
|
2017-11-16 17:44:24 +01:00
|
|
|
(Shallow(None), Write(WriteKind::StorageDeadOrDrop)),
|
|
|
|
LocalMutationIsAllowed::Yes,
|
|
|
|
flow_state);
|
2017-08-14 14:42:17 +02:00
|
|
|
}
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_terminator_entry(&mut self,
|
|
|
|
location: Location,
|
2017-10-30 05:50:39 -04:00
|
|
|
term: &Terminator<'tcx>,
|
2017-07-05 14:52:18 +02:00
|
|
|
flow_state: &Self::FlowState) {
|
|
|
|
let loc = location;
|
|
|
|
let summary = flow_state.summary();
|
|
|
|
debug!("MirBorrowckCtxt::process_terminator({:?}, {:?}): {}", location, term, summary);
|
|
|
|
let span = term.source_info.span;
|
|
|
|
match term.kind {
|
|
|
|
TerminatorKind::SwitchInt { ref discr, switch_ty: _, values: _, targets: _ } => {
|
|
|
|
self.consume_operand(ContextKind::SwitchInt.new(loc),
|
|
|
|
(discr, span), flow_state);
|
|
|
|
}
|
|
|
|
TerminatorKind::Drop { location: ref drop_lvalue, target: _, unwind: _ } => {
|
2017-11-17 17:19:57 +02:00
|
|
|
self.access_lvalue(ContextKind::Drop.new(loc),
|
|
|
|
(drop_lvalue, span),
|
|
|
|
(Deep, Write(WriteKind::StorageDeadOrDrop)),
|
2017-11-16 17:44:24 +01:00
|
|
|
LocalMutationIsAllowed::Yes,
|
2017-11-17 17:19:57 +02:00
|
|
|
flow_state);
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
TerminatorKind::DropAndReplace { location: ref drop_lvalue,
|
|
|
|
value: ref new_value,
|
|
|
|
target: _,
|
|
|
|
unwind: _ } => {
|
|
|
|
self.mutate_lvalue(ContextKind::DropAndReplace.new(loc),
|
2017-08-21 12:48:33 +02:00
|
|
|
(drop_lvalue, span),
|
|
|
|
Deep,
|
|
|
|
JustWrite,
|
|
|
|
flow_state);
|
2017-07-05 14:52:18 +02:00
|
|
|
self.consume_operand(ContextKind::DropAndReplace.new(loc),
|
|
|
|
(new_value, span), flow_state);
|
|
|
|
}
|
|
|
|
TerminatorKind::Call { ref func, ref args, ref destination, cleanup: _ } => {
|
|
|
|
self.consume_operand(ContextKind::CallOperator.new(loc),
|
|
|
|
(func, span), flow_state);
|
|
|
|
for arg in args {
|
|
|
|
self.consume_operand(ContextKind::CallOperand.new(loc),
|
|
|
|
(arg, span), flow_state);
|
|
|
|
}
|
|
|
|
if let Some((ref dest, _/*bb*/)) = *destination {
|
|
|
|
self.mutate_lvalue(ContextKind::CallDest.new(loc),
|
2017-08-21 12:48:33 +02:00
|
|
|
(dest, span),
|
|
|
|
Deep,
|
|
|
|
JustWrite,
|
|
|
|
flow_state);
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
TerminatorKind::Assert { ref cond, expected: _, ref msg, target: _, cleanup: _ } => {
|
|
|
|
self.consume_operand(ContextKind::Assert.new(loc),
|
|
|
|
(cond, span), flow_state);
|
|
|
|
match *msg {
|
|
|
|
AssertMessage::BoundsCheck { ref len, ref index } => {
|
|
|
|
self.consume_operand(ContextKind::Assert.new(loc),
|
|
|
|
(len, span), flow_state);
|
|
|
|
self.consume_operand(ContextKind::Assert.new(loc),
|
|
|
|
(index, span), flow_state);
|
|
|
|
}
|
|
|
|
AssertMessage::Math(_/*const_math_err*/) => {}
|
2017-08-16 13:05:48 -07:00
|
|
|
AssertMessage::GeneratorResumedAfterReturn => {}
|
|
|
|
AssertMessage::GeneratorResumedAfterPanic => {}
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-16 13:05:48 -07:00
|
|
|
TerminatorKind::Yield { ref value, resume: _, drop: _} => {
|
|
|
|
self.consume_operand(ContextKind::Yield.new(loc),
|
2017-11-17 17:19:57 +02:00
|
|
|
(value, span), flow_state);
|
2017-08-16 13:05:48 -07:00
|
|
|
}
|
|
|
|
|
2017-07-05 14:52:18 +02:00
|
|
|
TerminatorKind::Resume |
|
|
|
|
TerminatorKind::Return |
|
2017-11-19 04:26:23 -08:00
|
|
|
TerminatorKind::GeneratorDrop => {
|
|
|
|
// Returning from the function implicitly kills storage for all locals and statics.
|
|
|
|
// Often, the storage will already have been killed by an explicit
|
|
|
|
// StorageDead, but we don't always emit those (notably on unwind paths),
|
|
|
|
// so this "extra check" serves as a kind of backup.
|
|
|
|
let domain = flow_state.borrows.base_results.operator();
|
|
|
|
for borrow in domain.borrows() {
|
|
|
|
let root_lvalue = self.prefixes(
|
|
|
|
&borrow.lvalue,
|
|
|
|
PrefixSet::All
|
|
|
|
).last().unwrap();
|
|
|
|
match root_lvalue {
|
2017-12-01 14:31:47 +02:00
|
|
|
Place::Static(_) => {
|
2017-11-19 04:26:23 -08:00
|
|
|
self.access_lvalue(
|
|
|
|
ContextKind::StorageDead.new(loc),
|
|
|
|
(&root_lvalue, self.mir.source_info(borrow.location).span),
|
|
|
|
(Deep, Write(WriteKind::StorageDeadOrDrop)),
|
2017-11-16 17:44:24 +01:00
|
|
|
LocalMutationIsAllowed::Yes,
|
2017-11-19 04:26:23 -08:00
|
|
|
flow_state
|
|
|
|
);
|
|
|
|
}
|
2017-12-01 14:31:47 +02:00
|
|
|
Place::Local(_) => {
|
2017-11-19 04:26:23 -08:00
|
|
|
self.access_lvalue(
|
|
|
|
ContextKind::StorageDead.new(loc),
|
|
|
|
(&root_lvalue, self.mir.source_info(borrow.location).span),
|
|
|
|
(Shallow(None), Write(WriteKind::StorageDeadOrDrop)),
|
2017-11-16 17:44:24 +01:00
|
|
|
LocalMutationIsAllowed::Yes,
|
2017-11-19 04:26:23 -08:00
|
|
|
flow_state
|
|
|
|
);
|
|
|
|
}
|
2017-12-01 14:31:47 +02:00
|
|
|
Place::Projection(_) => ()
|
2017-11-19 04:26:23 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TerminatorKind::Goto { target: _ } |
|
2017-10-13 16:36:15 +03:00
|
|
|
TerminatorKind::Unreachable |
|
|
|
|
TerminatorKind::FalseEdges { .. } => {
|
2017-07-05 14:52:18 +02:00
|
|
|
// no data used, thus irrelevant to borrowck
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
|
|
|
enum MutateMode { JustWrite, WriteAndRead }
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
|
|
|
enum Control { Continue, Break }
|
|
|
|
|
2017-08-21 12:48:33 +02:00
|
|
|
use self::ShallowOrDeep::{Shallow, Deep};
|
|
|
|
use self::ReadOrWrite::{Read, Write};
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
|
|
|
enum ArtificialField {
|
|
|
|
Discriminant,
|
|
|
|
ArrayLength,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
|
|
|
enum ShallowOrDeep {
|
|
|
|
/// From the RFC: "A *shallow* access means that the immediate
|
|
|
|
/// fields reached at LV are accessed, but references or pointers
|
|
|
|
/// found within are not dereferenced. Right now, the only access
|
|
|
|
/// that is shallow is an assignment like `x = ...;`, which would
|
|
|
|
/// be a *shallow write* of `x`."
|
|
|
|
Shallow(Option<ArtificialField>),
|
|
|
|
|
|
|
|
/// From the RFC: "A *deep* access means that all data reachable
|
|
|
|
/// through the given lvalue may be invalidated or accesses by
|
|
|
|
/// this action."
|
|
|
|
Deep,
|
|
|
|
}
|
|
|
|
|
2017-11-16 17:44:24 +01:00
|
|
|
/// Kind of access to a value: read or write
|
|
|
|
/// (For informational purposes only)
|
2017-08-21 12:48:33 +02:00
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
|
|
|
enum ReadOrWrite {
|
|
|
|
/// From the RFC: "A *read* means that the existing data may be
|
|
|
|
/// read, but will not be changed."
|
|
|
|
Read(ReadKind),
|
|
|
|
|
|
|
|
/// From the RFC: "A *write* means that the data may be mutated to
|
|
|
|
/// new values or otherwise invalidated (for example, it could be
|
|
|
|
/// de-initialized, as in a move operation).
|
|
|
|
Write(WriteKind),
|
|
|
|
}
|
|
|
|
|
2017-11-16 17:44:24 +01:00
|
|
|
/// Kind of read access to a value
|
|
|
|
/// (For informational purposes only)
|
2017-08-21 12:48:33 +02:00
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
|
|
|
enum ReadKind {
|
|
|
|
Borrow(BorrowKind),
|
|
|
|
Copy,
|
|
|
|
}
|
|
|
|
|
2017-11-16 17:44:24 +01:00
|
|
|
/// Kind of write access to a value
|
|
|
|
/// (For informational purposes only)
|
2017-08-21 12:48:33 +02:00
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
|
|
|
enum WriteKind {
|
2017-11-17 00:09:18 +00:00
|
|
|
StorageDeadOrDrop,
|
2017-08-21 12:48:33 +02:00
|
|
|
MutableBorrow(BorrowKind),
|
|
|
|
Mutate,
|
|
|
|
Move,
|
|
|
|
}
|
|
|
|
|
2017-11-16 17:44:24 +01:00
|
|
|
/// When checking permissions for an lvalue access, this flag is used to indicate that an immutable
|
|
|
|
/// local lvalue can be mutated.
|
|
|
|
///
|
|
|
|
/// FIXME: @nikomatsakis suggested that this flag could be removed with the following modifications:
|
|
|
|
/// - Merge `check_access_permissions()` and `check_if_reassignment_to_immutable_state()`
|
|
|
|
/// - Split `is_mutable()` into `is_assignable()` (can be directly assigned) and
|
|
|
|
/// `is_declared_mutable()`
|
|
|
|
/// - Take flow state into consideration in `is_assignable()` for local variables
|
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
|
|
|
enum LocalMutationIsAllowed {
|
|
|
|
Yes,
|
|
|
|
No
|
|
|
|
}
|
|
|
|
|
MIR: Fix value moved diagnose messages
MIR: adopt borrowck test
Fix trailing whitespace
span_bug! on unexpected action
Make RegionVid use newtype_index!
Closes #45843
Check rvalue aggregates during check_stmt in tycheck, add initial, (not passing) test
Fix failing test
Remove attributes and test comments accidentally left behind, add in span_mirbugs
Normalize LvalueTy for ops and format code to satisfy tidy check
only normalize operand types when in an ADT constructor
avoid early return
handle the active field index in unions
normalize types in ADT constructor
Fixes #45940
Fix borrowck compiler errors for upvars contain "spurious" dereferences
Fixes #46003
added associated function Box::leak
Box::leak - improve documentation
Box::leak - fixed bug in documentation
Box::leak - relaxed constraints wrt. lifetimes
Box::leak - updated documentation
Box::leak - made an oops, fixed now =)
Box::leak: update unstable issue number (46179).
Add test for #44953
Add missing Debug impls to std_unicode
Also adds #![deny(missing_debug_implementations)] so they don't get
missed again.
Amend RELEASES for 1.22.1
and fix the date for 1.22.0
Rename param in `[T]::swap_with_slice` from `src` to `other`.
The idea of ‘source’ and ‘destination’ aren’t very applicable for this
operation since both slices can both be considered sources and
destinations.
Clarify stdin behavior of `Command::output`.
Fixes #44929.
Add hints for the case of confusing enum with its variants
Add failing testcases
Add module population and case of enum in place of expression
Use for_each_child_stable in find_module
Use multiline text for crate conflict diagnostics
Make float::from_bits transmute (and update the documentation to reflect this).
The current implementation/documentation was made to avoid sNaN because of
potential safety issues implied by old/bad LLVM documentation. These issues
aren't real, so we can just make the implementation transmute (as permitted
by the existing documentation of this method).
Also the documentation didn't actually match the behaviour: it said we may
change sNaNs, but in fact we canonicalized *all* NaNs.
Also an example in the documentation was wrong: it said we *always* change
sNaNs, when the documentation was explicitly written to indicate it was
implementation-defined.
This makes to_bits and from_bits perfectly roundtrip cross-platform, except
for one caveat: although the 2008 edition of IEEE-754 specifies how to
interpet the signaling bit, earlier editions didn't. This lead to some platforms
picking the opposite interpretation, so all signaling NaNs on x86/ARM are quiet
on MIPS, and vice-versa.
NaN-boxing is a fairly important optimization, while we don't even guarantee
that float operations properly preserve signalingness. As such, this seems like
the more natural strategy to take (as opposed to trying to mangle the signaling
bit on a per-platform basis).
This implementation is also, of course, faster.
Simplify an Iterator::fold to Iterator::any
This method of once-diagnostics doesn't allow nesting
UI tests extract the regular output from the 'rendered' field in json
Merge cfail and ui tests into ui tests
Add a MIR pass to lower 128-bit operators to lang item calls
Runs only with `-Z lower_128bit_ops` since it's not hooked into targets yet.
Include tuple projections in MIR tests
Add type checking for the lang item
As part of doing so, add more lang items instead of passing u128 to the i128 ones where it doesn't matter in twos-complement.
Handle shifts properly
* The overflow-checking shift items need to take a full 128-bit type, since they need to be able to detect idiocy like `1i128 << (1u128 << 127)`
* The unchecked ones just take u32, like the `*_sh?` methods in core
* Because shift-by-anything is allowed, cast into a new local for every shift
incr.comp.: Make sure we don't lose unused green results from the query cache.
rustbuild: Update LLVM and enable ThinLTO
This commit updates LLVM to fix #45511 (https://reviews.llvm.org/D39981) and
also reenables ThinLTO for libtest now that we shouldn't hit #45768. This also
opportunistically enables ThinLTO for libstd which was previously blocked
(#45661) on test failures related to debuginfo with a presumed cause of #45511.
Closes #45511
std: Flag Windows TLS dtor symbol as #[used]
Turns out ThinLTO was internalizing this symbol and eliminating it. Worse yet if
you compiled with LTO turns out no TLS destructors would run on Windows! The
`#[used]` annotation should be a more bulletproof implementation (in the face of
LTO) of preserving this symbol all the way through in LLVM and ensuring it makes
it all the way to the linker which will take care of it.
Add enum InitializationRequiringAction
Fix tidy tests
2017-11-23 17:06:48 +05:30
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
enum InitializationRequiringAction {
|
|
|
|
Update,
|
|
|
|
Borrow,
|
|
|
|
Use,
|
|
|
|
Assignment,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl InitializationRequiringAction {
|
|
|
|
fn as_noun(self) -> &'static str {
|
|
|
|
match self {
|
|
|
|
InitializationRequiringAction::Update => "update",
|
|
|
|
InitializationRequiringAction::Borrow => "borrow",
|
|
|
|
InitializationRequiringAction::Use => "use",
|
|
|
|
InitializationRequiringAction::Assignment => "assign"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn as_verb_in_past_tense(self) -> &'static str {
|
|
|
|
match self {
|
|
|
|
InitializationRequiringAction::Update => "updated",
|
|
|
|
InitializationRequiringAction::Borrow => "borrowed",
|
|
|
|
InitializationRequiringAction::Use => "used",
|
|
|
|
InitializationRequiringAction::Assignment => "assigned"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-07 04:44:41 -05:00
|
|
|
impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
2017-11-17 00:09:18 +00:00
|
|
|
/// Checks an access to the given lvalue to see if it is allowed. Examines the set of borrows
|
|
|
|
/// that are in scope, as well as which paths have been initialized, to ensure that (a) the
|
|
|
|
/// lvalue is initialized and (b) it is not borrowed in some way that would prevent this
|
|
|
|
/// access.
|
|
|
|
///
|
|
|
|
/// Returns true if an error is reported, false otherwise.
|
2017-08-21 12:48:33 +02:00
|
|
|
fn access_lvalue(&mut self,
|
|
|
|
context: Context,
|
2017-12-01 14:31:47 +02:00
|
|
|
lvalue_span: (&Place<'tcx>, Span),
|
2017-08-21 12:48:33 +02:00
|
|
|
kind: (ShallowOrDeep, ReadOrWrite),
|
2017-11-16 17:44:24 +01:00
|
|
|
is_local_mutation_allowed: LocalMutationIsAllowed,
|
2017-11-21 01:50:04 +02:00
|
|
|
flow_state: &InProgress<'cx, 'gcx, 'tcx>) {
|
2017-08-21 12:48:33 +02:00
|
|
|
let (sd, rw) = kind;
|
2017-10-21 21:15:04 +02:00
|
|
|
|
2017-11-21 01:50:04 +02:00
|
|
|
let storage_dead_or_drop_local = match (lvalue_span.0, rw) {
|
2017-12-01 14:31:47 +02:00
|
|
|
(&Place::Local(local), Write(WriteKind::StorageDeadOrDrop)) => Some(local),
|
2017-11-21 01:50:04 +02:00
|
|
|
_ => None
|
|
|
|
};
|
|
|
|
|
|
|
|
// Check if error has already been reported to stop duplicate reporting.
|
|
|
|
if let Some(local) = storage_dead_or_drop_local {
|
|
|
|
if self.storage_dead_or_drop_error_reported.contains(&local) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-21 21:15:04 +02:00
|
|
|
// Check permissions
|
2017-11-16 17:44:24 +01:00
|
|
|
let mut error_reported = self.check_access_permissions(lvalue_span,
|
|
|
|
rw,
|
|
|
|
is_local_mutation_allowed);
|
2017-10-21 21:15:04 +02:00
|
|
|
|
2017-08-21 12:48:33 +02:00
|
|
|
self.each_borrow_involving_path(
|
2017-10-03 14:00:38 +02:00
|
|
|
context, (sd, lvalue_span.0), flow_state, |this, _index, borrow, common_prefix| {
|
2017-08-21 12:48:33 +02:00
|
|
|
match (rw, borrow.kind) {
|
|
|
|
(Read(_), BorrowKind::Shared) => {
|
|
|
|
Control::Continue
|
|
|
|
}
|
|
|
|
(Read(kind), BorrowKind::Unique) |
|
|
|
|
(Read(kind), BorrowKind::Mut) => {
|
|
|
|
match kind {
|
2017-11-17 00:09:18 +00:00
|
|
|
ReadKind::Copy => {
|
|
|
|
error_reported = true;
|
2017-08-21 12:48:33 +02:00
|
|
|
this.report_use_while_mutably_borrowed(
|
2017-11-17 00:09:18 +00:00
|
|
|
context, lvalue_span, borrow)
|
|
|
|
},
|
2017-09-27 10:01:42 +03:00
|
|
|
ReadKind::Borrow(bk) => {
|
|
|
|
let end_issued_loan_span =
|
2017-10-25 14:17:17 -04:00
|
|
|
flow_state.borrows.base_results.operator().opt_region_end_span(
|
|
|
|
&borrow.region);
|
2017-11-17 00:09:18 +00:00
|
|
|
error_reported = true;
|
2017-08-21 12:48:33 +02:00
|
|
|
this.report_conflicting_borrow(
|
2017-09-27 10:01:42 +03:00
|
|
|
context, common_prefix, lvalue_span, bk,
|
|
|
|
&borrow, end_issued_loan_span)
|
|
|
|
}
|
2017-08-21 12:48:33 +02:00
|
|
|
}
|
|
|
|
Control::Break
|
|
|
|
}
|
|
|
|
(Write(kind), _) => {
|
|
|
|
match kind {
|
2017-09-27 10:01:42 +03:00
|
|
|
WriteKind::MutableBorrow(bk) => {
|
|
|
|
let end_issued_loan_span =
|
2017-10-25 14:17:17 -04:00
|
|
|
flow_state.borrows.base_results.operator().opt_region_end_span(
|
|
|
|
&borrow.region);
|
2017-11-17 00:09:18 +00:00
|
|
|
error_reported = true;
|
2017-08-21 12:48:33 +02:00
|
|
|
this.report_conflicting_borrow(
|
2017-09-27 10:01:42 +03:00
|
|
|
context, common_prefix, lvalue_span, bk,
|
|
|
|
&borrow, end_issued_loan_span)
|
|
|
|
}
|
2017-11-17 00:09:18 +00:00
|
|
|
WriteKind::StorageDeadOrDrop => {
|
|
|
|
let end_span =
|
|
|
|
flow_state.borrows.base_results.operator().opt_region_end_span(
|
|
|
|
&borrow.region);
|
|
|
|
error_reported = true;
|
|
|
|
this.report_borrowed_value_does_not_live_long_enough(
|
|
|
|
context, lvalue_span, end_span)
|
|
|
|
},
|
|
|
|
WriteKind::Mutate => {
|
|
|
|
error_reported = true;
|
2017-08-21 12:48:33 +02:00
|
|
|
this.report_illegal_mutation_of_borrowed(
|
2017-11-17 00:09:18 +00:00
|
|
|
context, lvalue_span, borrow)
|
|
|
|
},
|
|
|
|
WriteKind::Move => {
|
|
|
|
error_reported = true;
|
2017-08-21 12:48:33 +02:00
|
|
|
this.report_move_out_while_borrowed(
|
2017-11-17 00:09:18 +00:00
|
|
|
context, lvalue_span, &borrow)
|
|
|
|
},
|
2017-08-21 12:48:33 +02:00
|
|
|
}
|
|
|
|
Control::Break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2017-11-21 01:50:04 +02:00
|
|
|
|
|
|
|
if error_reported {
|
|
|
|
if let Some(local) = storage_dead_or_drop_local {
|
|
|
|
self.storage_dead_or_drop_error_reported.insert(local);
|
|
|
|
}
|
|
|
|
}
|
2017-08-21 12:48:33 +02:00
|
|
|
}
|
|
|
|
|
2017-07-05 14:52:18 +02:00
|
|
|
fn mutate_lvalue(&mut self,
|
|
|
|
context: Context,
|
2017-12-01 14:31:47 +02:00
|
|
|
lvalue_span: (&Place<'tcx>, Span),
|
2017-08-21 12:48:33 +02:00
|
|
|
kind: ShallowOrDeep,
|
2017-07-05 14:52:18 +02:00
|
|
|
mode: MutateMode,
|
2017-11-07 04:44:41 -05:00
|
|
|
flow_state: &InProgress<'cx, 'gcx, 'tcx>) {
|
2017-07-05 14:52:18 +02:00
|
|
|
// Write of P[i] or *P, or WriteAndRead of any P, requires P init'd.
|
|
|
|
match mode {
|
|
|
|
MutateMode::WriteAndRead => {
|
MIR: Fix value moved diagnose messages
MIR: adopt borrowck test
Fix trailing whitespace
span_bug! on unexpected action
Make RegionVid use newtype_index!
Closes #45843
Check rvalue aggregates during check_stmt in tycheck, add initial, (not passing) test
Fix failing test
Remove attributes and test comments accidentally left behind, add in span_mirbugs
Normalize LvalueTy for ops and format code to satisfy tidy check
only normalize operand types when in an ADT constructor
avoid early return
handle the active field index in unions
normalize types in ADT constructor
Fixes #45940
Fix borrowck compiler errors for upvars contain "spurious" dereferences
Fixes #46003
added associated function Box::leak
Box::leak - improve documentation
Box::leak - fixed bug in documentation
Box::leak - relaxed constraints wrt. lifetimes
Box::leak - updated documentation
Box::leak - made an oops, fixed now =)
Box::leak: update unstable issue number (46179).
Add test for #44953
Add missing Debug impls to std_unicode
Also adds #![deny(missing_debug_implementations)] so they don't get
missed again.
Amend RELEASES for 1.22.1
and fix the date for 1.22.0
Rename param in `[T]::swap_with_slice` from `src` to `other`.
The idea of ‘source’ and ‘destination’ aren’t very applicable for this
operation since both slices can both be considered sources and
destinations.
Clarify stdin behavior of `Command::output`.
Fixes #44929.
Add hints for the case of confusing enum with its variants
Add failing testcases
Add module population and case of enum in place of expression
Use for_each_child_stable in find_module
Use multiline text for crate conflict diagnostics
Make float::from_bits transmute (and update the documentation to reflect this).
The current implementation/documentation was made to avoid sNaN because of
potential safety issues implied by old/bad LLVM documentation. These issues
aren't real, so we can just make the implementation transmute (as permitted
by the existing documentation of this method).
Also the documentation didn't actually match the behaviour: it said we may
change sNaNs, but in fact we canonicalized *all* NaNs.
Also an example in the documentation was wrong: it said we *always* change
sNaNs, when the documentation was explicitly written to indicate it was
implementation-defined.
This makes to_bits and from_bits perfectly roundtrip cross-platform, except
for one caveat: although the 2008 edition of IEEE-754 specifies how to
interpet the signaling bit, earlier editions didn't. This lead to some platforms
picking the opposite interpretation, so all signaling NaNs on x86/ARM are quiet
on MIPS, and vice-versa.
NaN-boxing is a fairly important optimization, while we don't even guarantee
that float operations properly preserve signalingness. As such, this seems like
the more natural strategy to take (as opposed to trying to mangle the signaling
bit on a per-platform basis).
This implementation is also, of course, faster.
Simplify an Iterator::fold to Iterator::any
This method of once-diagnostics doesn't allow nesting
UI tests extract the regular output from the 'rendered' field in json
Merge cfail and ui tests into ui tests
Add a MIR pass to lower 128-bit operators to lang item calls
Runs only with `-Z lower_128bit_ops` since it's not hooked into targets yet.
Include tuple projections in MIR tests
Add type checking for the lang item
As part of doing so, add more lang items instead of passing u128 to the i128 ones where it doesn't matter in twos-complement.
Handle shifts properly
* The overflow-checking shift items need to take a full 128-bit type, since they need to be able to detect idiocy like `1i128 << (1u128 << 127)`
* The unchecked ones just take u32, like the `*_sh?` methods in core
* Because shift-by-anything is allowed, cast into a new local for every shift
incr.comp.: Make sure we don't lose unused green results from the query cache.
rustbuild: Update LLVM and enable ThinLTO
This commit updates LLVM to fix #45511 (https://reviews.llvm.org/D39981) and
also reenables ThinLTO for libtest now that we shouldn't hit #45768. This also
opportunistically enables ThinLTO for libstd which was previously blocked
(#45661) on test failures related to debuginfo with a presumed cause of #45511.
Closes #45511
std: Flag Windows TLS dtor symbol as #[used]
Turns out ThinLTO was internalizing this symbol and eliminating it. Worse yet if
you compiled with LTO turns out no TLS destructors would run on Windows! The
`#[used]` annotation should be a more bulletproof implementation (in the face of
LTO) of preserving this symbol all the way through in LLVM and ensuring it makes
it all the way to the linker which will take care of it.
Add enum InitializationRequiringAction
Fix tidy tests
2017-11-23 17:06:48 +05:30
|
|
|
self.check_if_path_is_moved(context, InitializationRequiringAction::Update,
|
|
|
|
lvalue_span, flow_state);
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
MutateMode::JustWrite => {
|
|
|
|
self.check_if_assigned_path_is_moved(context, lvalue_span, flow_state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-16 17:44:24 +01:00
|
|
|
self.access_lvalue(context,
|
|
|
|
lvalue_span,
|
|
|
|
(kind, Write(WriteKind::Mutate)),
|
|
|
|
LocalMutationIsAllowed::Yes,
|
|
|
|
flow_state);
|
2017-07-05 14:52:18 +02:00
|
|
|
|
|
|
|
// check for reassignments to immutable local variables
|
|
|
|
self.check_if_reassignment_to_immutable_state(context, lvalue_span, flow_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn consume_rvalue(&mut self,
|
|
|
|
context: Context,
|
2017-10-30 05:50:39 -04:00
|
|
|
(rvalue, span): (&Rvalue<'tcx>, Span),
|
2017-08-21 12:48:33 +02:00
|
|
|
_location: Location,
|
2017-11-07 04:44:41 -05:00
|
|
|
flow_state: &InProgress<'cx, 'gcx, 'tcx>) {
|
2017-07-05 14:52:18 +02:00
|
|
|
match *rvalue {
|
|
|
|
Rvalue::Ref(_/*rgn*/, bk, ref lvalue) => {
|
2017-08-21 12:48:33 +02:00
|
|
|
let access_kind = match bk {
|
|
|
|
BorrowKind::Shared => (Deep, Read(ReadKind::Borrow(bk))),
|
|
|
|
BorrowKind::Unique |
|
|
|
|
BorrowKind::Mut => (Deep, Write(WriteKind::MutableBorrow(bk))),
|
|
|
|
};
|
2017-11-16 17:44:24 +01:00
|
|
|
self.access_lvalue(context,
|
|
|
|
(lvalue, span),
|
|
|
|
access_kind,
|
|
|
|
LocalMutationIsAllowed::No,
|
|
|
|
flow_state);
|
MIR: Fix value moved diagnose messages
MIR: adopt borrowck test
Fix trailing whitespace
span_bug! on unexpected action
Make RegionVid use newtype_index!
Closes #45843
Check rvalue aggregates during check_stmt in tycheck, add initial, (not passing) test
Fix failing test
Remove attributes and test comments accidentally left behind, add in span_mirbugs
Normalize LvalueTy for ops and format code to satisfy tidy check
only normalize operand types when in an ADT constructor
avoid early return
handle the active field index in unions
normalize types in ADT constructor
Fixes #45940
Fix borrowck compiler errors for upvars contain "spurious" dereferences
Fixes #46003
added associated function Box::leak
Box::leak - improve documentation
Box::leak - fixed bug in documentation
Box::leak - relaxed constraints wrt. lifetimes
Box::leak - updated documentation
Box::leak - made an oops, fixed now =)
Box::leak: update unstable issue number (46179).
Add test for #44953
Add missing Debug impls to std_unicode
Also adds #![deny(missing_debug_implementations)] so they don't get
missed again.
Amend RELEASES for 1.22.1
and fix the date for 1.22.0
Rename param in `[T]::swap_with_slice` from `src` to `other`.
The idea of ‘source’ and ‘destination’ aren’t very applicable for this
operation since both slices can both be considered sources and
destinations.
Clarify stdin behavior of `Command::output`.
Fixes #44929.
Add hints for the case of confusing enum with its variants
Add failing testcases
Add module population and case of enum in place of expression
Use for_each_child_stable in find_module
Use multiline text for crate conflict diagnostics
Make float::from_bits transmute (and update the documentation to reflect this).
The current implementation/documentation was made to avoid sNaN because of
potential safety issues implied by old/bad LLVM documentation. These issues
aren't real, so we can just make the implementation transmute (as permitted
by the existing documentation of this method).
Also the documentation didn't actually match the behaviour: it said we may
change sNaNs, but in fact we canonicalized *all* NaNs.
Also an example in the documentation was wrong: it said we *always* change
sNaNs, when the documentation was explicitly written to indicate it was
implementation-defined.
This makes to_bits and from_bits perfectly roundtrip cross-platform, except
for one caveat: although the 2008 edition of IEEE-754 specifies how to
interpet the signaling bit, earlier editions didn't. This lead to some platforms
picking the opposite interpretation, so all signaling NaNs on x86/ARM are quiet
on MIPS, and vice-versa.
NaN-boxing is a fairly important optimization, while we don't even guarantee
that float operations properly preserve signalingness. As such, this seems like
the more natural strategy to take (as opposed to trying to mangle the signaling
bit on a per-platform basis).
This implementation is also, of course, faster.
Simplify an Iterator::fold to Iterator::any
This method of once-diagnostics doesn't allow nesting
UI tests extract the regular output from the 'rendered' field in json
Merge cfail and ui tests into ui tests
Add a MIR pass to lower 128-bit operators to lang item calls
Runs only with `-Z lower_128bit_ops` since it's not hooked into targets yet.
Include tuple projections in MIR tests
Add type checking for the lang item
As part of doing so, add more lang items instead of passing u128 to the i128 ones where it doesn't matter in twos-complement.
Handle shifts properly
* The overflow-checking shift items need to take a full 128-bit type, since they need to be able to detect idiocy like `1i128 << (1u128 << 127)`
* The unchecked ones just take u32, like the `*_sh?` methods in core
* Because shift-by-anything is allowed, cast into a new local for every shift
incr.comp.: Make sure we don't lose unused green results from the query cache.
rustbuild: Update LLVM and enable ThinLTO
This commit updates LLVM to fix #45511 (https://reviews.llvm.org/D39981) and
also reenables ThinLTO for libtest now that we shouldn't hit #45768. This also
opportunistically enables ThinLTO for libstd which was previously blocked
(#45661) on test failures related to debuginfo with a presumed cause of #45511.
Closes #45511
std: Flag Windows TLS dtor symbol as #[used]
Turns out ThinLTO was internalizing this symbol and eliminating it. Worse yet if
you compiled with LTO turns out no TLS destructors would run on Windows! The
`#[used]` annotation should be a more bulletproof implementation (in the face of
LTO) of preserving this symbol all the way through in LLVM and ensuring it makes
it all the way to the linker which will take care of it.
Add enum InitializationRequiringAction
Fix tidy tests
2017-11-23 17:06:48 +05:30
|
|
|
self.check_if_path_is_moved(context, InitializationRequiringAction::Borrow,
|
|
|
|
(lvalue, span), flow_state);
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Rvalue::Use(ref operand) |
|
|
|
|
Rvalue::Repeat(ref operand, _) |
|
|
|
|
Rvalue::UnaryOp(_/*un_op*/, ref operand) |
|
|
|
|
Rvalue::Cast(_/*cast_kind*/, ref operand, _/*ty*/) => {
|
2017-11-17 17:19:57 +02:00
|
|
|
self.consume_operand(context, (operand, span), flow_state)
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Rvalue::Len(ref lvalue) |
|
|
|
|
Rvalue::Discriminant(ref lvalue) => {
|
2017-08-21 12:48:33 +02:00
|
|
|
let af = match *rvalue {
|
|
|
|
Rvalue::Len(..) => ArtificialField::ArrayLength,
|
|
|
|
Rvalue::Discriminant(..) => ArtificialField::Discriminant,
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
2017-11-16 17:44:24 +01:00
|
|
|
self.access_lvalue(context,
|
|
|
|
(lvalue, span),
|
|
|
|
(Shallow(Some(af)), Read(ReadKind::Copy)),
|
|
|
|
LocalMutationIsAllowed::No,
|
|
|
|
flow_state);
|
MIR: Fix value moved diagnose messages
MIR: adopt borrowck test
Fix trailing whitespace
span_bug! on unexpected action
Make RegionVid use newtype_index!
Closes #45843
Check rvalue aggregates during check_stmt in tycheck, add initial, (not passing) test
Fix failing test
Remove attributes and test comments accidentally left behind, add in span_mirbugs
Normalize LvalueTy for ops and format code to satisfy tidy check
only normalize operand types when in an ADT constructor
avoid early return
handle the active field index in unions
normalize types in ADT constructor
Fixes #45940
Fix borrowck compiler errors for upvars contain "spurious" dereferences
Fixes #46003
added associated function Box::leak
Box::leak - improve documentation
Box::leak - fixed bug in documentation
Box::leak - relaxed constraints wrt. lifetimes
Box::leak - updated documentation
Box::leak - made an oops, fixed now =)
Box::leak: update unstable issue number (46179).
Add test for #44953
Add missing Debug impls to std_unicode
Also adds #![deny(missing_debug_implementations)] so they don't get
missed again.
Amend RELEASES for 1.22.1
and fix the date for 1.22.0
Rename param in `[T]::swap_with_slice` from `src` to `other`.
The idea of ‘source’ and ‘destination’ aren’t very applicable for this
operation since both slices can both be considered sources and
destinations.
Clarify stdin behavior of `Command::output`.
Fixes #44929.
Add hints for the case of confusing enum with its variants
Add failing testcases
Add module population and case of enum in place of expression
Use for_each_child_stable in find_module
Use multiline text for crate conflict diagnostics
Make float::from_bits transmute (and update the documentation to reflect this).
The current implementation/documentation was made to avoid sNaN because of
potential safety issues implied by old/bad LLVM documentation. These issues
aren't real, so we can just make the implementation transmute (as permitted
by the existing documentation of this method).
Also the documentation didn't actually match the behaviour: it said we may
change sNaNs, but in fact we canonicalized *all* NaNs.
Also an example in the documentation was wrong: it said we *always* change
sNaNs, when the documentation was explicitly written to indicate it was
implementation-defined.
This makes to_bits and from_bits perfectly roundtrip cross-platform, except
for one caveat: although the 2008 edition of IEEE-754 specifies how to
interpet the signaling bit, earlier editions didn't. This lead to some platforms
picking the opposite interpretation, so all signaling NaNs on x86/ARM are quiet
on MIPS, and vice-versa.
NaN-boxing is a fairly important optimization, while we don't even guarantee
that float operations properly preserve signalingness. As such, this seems like
the more natural strategy to take (as opposed to trying to mangle the signaling
bit on a per-platform basis).
This implementation is also, of course, faster.
Simplify an Iterator::fold to Iterator::any
This method of once-diagnostics doesn't allow nesting
UI tests extract the regular output from the 'rendered' field in json
Merge cfail and ui tests into ui tests
Add a MIR pass to lower 128-bit operators to lang item calls
Runs only with `-Z lower_128bit_ops` since it's not hooked into targets yet.
Include tuple projections in MIR tests
Add type checking for the lang item
As part of doing so, add more lang items instead of passing u128 to the i128 ones where it doesn't matter in twos-complement.
Handle shifts properly
* The overflow-checking shift items need to take a full 128-bit type, since they need to be able to detect idiocy like `1i128 << (1u128 << 127)`
* The unchecked ones just take u32, like the `*_sh?` methods in core
* Because shift-by-anything is allowed, cast into a new local for every shift
incr.comp.: Make sure we don't lose unused green results from the query cache.
rustbuild: Update LLVM and enable ThinLTO
This commit updates LLVM to fix #45511 (https://reviews.llvm.org/D39981) and
also reenables ThinLTO for libtest now that we shouldn't hit #45768. This also
opportunistically enables ThinLTO for libstd which was previously blocked
(#45661) on test failures related to debuginfo with a presumed cause of #45511.
Closes #45511
std: Flag Windows TLS dtor symbol as #[used]
Turns out ThinLTO was internalizing this symbol and eliminating it. Worse yet if
you compiled with LTO turns out no TLS destructors would run on Windows! The
`#[used]` annotation should be a more bulletproof implementation (in the face of
LTO) of preserving this symbol all the way through in LLVM and ensuring it makes
it all the way to the linker which will take care of it.
Add enum InitializationRequiringAction
Fix tidy tests
2017-11-23 17:06:48 +05:30
|
|
|
self.check_if_path_is_moved(context, InitializationRequiringAction::Use,
|
|
|
|
(lvalue, span), flow_state);
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Rvalue::BinaryOp(_bin_op, ref operand1, ref operand2) |
|
|
|
|
Rvalue::CheckedBinaryOp(_bin_op, ref operand1, ref operand2) => {
|
2017-11-17 17:19:57 +02:00
|
|
|
self.consume_operand(context, (operand1, span), flow_state);
|
|
|
|
self.consume_operand(context, (operand2, span), flow_state);
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Rvalue::NullaryOp(_op, _ty) => {
|
|
|
|
// nullary ops take no dynamic input; no borrowck effect.
|
|
|
|
//
|
|
|
|
// FIXME: is above actually true? Do we want to track
|
|
|
|
// the fact that uninitialized data can be created via
|
|
|
|
// `NullOp::Box`?
|
|
|
|
}
|
|
|
|
|
|
|
|
Rvalue::Aggregate(ref _aggregate_kind, ref operands) => {
|
|
|
|
for operand in operands {
|
2017-11-17 17:19:57 +02:00
|
|
|
self.consume_operand(context, (operand, span), flow_state);
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn consume_operand(&mut self,
|
|
|
|
context: Context,
|
2017-10-30 05:50:39 -04:00
|
|
|
(operand, span): (&Operand<'tcx>, Span),
|
2017-11-07 04:44:41 -05:00
|
|
|
flow_state: &InProgress<'cx, 'gcx, 'tcx>) {
|
2017-07-05 14:52:18 +02:00
|
|
|
match *operand {
|
2017-11-17 17:19:57 +02:00
|
|
|
Operand::Copy(ref lvalue) => {
|
|
|
|
// copy of lvalue: check if this is "copy of frozen path"
|
|
|
|
// (FIXME: see check_loans.rs)
|
|
|
|
self.access_lvalue(context,
|
|
|
|
(lvalue, span),
|
|
|
|
(Deep, Read(ReadKind::Copy)),
|
2017-11-16 17:44:24 +01:00
|
|
|
LocalMutationIsAllowed::No,
|
2017-11-17 17:19:57 +02:00
|
|
|
flow_state);
|
2017-07-05 14:52:18 +02:00
|
|
|
|
2017-11-17 17:19:57 +02:00
|
|
|
// Finally, check if path was already moved.
|
|
|
|
self.check_if_path_is_moved(context, InitializationRequiringAction::Use,
|
|
|
|
(lvalue, span), flow_state);
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
2017-11-17 17:19:57 +02:00
|
|
|
Operand::Move(ref lvalue) => {
|
|
|
|
// move of lvalue: check if this is move of already borrowed path
|
|
|
|
self.access_lvalue(context,
|
|
|
|
(lvalue, span),
|
|
|
|
(Deep, Write(WriteKind::Move)),
|
2017-11-16 17:44:24 +01:00
|
|
|
LocalMutationIsAllowed::Yes,
|
2017-11-17 17:19:57 +02:00
|
|
|
flow_state);
|
|
|
|
|
|
|
|
// Finally, check if path was already moved.
|
MIR: Fix value moved diagnose messages
MIR: adopt borrowck test
Fix trailing whitespace
span_bug! on unexpected action
Make RegionVid use newtype_index!
Closes #45843
Check rvalue aggregates during check_stmt in tycheck, add initial, (not passing) test
Fix failing test
Remove attributes and test comments accidentally left behind, add in span_mirbugs
Normalize LvalueTy for ops and format code to satisfy tidy check
only normalize operand types when in an ADT constructor
avoid early return
handle the active field index in unions
normalize types in ADT constructor
Fixes #45940
Fix borrowck compiler errors for upvars contain "spurious" dereferences
Fixes #46003
added associated function Box::leak
Box::leak - improve documentation
Box::leak - fixed bug in documentation
Box::leak - relaxed constraints wrt. lifetimes
Box::leak - updated documentation
Box::leak - made an oops, fixed now =)
Box::leak: update unstable issue number (46179).
Add test for #44953
Add missing Debug impls to std_unicode
Also adds #![deny(missing_debug_implementations)] so they don't get
missed again.
Amend RELEASES for 1.22.1
and fix the date for 1.22.0
Rename param in `[T]::swap_with_slice` from `src` to `other`.
The idea of ‘source’ and ‘destination’ aren’t very applicable for this
operation since both slices can both be considered sources and
destinations.
Clarify stdin behavior of `Command::output`.
Fixes #44929.
Add hints for the case of confusing enum with its variants
Add failing testcases
Add module population and case of enum in place of expression
Use for_each_child_stable in find_module
Use multiline text for crate conflict diagnostics
Make float::from_bits transmute (and update the documentation to reflect this).
The current implementation/documentation was made to avoid sNaN because of
potential safety issues implied by old/bad LLVM documentation. These issues
aren't real, so we can just make the implementation transmute (as permitted
by the existing documentation of this method).
Also the documentation didn't actually match the behaviour: it said we may
change sNaNs, but in fact we canonicalized *all* NaNs.
Also an example in the documentation was wrong: it said we *always* change
sNaNs, when the documentation was explicitly written to indicate it was
implementation-defined.
This makes to_bits and from_bits perfectly roundtrip cross-platform, except
for one caveat: although the 2008 edition of IEEE-754 specifies how to
interpet the signaling bit, earlier editions didn't. This lead to some platforms
picking the opposite interpretation, so all signaling NaNs on x86/ARM are quiet
on MIPS, and vice-versa.
NaN-boxing is a fairly important optimization, while we don't even guarantee
that float operations properly preserve signalingness. As such, this seems like
the more natural strategy to take (as opposed to trying to mangle the signaling
bit on a per-platform basis).
This implementation is also, of course, faster.
Simplify an Iterator::fold to Iterator::any
This method of once-diagnostics doesn't allow nesting
UI tests extract the regular output from the 'rendered' field in json
Merge cfail and ui tests into ui tests
Add a MIR pass to lower 128-bit operators to lang item calls
Runs only with `-Z lower_128bit_ops` since it's not hooked into targets yet.
Include tuple projections in MIR tests
Add type checking for the lang item
As part of doing so, add more lang items instead of passing u128 to the i128 ones where it doesn't matter in twos-complement.
Handle shifts properly
* The overflow-checking shift items need to take a full 128-bit type, since they need to be able to detect idiocy like `1i128 << (1u128 << 127)`
* The unchecked ones just take u32, like the `*_sh?` methods in core
* Because shift-by-anything is allowed, cast into a new local for every shift
incr.comp.: Make sure we don't lose unused green results from the query cache.
rustbuild: Update LLVM and enable ThinLTO
This commit updates LLVM to fix #45511 (https://reviews.llvm.org/D39981) and
also reenables ThinLTO for libtest now that we shouldn't hit #45768. This also
opportunistically enables ThinLTO for libstd which was previously blocked
(#45661) on test failures related to debuginfo with a presumed cause of #45511.
Closes #45511
std: Flag Windows TLS dtor symbol as #[used]
Turns out ThinLTO was internalizing this symbol and eliminating it. Worse yet if
you compiled with LTO turns out no TLS destructors would run on Windows! The
`#[used]` annotation should be a more bulletproof implementation (in the face of
LTO) of preserving this symbol all the way through in LLVM and ensuring it makes
it all the way to the linker which will take care of it.
Add enum InitializationRequiringAction
Fix tidy tests
2017-11-23 17:06:48 +05:30
|
|
|
self.check_if_path_is_moved(context, InitializationRequiringAction::Use,
|
2017-11-17 17:19:57 +02:00
|
|
|
(lvalue, span), flow_state);
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
2017-11-17 17:19:57 +02:00
|
|
|
Operand::Constant(_) => {}
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-07 04:44:41 -05:00
|
|
|
impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
2017-07-05 14:52:18 +02:00
|
|
|
fn check_if_reassignment_to_immutable_state(&mut self,
|
|
|
|
context: Context,
|
2017-12-01 14:31:47 +02:00
|
|
|
(lvalue, span): (&Place<'tcx>, Span),
|
2017-11-07 04:44:41 -05:00
|
|
|
flow_state: &InProgress<'cx, 'gcx, 'tcx>) {
|
MIR-borrowck: Big fix to `fn check_if_path_is_moved`.
Fix #44833 (a very specific instance of a very broad bug).
In `check_if_path_is_moved(L)`, check nearest prefix of L with
MovePath, and suffixes of L with MovePaths.
Over the course of review, ariel pointed out a number of issues that
led to this version of the commit:
1. Looking solely at supporting prefixes does not suffice: it
overlooks checking if the path was ever actually initialized in the
first place. So you need to be willing to consider non-supporting
prefixes. Once you are looking at all prefixes, you *could* just
look at the local that forms the base of the projection, but to
handle partial initialization (which still needs to be formally
specified), this code instead looks at the nearest prefix of L that
has an associated MovePath (which, in the limit, will end up being
a local).
2. You also need to consider the suffixes of the given Lvalue, due to
how dataflow is representing partial moves of individual fields out
of struct values.
3. (There was originally a third search, but ariel pointed out that
the first and third could be folded into one.)
Also includes some drive-by refactorings to simplify some method
signatures and prefer `for _ in _` over `loop { }` (at least when it
comes semi-naturally).
2017-10-04 17:46:46 +02:00
|
|
|
let move_data = self.move_data;
|
2017-07-05 14:52:18 +02:00
|
|
|
|
|
|
|
// determine if this path has a non-mut owner (and thus needs checking).
|
2017-11-30 23:18:38 +00:00
|
|
|
if let Ok(()) = self.is_mutable(lvalue, LocalMutationIsAllowed::No) {
|
|
|
|
return;
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
|
2017-11-30 23:18:38 +00:00
|
|
|
if let Err(_) = self.is_mutable(lvalue, LocalMutationIsAllowed::Yes) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
match self.move_path_closest_to(lvalue) {
|
|
|
|
Ok(mpi) => {
|
|
|
|
for ii in &move_data.init_path_map[mpi] {
|
|
|
|
if flow_state.ever_inits.curr_state.contains(ii) {
|
|
|
|
let first_assign_span = self.move_data.inits[*ii].span;
|
|
|
|
self.report_illegal_reassignment(
|
|
|
|
context, (lvalue, span), first_assign_span);
|
|
|
|
break;
|
|
|
|
}
|
2017-11-27 08:06:36 +00:00
|
|
|
}
|
2017-11-30 23:18:38 +00:00
|
|
|
},
|
|
|
|
Err(NoMovePathFound::ReachedStatic) => {
|
|
|
|
let item_msg = match self.describe_lvalue(lvalue) {
|
|
|
|
Some(name) => format!("immutable static item `{}`", name),
|
|
|
|
None => "immutable static item".to_owned()
|
|
|
|
};
|
|
|
|
self.tcx.sess.delay_span_bug(span,
|
|
|
|
&format!("cannot assign to {}, should have been caught by \
|
|
|
|
`check_access_permissions()`", item_msg));
|
|
|
|
},
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_if_path_is_moved(&mut self,
|
|
|
|
context: Context,
|
MIR: Fix value moved diagnose messages
MIR: adopt borrowck test
Fix trailing whitespace
span_bug! on unexpected action
Make RegionVid use newtype_index!
Closes #45843
Check rvalue aggregates during check_stmt in tycheck, add initial, (not passing) test
Fix failing test
Remove attributes and test comments accidentally left behind, add in span_mirbugs
Normalize LvalueTy for ops and format code to satisfy tidy check
only normalize operand types when in an ADT constructor
avoid early return
handle the active field index in unions
normalize types in ADT constructor
Fixes #45940
Fix borrowck compiler errors for upvars contain "spurious" dereferences
Fixes #46003
added associated function Box::leak
Box::leak - improve documentation
Box::leak - fixed bug in documentation
Box::leak - relaxed constraints wrt. lifetimes
Box::leak - updated documentation
Box::leak - made an oops, fixed now =)
Box::leak: update unstable issue number (46179).
Add test for #44953
Add missing Debug impls to std_unicode
Also adds #![deny(missing_debug_implementations)] so they don't get
missed again.
Amend RELEASES for 1.22.1
and fix the date for 1.22.0
Rename param in `[T]::swap_with_slice` from `src` to `other`.
The idea of ‘source’ and ‘destination’ aren’t very applicable for this
operation since both slices can both be considered sources and
destinations.
Clarify stdin behavior of `Command::output`.
Fixes #44929.
Add hints for the case of confusing enum with its variants
Add failing testcases
Add module population and case of enum in place of expression
Use for_each_child_stable in find_module
Use multiline text for crate conflict diagnostics
Make float::from_bits transmute (and update the documentation to reflect this).
The current implementation/documentation was made to avoid sNaN because of
potential safety issues implied by old/bad LLVM documentation. These issues
aren't real, so we can just make the implementation transmute (as permitted
by the existing documentation of this method).
Also the documentation didn't actually match the behaviour: it said we may
change sNaNs, but in fact we canonicalized *all* NaNs.
Also an example in the documentation was wrong: it said we *always* change
sNaNs, when the documentation was explicitly written to indicate it was
implementation-defined.
This makes to_bits and from_bits perfectly roundtrip cross-platform, except
for one caveat: although the 2008 edition of IEEE-754 specifies how to
interpet the signaling bit, earlier editions didn't. This lead to some platforms
picking the opposite interpretation, so all signaling NaNs on x86/ARM are quiet
on MIPS, and vice-versa.
NaN-boxing is a fairly important optimization, while we don't even guarantee
that float operations properly preserve signalingness. As such, this seems like
the more natural strategy to take (as opposed to trying to mangle the signaling
bit on a per-platform basis).
This implementation is also, of course, faster.
Simplify an Iterator::fold to Iterator::any
This method of once-diagnostics doesn't allow nesting
UI tests extract the regular output from the 'rendered' field in json
Merge cfail and ui tests into ui tests
Add a MIR pass to lower 128-bit operators to lang item calls
Runs only with `-Z lower_128bit_ops` since it's not hooked into targets yet.
Include tuple projections in MIR tests
Add type checking for the lang item
As part of doing so, add more lang items instead of passing u128 to the i128 ones where it doesn't matter in twos-complement.
Handle shifts properly
* The overflow-checking shift items need to take a full 128-bit type, since they need to be able to detect idiocy like `1i128 << (1u128 << 127)`
* The unchecked ones just take u32, like the `*_sh?` methods in core
* Because shift-by-anything is allowed, cast into a new local for every shift
incr.comp.: Make sure we don't lose unused green results from the query cache.
rustbuild: Update LLVM and enable ThinLTO
This commit updates LLVM to fix #45511 (https://reviews.llvm.org/D39981) and
also reenables ThinLTO for libtest now that we shouldn't hit #45768. This also
opportunistically enables ThinLTO for libstd which was previously blocked
(#45661) on test failures related to debuginfo with a presumed cause of #45511.
Closes #45511
std: Flag Windows TLS dtor symbol as #[used]
Turns out ThinLTO was internalizing this symbol and eliminating it. Worse yet if
you compiled with LTO turns out no TLS destructors would run on Windows! The
`#[used]` annotation should be a more bulletproof implementation (in the face of
LTO) of preserving this symbol all the way through in LLVM and ensuring it makes
it all the way to the linker which will take care of it.
Add enum InitializationRequiringAction
Fix tidy tests
2017-11-23 17:06:48 +05:30
|
|
|
desired_action: InitializationRequiringAction,
|
2017-12-01 14:31:47 +02:00
|
|
|
lvalue_span: (&Place<'tcx>, Span),
|
2017-11-07 04:44:41 -05:00
|
|
|
flow_state: &InProgress<'cx, 'gcx, 'tcx>) {
|
2017-07-05 14:52:18 +02:00
|
|
|
// FIXME: analogous code in check_loans first maps `lvalue` to
|
|
|
|
// its base_path ... but is that what we want here?
|
|
|
|
let lvalue = self.base_path(lvalue_span.0);
|
|
|
|
|
|
|
|
let maybe_uninits = &flow_state.uninits;
|
2017-11-08 18:32:08 +03:00
|
|
|
let curr_move_outs = &flow_state.move_outs.curr_state;
|
MIR-borrowck: Big fix to `fn check_if_path_is_moved`.
Fix #44833 (a very specific instance of a very broad bug).
In `check_if_path_is_moved(L)`, check nearest prefix of L with
MovePath, and suffixes of L with MovePaths.
Over the course of review, ariel pointed out a number of issues that
led to this version of the commit:
1. Looking solely at supporting prefixes does not suffice: it
overlooks checking if the path was ever actually initialized in the
first place. So you need to be willing to consider non-supporting
prefixes. Once you are looking at all prefixes, you *could* just
look at the local that forms the base of the projection, but to
handle partial initialization (which still needs to be formally
specified), this code instead looks at the nearest prefix of L that
has an associated MovePath (which, in the limit, will end up being
a local).
2. You also need to consider the suffixes of the given Lvalue, due to
how dataflow is representing partial moves of individual fields out
of struct values.
3. (There was originally a third search, but ariel pointed out that
the first and third could be folded into one.)
Also includes some drive-by refactorings to simplify some method
signatures and prefer `for _ in _` over `loop { }` (at least when it
comes semi-naturally).
2017-10-04 17:46:46 +02:00
|
|
|
|
|
|
|
// Bad scenarios:
|
|
|
|
//
|
|
|
|
// 1. Move of `a.b.c`, use of `a.b.c`
|
|
|
|
// 2. Move of `a.b.c`, use of `a.b.c.d` (without first reinitializing `a.b.c.d`)
|
|
|
|
// 3. Move of `a.b.c`, use of `a` or `a.b`
|
|
|
|
// 4. Uninitialized `(a.b.c: &_)`, use of `*a.b.c`; note that with
|
|
|
|
// partial initialization support, one might have `a.x`
|
|
|
|
// initialized but not `a.b`.
|
|
|
|
//
|
|
|
|
// OK scenarios:
|
|
|
|
//
|
|
|
|
// 5. Move of `a.b.c`, use of `a.b.d`
|
|
|
|
// 6. Uninitialized `a.x`, initialized `a.b`, use of `a.b`
|
|
|
|
// 7. Copied `(a.b: &_)`, use of `*(a.b).c`; note that `a.b`
|
|
|
|
// must have been initialized for the use to be sound.
|
|
|
|
// 8. Move of `a.b.c` then reinit of `a.b.c.d`, use of `a.b.c.d`
|
|
|
|
|
|
|
|
// The dataflow tracks shallow prefixes distinctly (that is,
|
|
|
|
// field-accesses on P distinctly from P itself), in order to
|
|
|
|
// track substructure initialization separately from the whole
|
|
|
|
// structure.
|
|
|
|
//
|
|
|
|
// E.g., when looking at (*a.b.c).d, if the closest prefix for
|
|
|
|
// which we have a MovePath is `a.b`, then that means that the
|
|
|
|
// initialization state of `a.b` is all we need to inspect to
|
|
|
|
// know if `a.b.c` is valid (and from that we infer that the
|
|
|
|
// dereference and `.d` access is also valid, since we assume
|
|
|
|
// `a.b.c` is assigned a reference to a initialized and
|
|
|
|
// well-formed record structure.)
|
|
|
|
|
|
|
|
// Therefore, if we seek out the *closest* prefix for which we
|
|
|
|
// have a MovePath, that should capture the initialization
|
|
|
|
// state for the lvalue scenario.
|
|
|
|
//
|
|
|
|
// This code covers scenarios 1, 2, and 4.
|
|
|
|
|
|
|
|
debug!("check_if_path_is_moved part1 lvalue: {:?}", lvalue);
|
|
|
|
match self.move_path_closest_to(lvalue) {
|
|
|
|
Ok(mpi) => {
|
|
|
|
if maybe_uninits.curr_state.contains(&mpi) {
|
2017-11-08 18:32:08 +03:00
|
|
|
self.report_use_of_moved_or_uninitialized(context, desired_action,
|
|
|
|
lvalue_span, mpi,
|
|
|
|
curr_move_outs);
|
MIR-borrowck: Big fix to `fn check_if_path_is_moved`.
Fix #44833 (a very specific instance of a very broad bug).
In `check_if_path_is_moved(L)`, check nearest prefix of L with
MovePath, and suffixes of L with MovePaths.
Over the course of review, ariel pointed out a number of issues that
led to this version of the commit:
1. Looking solely at supporting prefixes does not suffice: it
overlooks checking if the path was ever actually initialized in the
first place. So you need to be willing to consider non-supporting
prefixes. Once you are looking at all prefixes, you *could* just
look at the local that forms the base of the projection, but to
handle partial initialization (which still needs to be formally
specified), this code instead looks at the nearest prefix of L that
has an associated MovePath (which, in the limit, will end up being
a local).
2. You also need to consider the suffixes of the given Lvalue, due to
how dataflow is representing partial moves of individual fields out
of struct values.
3. (There was originally a third search, but ariel pointed out that
the first and third could be folded into one.)
Also includes some drive-by refactorings to simplify some method
signatures and prefer `for _ in _` over `loop { }` (at least when it
comes semi-naturally).
2017-10-04 17:46:46 +02:00
|
|
|
return; // don't bother finding other problems.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(NoMovePathFound::ReachedStatic) => {
|
|
|
|
// Okay: we do not build MoveData for static variables
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only query longest prefix with a MovePath, not further
|
|
|
|
// ancestors; dataflow recurs on children when parents
|
|
|
|
// move (to support partial (re)inits).
|
|
|
|
//
|
|
|
|
// (I.e. querying parents breaks scenario 8; but may want
|
|
|
|
// to do such a query based on partial-init feature-gate.)
|
|
|
|
}
|
|
|
|
|
|
|
|
// A move of any shallow suffix of `lvalue` also interferes
|
|
|
|
// with an attempt to use `lvalue`. This is scenario 3 above.
|
|
|
|
//
|
|
|
|
// (Distinct from handling of scenarios 1+2+4 above because
|
|
|
|
// `lvalue` does not interfere with suffixes of its prefixes,
|
|
|
|
// e.g. `a.b.c` does not interfere with `a.b.d`)
|
|
|
|
|
|
|
|
debug!("check_if_path_is_moved part2 lvalue: {:?}", lvalue);
|
|
|
|
if let Some(mpi) = self.move_path_for_lvalue(lvalue) {
|
2017-11-08 18:32:08 +03:00
|
|
|
if let Some(child_mpi) = maybe_uninits.has_any_child_of(mpi) {
|
|
|
|
self.report_use_of_moved_or_uninitialized(context, desired_action,
|
|
|
|
lvalue_span, child_mpi,
|
|
|
|
curr_move_outs);
|
MIR-borrowck: Big fix to `fn check_if_path_is_moved`.
Fix #44833 (a very specific instance of a very broad bug).
In `check_if_path_is_moved(L)`, check nearest prefix of L with
MovePath, and suffixes of L with MovePaths.
Over the course of review, ariel pointed out a number of issues that
led to this version of the commit:
1. Looking solely at supporting prefixes does not suffice: it
overlooks checking if the path was ever actually initialized in the
first place. So you need to be willing to consider non-supporting
prefixes. Once you are looking at all prefixes, you *could* just
look at the local that forms the base of the projection, but to
handle partial initialization (which still needs to be formally
specified), this code instead looks at the nearest prefix of L that
has an associated MovePath (which, in the limit, will end up being
a local).
2. You also need to consider the suffixes of the given Lvalue, due to
how dataflow is representing partial moves of individual fields out
of struct values.
3. (There was originally a third search, but ariel pointed out that
the first and third could be folded into one.)
Also includes some drive-by refactorings to simplify some method
signatures and prefer `for _ in _` over `loop { }` (at least when it
comes semi-naturally).
2017-10-04 17:46:46 +02:00
|
|
|
return; // don't bother finding other problems.
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
MIR-borrowck: Big fix to `fn check_if_path_is_moved`.
Fix #44833 (a very specific instance of a very broad bug).
In `check_if_path_is_moved(L)`, check nearest prefix of L with
MovePath, and suffixes of L with MovePaths.
Over the course of review, ariel pointed out a number of issues that
led to this version of the commit:
1. Looking solely at supporting prefixes does not suffice: it
overlooks checking if the path was ever actually initialized in the
first place. So you need to be willing to consider non-supporting
prefixes. Once you are looking at all prefixes, you *could* just
look at the local that forms the base of the projection, but to
handle partial initialization (which still needs to be formally
specified), this code instead looks at the nearest prefix of L that
has an associated MovePath (which, in the limit, will end up being
a local).
2. You also need to consider the suffixes of the given Lvalue, due to
how dataflow is representing partial moves of individual fields out
of struct values.
3. (There was originally a third search, but ariel pointed out that
the first and third could be folded into one.)
Also includes some drive-by refactorings to simplify some method
signatures and prefer `for _ in _` over `loop { }` (at least when it
comes semi-naturally).
2017-10-04 17:46:46 +02:00
|
|
|
/// Currently MoveData does not store entries for all lvalues in
|
|
|
|
/// the input MIR. For example it will currently filter out
|
|
|
|
/// lvalues that are Copy; thus we do not track lvalues of shared
|
|
|
|
/// reference type. This routine will walk up an lvalue along its
|
|
|
|
/// prefixes, searching for a foundational lvalue that *is*
|
|
|
|
/// tracked in the MoveData.
|
|
|
|
///
|
|
|
|
/// An Err result includes a tag indicated why the search failed.
|
|
|
|
/// Currenly this can only occur if the lvalue is built off of a
|
|
|
|
/// static variable, as we do not track those in the MoveData.
|
2017-12-01 14:31:47 +02:00
|
|
|
fn move_path_closest_to(&mut self, lvalue: &Place<'tcx>)
|
MIR-borrowck: Big fix to `fn check_if_path_is_moved`.
Fix #44833 (a very specific instance of a very broad bug).
In `check_if_path_is_moved(L)`, check nearest prefix of L with
MovePath, and suffixes of L with MovePaths.
Over the course of review, ariel pointed out a number of issues that
led to this version of the commit:
1. Looking solely at supporting prefixes does not suffice: it
overlooks checking if the path was ever actually initialized in the
first place. So you need to be willing to consider non-supporting
prefixes. Once you are looking at all prefixes, you *could* just
look at the local that forms the base of the projection, but to
handle partial initialization (which still needs to be formally
specified), this code instead looks at the nearest prefix of L that
has an associated MovePath (which, in the limit, will end up being
a local).
2. You also need to consider the suffixes of the given Lvalue, due to
how dataflow is representing partial moves of individual fields out
of struct values.
3. (There was originally a third search, but ariel pointed out that
the first and third could be folded into one.)
Also includes some drive-by refactorings to simplify some method
signatures and prefer `for _ in _` over `loop { }` (at least when it
comes semi-naturally).
2017-10-04 17:46:46 +02:00
|
|
|
-> Result<MovePathIndex, NoMovePathFound>
|
|
|
|
{
|
|
|
|
let mut last_prefix = lvalue;
|
|
|
|
for prefix in self.prefixes(lvalue, PrefixSet::All) {
|
|
|
|
if let Some(mpi) = self.move_path_for_lvalue(prefix) {
|
|
|
|
return Ok(mpi);
|
|
|
|
}
|
|
|
|
last_prefix = prefix;
|
|
|
|
}
|
|
|
|
match *last_prefix {
|
2017-12-01 14:31:47 +02:00
|
|
|
Place::Local(_) => panic!("should have move path for every Local"),
|
|
|
|
Place::Projection(_) => panic!("PrefixSet::All meant dont stop for Projection"),
|
|
|
|
Place::Static(_) => return Err(NoMovePathFound::ReachedStatic),
|
MIR-borrowck: Big fix to `fn check_if_path_is_moved`.
Fix #44833 (a very specific instance of a very broad bug).
In `check_if_path_is_moved(L)`, check nearest prefix of L with
MovePath, and suffixes of L with MovePaths.
Over the course of review, ariel pointed out a number of issues that
led to this version of the commit:
1. Looking solely at supporting prefixes does not suffice: it
overlooks checking if the path was ever actually initialized in the
first place. So you need to be willing to consider non-supporting
prefixes. Once you are looking at all prefixes, you *could* just
look at the local that forms the base of the projection, but to
handle partial initialization (which still needs to be formally
specified), this code instead looks at the nearest prefix of L that
has an associated MovePath (which, in the limit, will end up being
a local).
2. You also need to consider the suffixes of the given Lvalue, due to
how dataflow is representing partial moves of individual fields out
of struct values.
3. (There was originally a third search, but ariel pointed out that
the first and third could be folded into one.)
Also includes some drive-by refactorings to simplify some method
signatures and prefer `for _ in _` over `loop { }` (at least when it
comes semi-naturally).
2017-10-04 17:46:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-05 14:52:18 +02:00
|
|
|
fn move_path_for_lvalue(&mut self,
|
2017-12-01 14:31:47 +02:00
|
|
|
lvalue: &Place<'tcx>)
|
2017-07-05 14:52:18 +02:00
|
|
|
-> Option<MovePathIndex>
|
|
|
|
{
|
|
|
|
// If returns None, then there is no move path corresponding
|
|
|
|
// to a direct owner of `lvalue` (which means there is nothing
|
|
|
|
// that borrowck tracks for its analysis).
|
|
|
|
|
MIR-borrowck: Big fix to `fn check_if_path_is_moved`.
Fix #44833 (a very specific instance of a very broad bug).
In `check_if_path_is_moved(L)`, check nearest prefix of L with
MovePath, and suffixes of L with MovePaths.
Over the course of review, ariel pointed out a number of issues that
led to this version of the commit:
1. Looking solely at supporting prefixes does not suffice: it
overlooks checking if the path was ever actually initialized in the
first place. So you need to be willing to consider non-supporting
prefixes. Once you are looking at all prefixes, you *could* just
look at the local that forms the base of the projection, but to
handle partial initialization (which still needs to be formally
specified), this code instead looks at the nearest prefix of L that
has an associated MovePath (which, in the limit, will end up being
a local).
2. You also need to consider the suffixes of the given Lvalue, due to
how dataflow is representing partial moves of individual fields out
of struct values.
3. (There was originally a third search, but ariel pointed out that
the first and third could be folded into one.)
Also includes some drive-by refactorings to simplify some method
signatures and prefer `for _ in _` over `loop { }` (at least when it
comes semi-naturally).
2017-10-04 17:46:46 +02:00
|
|
|
match self.move_data.rev_lookup.find(lvalue) {
|
2017-07-05 14:52:18 +02:00
|
|
|
LookupResult::Parent(_) => None,
|
|
|
|
LookupResult::Exact(mpi) => Some(mpi),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_if_assigned_path_is_moved(&mut self,
|
|
|
|
context: Context,
|
2017-12-01 14:31:47 +02:00
|
|
|
(lvalue, span): (&Place<'tcx>, Span),
|
2017-11-07 04:44:41 -05:00
|
|
|
flow_state: &InProgress<'cx, 'gcx, 'tcx>) {
|
2017-07-05 14:52:18 +02:00
|
|
|
// recur down lvalue; dispatch to check_if_path_is_moved when necessary
|
|
|
|
let mut lvalue = lvalue;
|
|
|
|
loop {
|
|
|
|
match *lvalue {
|
2017-12-01 14:31:47 +02:00
|
|
|
Place::Local(_) | Place::Static(_) => {
|
2017-07-05 14:52:18 +02:00
|
|
|
// assigning to `x` does not require `x` be initialized.
|
|
|
|
break;
|
|
|
|
}
|
2017-12-01 14:31:47 +02:00
|
|
|
Place::Projection(ref proj) => {
|
2017-07-05 14:52:18 +02:00
|
|
|
let Projection { ref base, ref elem } = **proj;
|
|
|
|
match *elem {
|
|
|
|
ProjectionElem::Deref |
|
|
|
|
// assigning to *P requires `P` initialized.
|
|
|
|
ProjectionElem::Index(_/*operand*/) |
|
|
|
|
ProjectionElem::ConstantIndex { .. } |
|
|
|
|
// assigning to P[i] requires `P` initialized.
|
|
|
|
ProjectionElem::Downcast(_/*adt_def*/, _/*variant_idx*/) =>
|
|
|
|
// assigning to (P->variant) is okay if assigning to `P` is okay
|
|
|
|
//
|
|
|
|
// FIXME: is this true even if P is a adt with a dtor?
|
|
|
|
{ }
|
|
|
|
|
|
|
|
ProjectionElem::Subslice { .. } => {
|
|
|
|
panic!("we dont allow assignments to subslices, context: {:?}",
|
|
|
|
context);
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectionElem::Field(..) => {
|
|
|
|
// if type of `P` has a dtor, then
|
|
|
|
// assigning to `P.f` requires `P` itself
|
|
|
|
// be already initialized
|
|
|
|
let tcx = self.tcx;
|
|
|
|
match base.ty(self.mir, tcx).to_ty(tcx).sty {
|
|
|
|
ty::TyAdt(def, _) if def.has_dtor(tcx) => {
|
|
|
|
|
|
|
|
// FIXME: analogous code in
|
|
|
|
// check_loans.rs first maps
|
|
|
|
// `base` to its base_path.
|
|
|
|
|
2017-08-21 12:48:33 +02:00
|
|
|
self.check_if_path_is_moved(
|
MIR: Fix value moved diagnose messages
MIR: adopt borrowck test
Fix trailing whitespace
span_bug! on unexpected action
Make RegionVid use newtype_index!
Closes #45843
Check rvalue aggregates during check_stmt in tycheck, add initial, (not passing) test
Fix failing test
Remove attributes and test comments accidentally left behind, add in span_mirbugs
Normalize LvalueTy for ops and format code to satisfy tidy check
only normalize operand types when in an ADT constructor
avoid early return
handle the active field index in unions
normalize types in ADT constructor
Fixes #45940
Fix borrowck compiler errors for upvars contain "spurious" dereferences
Fixes #46003
added associated function Box::leak
Box::leak - improve documentation
Box::leak - fixed bug in documentation
Box::leak - relaxed constraints wrt. lifetimes
Box::leak - updated documentation
Box::leak - made an oops, fixed now =)
Box::leak: update unstable issue number (46179).
Add test for #44953
Add missing Debug impls to std_unicode
Also adds #![deny(missing_debug_implementations)] so they don't get
missed again.
Amend RELEASES for 1.22.1
and fix the date for 1.22.0
Rename param in `[T]::swap_with_slice` from `src` to `other`.
The idea of ‘source’ and ‘destination’ aren’t very applicable for this
operation since both slices can both be considered sources and
destinations.
Clarify stdin behavior of `Command::output`.
Fixes #44929.
Add hints for the case of confusing enum with its variants
Add failing testcases
Add module population and case of enum in place of expression
Use for_each_child_stable in find_module
Use multiline text for crate conflict diagnostics
Make float::from_bits transmute (and update the documentation to reflect this).
The current implementation/documentation was made to avoid sNaN because of
potential safety issues implied by old/bad LLVM documentation. These issues
aren't real, so we can just make the implementation transmute (as permitted
by the existing documentation of this method).
Also the documentation didn't actually match the behaviour: it said we may
change sNaNs, but in fact we canonicalized *all* NaNs.
Also an example in the documentation was wrong: it said we *always* change
sNaNs, when the documentation was explicitly written to indicate it was
implementation-defined.
This makes to_bits and from_bits perfectly roundtrip cross-platform, except
for one caveat: although the 2008 edition of IEEE-754 specifies how to
interpet the signaling bit, earlier editions didn't. This lead to some platforms
picking the opposite interpretation, so all signaling NaNs on x86/ARM are quiet
on MIPS, and vice-versa.
NaN-boxing is a fairly important optimization, while we don't even guarantee
that float operations properly preserve signalingness. As such, this seems like
the more natural strategy to take (as opposed to trying to mangle the signaling
bit on a per-platform basis).
This implementation is also, of course, faster.
Simplify an Iterator::fold to Iterator::any
This method of once-diagnostics doesn't allow nesting
UI tests extract the regular output from the 'rendered' field in json
Merge cfail and ui tests into ui tests
Add a MIR pass to lower 128-bit operators to lang item calls
Runs only with `-Z lower_128bit_ops` since it's not hooked into targets yet.
Include tuple projections in MIR tests
Add type checking for the lang item
As part of doing so, add more lang items instead of passing u128 to the i128 ones where it doesn't matter in twos-complement.
Handle shifts properly
* The overflow-checking shift items need to take a full 128-bit type, since they need to be able to detect idiocy like `1i128 << (1u128 << 127)`
* The unchecked ones just take u32, like the `*_sh?` methods in core
* Because shift-by-anything is allowed, cast into a new local for every shift
incr.comp.: Make sure we don't lose unused green results from the query cache.
rustbuild: Update LLVM and enable ThinLTO
This commit updates LLVM to fix #45511 (https://reviews.llvm.org/D39981) and
also reenables ThinLTO for libtest now that we shouldn't hit #45768. This also
opportunistically enables ThinLTO for libstd which was previously blocked
(#45661) on test failures related to debuginfo with a presumed cause of #45511.
Closes #45511
std: Flag Windows TLS dtor symbol as #[used]
Turns out ThinLTO was internalizing this symbol and eliminating it. Worse yet if
you compiled with LTO turns out no TLS destructors would run on Windows! The
`#[used]` annotation should be a more bulletproof implementation (in the face of
LTO) of preserving this symbol all the way through in LLVM and ensuring it makes
it all the way to the linker which will take care of it.
Add enum InitializationRequiringAction
Fix tidy tests
2017-11-23 17:06:48 +05:30
|
|
|
context, InitializationRequiringAction::Assignment,
|
|
|
|
(base, span), flow_state);
|
2017-07-05 14:52:18 +02:00
|
|
|
|
|
|
|
// (base initialized; no need to
|
|
|
|
// recur further)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lvalue = base;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-10-21 21:15:04 +02:00
|
|
|
|
|
|
|
/// Check the permissions for the given lvalue and read or write kind
|
2017-11-16 17:44:24 +01:00
|
|
|
///
|
|
|
|
/// Returns true if an error is reported, false otherwise.
|
|
|
|
fn check_access_permissions(&self,
|
2017-12-01 14:31:47 +02:00
|
|
|
(lvalue, span): (&Place<'tcx>, Span),
|
2017-11-16 17:44:24 +01:00
|
|
|
kind: ReadOrWrite,
|
|
|
|
is_local_mutation_allowed: LocalMutationIsAllowed)
|
|
|
|
-> bool {
|
|
|
|
debug!("check_access_permissions({:?}, {:?}, {:?})",
|
|
|
|
lvalue, kind, is_local_mutation_allowed);
|
|
|
|
let mut error_reported = false;
|
2017-10-21 21:15:04 +02:00
|
|
|
match kind {
|
|
|
|
Write(WriteKind::MutableBorrow(BorrowKind::Unique)) => {
|
|
|
|
if let Err(_lvalue_err) = self.is_unique(lvalue) {
|
2017-11-16 17:44:24 +01:00
|
|
|
span_bug!(span, "&unique borrow for {:?} should not fail", lvalue);
|
2017-10-21 21:15:04 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
Write(WriteKind::MutableBorrow(BorrowKind::Mut)) => {
|
2017-11-16 17:44:24 +01:00
|
|
|
if let Err(lvalue_err) = self.is_mutable(lvalue, is_local_mutation_allowed) {
|
|
|
|
error_reported = true;
|
|
|
|
|
|
|
|
let item_msg = match self.describe_lvalue(lvalue) {
|
|
|
|
Some(name) => format!("immutable item `{}`", name),
|
|
|
|
None => "immutable item".to_owned()
|
|
|
|
};
|
|
|
|
|
2017-10-21 21:15:04 +02:00
|
|
|
let mut err = self.tcx.cannot_borrow_path_as_mutable(span,
|
2017-11-16 17:44:24 +01:00
|
|
|
&item_msg,
|
2017-10-21 21:15:04 +02:00
|
|
|
Origin::Mir);
|
|
|
|
err.span_label(span, "cannot borrow as mutable");
|
|
|
|
|
|
|
|
if lvalue != lvalue_err {
|
2017-11-16 17:44:24 +01:00
|
|
|
if let Some(name) = self.describe_lvalue(lvalue_err) {
|
|
|
|
err.note(&format!("Value not mutable causing this error: `{}`", name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err.emit();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Write(WriteKind::Mutate) => {
|
|
|
|
if let Err(lvalue_err) = self.is_mutable(lvalue, is_local_mutation_allowed) {
|
|
|
|
error_reported = true;
|
|
|
|
|
|
|
|
let item_msg = match self.describe_lvalue(lvalue) {
|
|
|
|
Some(name) => format!("immutable item `{}`", name),
|
|
|
|
None => "immutable item".to_owned()
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut err = self.tcx.cannot_assign(span,
|
|
|
|
&item_msg,
|
|
|
|
Origin::Mir);
|
|
|
|
err.span_label(span, "cannot mutate");
|
|
|
|
|
|
|
|
if lvalue != lvalue_err {
|
|
|
|
if let Some(name) = self.describe_lvalue(lvalue_err) {
|
|
|
|
err.note(&format!("Value not mutable causing this error: `{}`", name));
|
|
|
|
}
|
2017-10-21 21:15:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
err.emit();
|
|
|
|
}
|
|
|
|
},
|
2017-11-16 17:44:24 +01:00
|
|
|
Write(WriteKind::Move) |
|
|
|
|
Write(WriteKind::StorageDeadOrDrop) |
|
|
|
|
Write(WriteKind::MutableBorrow(BorrowKind::Shared)) => {
|
|
|
|
if let Err(_lvalue_err) = self.is_mutable(lvalue, is_local_mutation_allowed) {
|
|
|
|
self.tcx.sess.delay_span_bug(span,
|
|
|
|
&format!("Accessing `{:?}` with the kind `{:?}` shouldn't be possible",
|
|
|
|
lvalue,
|
|
|
|
kind));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Read(ReadKind::Borrow(BorrowKind::Unique)) |
|
|
|
|
Read(ReadKind::Borrow(BorrowKind::Mut)) |
|
|
|
|
Read(ReadKind::Borrow(BorrowKind::Shared)) |
|
|
|
|
Read(ReadKind::Copy) => {} // Access authorized
|
2017-10-21 21:15:04 +02:00
|
|
|
}
|
2017-11-16 17:44:24 +01:00
|
|
|
|
|
|
|
error_reported
|
2017-10-21 21:15:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Can this value be written or borrowed mutably
|
2017-11-16 17:44:24 +01:00
|
|
|
fn is_mutable<'d>(&self,
|
2017-12-01 14:31:47 +02:00
|
|
|
lvalue: &'d Place<'tcx>,
|
2017-11-16 17:44:24 +01:00
|
|
|
is_local_mutation_allowed: LocalMutationIsAllowed)
|
2017-12-01 14:31:47 +02:00
|
|
|
-> Result<(), &'d Place<'tcx>> {
|
2017-10-21 21:15:04 +02:00
|
|
|
match *lvalue {
|
2017-12-01 14:31:47 +02:00
|
|
|
Place::Local(local) => {
|
2017-10-21 21:15:04 +02:00
|
|
|
let local = &self.mir.local_decls[local];
|
|
|
|
match local.mutability {
|
2017-11-16 17:44:24 +01:00
|
|
|
Mutability::Not =>
|
|
|
|
match is_local_mutation_allowed {
|
|
|
|
LocalMutationIsAllowed::Yes => Ok(()),
|
|
|
|
LocalMutationIsAllowed::No => Err(lvalue),
|
|
|
|
},
|
2017-10-21 21:15:04 +02:00
|
|
|
Mutability::Mut => Ok(())
|
|
|
|
}
|
|
|
|
},
|
2017-12-01 14:31:47 +02:00
|
|
|
Place::Static(ref static_) => {
|
2017-10-21 21:15:04 +02:00
|
|
|
if !self.tcx.is_static_mut(static_.def_id) {
|
|
|
|
Err(lvalue)
|
|
|
|
} else {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
},
|
2017-12-01 14:31:47 +02:00
|
|
|
Place::Projection(ref proj) => {
|
2017-10-21 21:15:04 +02:00
|
|
|
match proj.elem {
|
|
|
|
ProjectionElem::Deref => {
|
|
|
|
let base_ty = proj.base.ty(self.mir, self.tcx).to_ty(self.tcx);
|
|
|
|
|
2017-11-30 23:18:38 +00:00
|
|
|
// Check the kind of deref to decide
|
2017-10-21 21:15:04 +02:00
|
|
|
match base_ty.sty {
|
|
|
|
ty::TyRef(_, tnm) => {
|
|
|
|
match tnm.mutbl {
|
|
|
|
// Shared borrowed data is never mutable
|
|
|
|
hir::MutImmutable => Err(lvalue),
|
|
|
|
// Mutably borrowed data is mutable, but only if we have a
|
|
|
|
// unique path to the `&mut`
|
2017-11-30 23:18:38 +00:00
|
|
|
hir::MutMutable => {
|
|
|
|
if self.is_upvar_field_projection(&proj.base).is_some() {
|
|
|
|
self.is_mutable(&proj.base, is_local_mutation_allowed)
|
|
|
|
} else {
|
|
|
|
self.is_unique(&proj.base)
|
|
|
|
}
|
|
|
|
},
|
2017-10-21 21:15:04 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
ty::TyRawPtr(tnm) => {
|
|
|
|
match tnm.mutbl {
|
|
|
|
// `*const` raw pointers are not mutable
|
|
|
|
hir::MutImmutable => Err(lvalue),
|
|
|
|
// `*mut` raw pointers are always mutable, regardless of context
|
|
|
|
// The users have to check by themselve.
|
|
|
|
hir::MutMutable => Ok(()),
|
|
|
|
}
|
|
|
|
},
|
2017-11-30 23:18:38 +00:00
|
|
|
// `Box<T>` owns its content, so mutable if its location is mutable
|
|
|
|
_ if base_ty.is_box() =>
|
|
|
|
self.is_mutable(&proj.base, LocalMutationIsAllowed::No),
|
2017-10-21 21:15:04 +02:00
|
|
|
// Deref should only be for reference, pointers or boxes
|
2017-11-30 23:18:38 +00:00
|
|
|
_ => bug!("Deref of unexpected type: {:?}", base_ty),
|
2017-10-21 21:15:04 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
// All other projections are owned by their base path, so mutable if
|
|
|
|
// base path is mutable
|
|
|
|
ProjectionElem::Field(..) |
|
|
|
|
ProjectionElem::Index(..) |
|
|
|
|
ProjectionElem::ConstantIndex{..} |
|
|
|
|
ProjectionElem::Subslice{..} |
|
2017-11-30 23:18:38 +00:00
|
|
|
ProjectionElem::Downcast(..) => {
|
|
|
|
let field_projection = self.is_upvar_field_projection(lvalue);
|
|
|
|
|
|
|
|
if let Some(field) = field_projection {
|
|
|
|
let decl = &self.mir.upvar_decls[field.index()];
|
|
|
|
|
|
|
|
return match decl.mutability {
|
|
|
|
Mutability::Mut => self.is_unique(&proj.base),
|
|
|
|
Mutability::Not => Err(lvalue),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-11-16 17:44:24 +01:00
|
|
|
self.is_mutable(&proj.base, LocalMutationIsAllowed::No)
|
2017-11-30 23:18:38 +00:00
|
|
|
}
|
2017-10-21 21:15:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Does this lvalue have a unique path
|
2017-12-01 14:31:47 +02:00
|
|
|
fn is_unique<'d>(&self, lvalue: &'d Place<'tcx>) -> Result<(), &'d Place<'tcx>> {
|
2017-10-21 21:15:04 +02:00
|
|
|
match *lvalue {
|
2017-12-01 14:31:47 +02:00
|
|
|
Place::Local(..) => {
|
2017-10-21 21:15:04 +02:00
|
|
|
// Local variables are unique
|
|
|
|
Ok(())
|
|
|
|
},
|
2017-12-01 14:31:47 +02:00
|
|
|
Place::Static(..) => {
|
2017-10-21 21:15:04 +02:00
|
|
|
// Static variables are not
|
|
|
|
Err(lvalue)
|
|
|
|
},
|
2017-12-01 14:31:47 +02:00
|
|
|
Place::Projection(ref proj) => {
|
2017-10-21 21:15:04 +02:00
|
|
|
match proj.elem {
|
|
|
|
ProjectionElem::Deref => {
|
|
|
|
let base_ty = proj.base.ty(self.mir, self.tcx).to_ty(self.tcx);
|
|
|
|
|
|
|
|
// `Box<T>` referent is unique if box is a unique spot
|
|
|
|
if base_ty.is_box() {
|
|
|
|
return self.is_unique(&proj.base);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise we check the kind of deref to decide
|
|
|
|
match base_ty.sty {
|
|
|
|
ty::TyRef(_, tnm) => {
|
|
|
|
match tnm.mutbl {
|
|
|
|
// lvalue represent an aliased location
|
|
|
|
hir::MutImmutable => Err(lvalue),
|
|
|
|
// `&mut T` is as unique as the context in which it is found
|
|
|
|
hir::MutMutable => self.is_unique(&proj.base),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
ty::TyRawPtr(tnm) => {
|
|
|
|
match tnm.mutbl {
|
|
|
|
// `*mut` can be aliased, but we leave it to user
|
|
|
|
hir::MutMutable => Ok(()),
|
|
|
|
// `*const` is treated the same as `*mut`
|
|
|
|
hir::MutImmutable => Ok(()),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// Deref should only be for reference, pointers or boxes
|
|
|
|
_ => bug!("Deref of unexpected type: {:?}", base_ty)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// Other projections are unique if the base is unique
|
|
|
|
ProjectionElem::Field(..) |
|
|
|
|
ProjectionElem::Index(..) |
|
|
|
|
ProjectionElem::ConstantIndex{..} |
|
|
|
|
ProjectionElem::Subslice{..} |
|
|
|
|
ProjectionElem::Downcast(..) =>
|
|
|
|
self.is_unique(&proj.base)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-09-22 15:37:43 +02:00
|
|
|
}
|
2017-07-05 14:52:18 +02:00
|
|
|
|
MIR-borrowck: Big fix to `fn check_if_path_is_moved`.
Fix #44833 (a very specific instance of a very broad bug).
In `check_if_path_is_moved(L)`, check nearest prefix of L with
MovePath, and suffixes of L with MovePaths.
Over the course of review, ariel pointed out a number of issues that
led to this version of the commit:
1. Looking solely at supporting prefixes does not suffice: it
overlooks checking if the path was ever actually initialized in the
first place. So you need to be willing to consider non-supporting
prefixes. Once you are looking at all prefixes, you *could* just
look at the local that forms the base of the projection, but to
handle partial initialization (which still needs to be formally
specified), this code instead looks at the nearest prefix of L that
has an associated MovePath (which, in the limit, will end up being
a local).
2. You also need to consider the suffixes of the given Lvalue, due to
how dataflow is representing partial moves of individual fields out
of struct values.
3. (There was originally a third search, but ariel pointed out that
the first and third could be folded into one.)
Also includes some drive-by refactorings to simplify some method
signatures and prefer `for _ in _` over `loop { }` (at least when it
comes semi-naturally).
2017-10-04 17:46:46 +02:00
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
|
|
|
enum NoMovePathFound {
|
|
|
|
ReachedStatic,
|
|
|
|
}
|
|
|
|
|
2017-11-07 04:44:41 -05:00
|
|
|
impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
2017-07-05 14:52:18 +02:00
|
|
|
fn each_borrow_involving_path<F>(&mut self,
|
|
|
|
_context: Context,
|
2017-12-01 14:31:47 +02:00
|
|
|
access_lvalue: (ShallowOrDeep, &Place<'tcx>),
|
2017-11-07 04:44:41 -05:00
|
|
|
flow_state: &InProgress<'cx, 'gcx, 'tcx>,
|
2017-07-05 14:52:18 +02:00
|
|
|
mut op: F)
|
2017-12-01 14:31:47 +02:00
|
|
|
where F: FnMut(&mut Self, BorrowIndex, &BorrowData<'tcx>, &Place<'tcx>) -> Control
|
2017-07-05 14:52:18 +02:00
|
|
|
{
|
2017-08-21 12:48:33 +02:00
|
|
|
let (access, lvalue) = access_lvalue;
|
|
|
|
|
2017-07-05 14:52:18 +02:00
|
|
|
// FIXME: analogous code in check_loans first maps `lvalue` to
|
|
|
|
// its base_path.
|
|
|
|
|
|
|
|
let domain = flow_state.borrows.base_results.operator();
|
|
|
|
let data = domain.borrows();
|
|
|
|
|
|
|
|
// check for loan restricting path P being used. Accounts for
|
|
|
|
// borrows of P, P.a.b, etc.
|
2017-08-21 12:48:33 +02:00
|
|
|
'next_borrow: for i in flow_state.borrows.elems_incoming() {
|
2017-07-05 14:52:18 +02:00
|
|
|
let borrowed = &data[i];
|
2017-08-21 12:48:33 +02:00
|
|
|
|
|
|
|
// Is `lvalue` (or a prefix of it) already borrowed? If
|
|
|
|
// so, that's relevant.
|
|
|
|
//
|
|
|
|
// FIXME: Differs from AST-borrowck; includes drive-by fix
|
|
|
|
// to #38899. Will probably need back-compat mode flag.
|
|
|
|
for accessed_prefix in self.prefixes(lvalue, PrefixSet::All) {
|
|
|
|
if *accessed_prefix == borrowed.lvalue {
|
2017-10-03 14:00:38 +02:00
|
|
|
// FIXME: pass in enum describing case we are in?
|
|
|
|
let ctrl = op(self, i, borrowed, accessed_prefix);
|
2017-07-05 14:52:18 +02:00
|
|
|
if ctrl == Control::Break { return; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-21 12:48:33 +02:00
|
|
|
// Is `lvalue` a prefix (modulo access type) of the
|
|
|
|
// `borrowed.lvalue`? If so, that's relevant.
|
|
|
|
|
|
|
|
let prefix_kind = match access {
|
|
|
|
Shallow(Some(ArtificialField::Discriminant)) |
|
|
|
|
Shallow(Some(ArtificialField::ArrayLength)) => {
|
|
|
|
// The discriminant and array length are like
|
|
|
|
// additional fields on the type; they do not
|
|
|
|
// overlap any existing data there. Furthermore,
|
|
|
|
// they cannot actually be a prefix of any
|
|
|
|
// borrowed lvalue (at least in MIR as it is
|
|
|
|
// currently.)
|
|
|
|
continue 'next_borrow;
|
|
|
|
}
|
|
|
|
Shallow(None) => PrefixSet::Shallow,
|
|
|
|
Deep => PrefixSet::Supporting,
|
|
|
|
};
|
|
|
|
|
|
|
|
for borrowed_prefix in self.prefixes(&borrowed.lvalue, prefix_kind) {
|
|
|
|
if borrowed_prefix == lvalue {
|
2017-10-03 14:00:38 +02:00
|
|
|
// FIXME: pass in enum describing case we are in?
|
|
|
|
let ctrl = op(self, i, borrowed, borrowed_prefix);
|
2017-07-05 14:52:18 +02:00
|
|
|
if ctrl == Control::Break { return; }
|
|
|
|
}
|
|
|
|
}
|
2017-08-21 12:48:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
use self::prefixes::PrefixSet;
|
2017-07-05 14:52:18 +02:00
|
|
|
|
2017-08-21 12:48:33 +02:00
|
|
|
/// From the NLL RFC: "The deep [aka 'supporting'] prefixes for an
|
|
|
|
/// lvalue are formed by stripping away fields and derefs, except that
|
|
|
|
/// we stop when we reach the deref of a shared reference. [...] "
|
|
|
|
///
|
|
|
|
/// "Shallow prefixes are found by stripping away fields, but stop at
|
|
|
|
/// any dereference. So: writing a path like `a` is illegal if `a.b`
|
|
|
|
/// is borrowed. But: writing `a` is legal if `*a` is borrowed,
|
|
|
|
/// whether or not `a` is a shared or mutable reference. [...] "
|
|
|
|
mod prefixes {
|
|
|
|
use super::{MirBorrowckCtxt};
|
|
|
|
|
|
|
|
use rustc::hir;
|
|
|
|
use rustc::ty::{self, TyCtxt};
|
2017-12-01 14:31:47 +02:00
|
|
|
use rustc::mir::{Place, Mir, ProjectionElem};
|
2017-08-21 12:48:33 +02:00
|
|
|
|
2017-10-03 14:00:38 +02:00
|
|
|
pub trait IsPrefixOf<'tcx> {
|
2017-12-01 14:31:47 +02:00
|
|
|
fn is_prefix_of(&self, other: &Place<'tcx>) -> bool;
|
2017-10-03 14:00:38 +02:00
|
|
|
}
|
|
|
|
|
2017-12-01 14:31:47 +02:00
|
|
|
impl<'tcx> IsPrefixOf<'tcx> for Place<'tcx> {
|
|
|
|
fn is_prefix_of(&self, other: &Place<'tcx>) -> bool {
|
2017-10-03 14:00:38 +02:00
|
|
|
let mut cursor = other;
|
|
|
|
loop {
|
|
|
|
if self == cursor {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
match *cursor {
|
2017-12-01 14:31:47 +02:00
|
|
|
Place::Local(_) |
|
|
|
|
Place::Static(_) => return false,
|
|
|
|
Place::Projection(ref proj) => {
|
2017-10-03 14:00:38 +02:00
|
|
|
cursor = &proj.base;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-07 04:44:41 -05:00
|
|
|
pub(super) struct Prefixes<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
|
|
|
|
mir: &'cx Mir<'tcx>,
|
|
|
|
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
|
2017-08-21 12:48:33 +02:00
|
|
|
kind: PrefixSet,
|
2017-12-01 14:31:47 +02:00
|
|
|
next: Option<&'cx Place<'tcx>>,
|
2017-08-21 12:48:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
|
|
|
pub(super) enum PrefixSet {
|
MIR-borrowck: Big fix to `fn check_if_path_is_moved`.
Fix #44833 (a very specific instance of a very broad bug).
In `check_if_path_is_moved(L)`, check nearest prefix of L with
MovePath, and suffixes of L with MovePaths.
Over the course of review, ariel pointed out a number of issues that
led to this version of the commit:
1. Looking solely at supporting prefixes does not suffice: it
overlooks checking if the path was ever actually initialized in the
first place. So you need to be willing to consider non-supporting
prefixes. Once you are looking at all prefixes, you *could* just
look at the local that forms the base of the projection, but to
handle partial initialization (which still needs to be formally
specified), this code instead looks at the nearest prefix of L that
has an associated MovePath (which, in the limit, will end up being
a local).
2. You also need to consider the suffixes of the given Lvalue, due to
how dataflow is representing partial moves of individual fields out
of struct values.
3. (There was originally a third search, but ariel pointed out that
the first and third could be folded into one.)
Also includes some drive-by refactorings to simplify some method
signatures and prefer `for _ in _` over `loop { }` (at least when it
comes semi-naturally).
2017-10-04 17:46:46 +02:00
|
|
|
/// Doesn't stop until it returns the base case (a Local or
|
|
|
|
/// Static prefix).
|
2017-08-21 12:48:33 +02:00
|
|
|
All,
|
MIR-borrowck: Big fix to `fn check_if_path_is_moved`.
Fix #44833 (a very specific instance of a very broad bug).
In `check_if_path_is_moved(L)`, check nearest prefix of L with
MovePath, and suffixes of L with MovePaths.
Over the course of review, ariel pointed out a number of issues that
led to this version of the commit:
1. Looking solely at supporting prefixes does not suffice: it
overlooks checking if the path was ever actually initialized in the
first place. So you need to be willing to consider non-supporting
prefixes. Once you are looking at all prefixes, you *could* just
look at the local that forms the base of the projection, but to
handle partial initialization (which still needs to be formally
specified), this code instead looks at the nearest prefix of L that
has an associated MovePath (which, in the limit, will end up being
a local).
2. You also need to consider the suffixes of the given Lvalue, due to
how dataflow is representing partial moves of individual fields out
of struct values.
3. (There was originally a third search, but ariel pointed out that
the first and third could be folded into one.)
Also includes some drive-by refactorings to simplify some method
signatures and prefer `for _ in _` over `loop { }` (at least when it
comes semi-naturally).
2017-10-04 17:46:46 +02:00
|
|
|
/// Stops at any dereference.
|
2017-08-21 12:48:33 +02:00
|
|
|
Shallow,
|
MIR-borrowck: Big fix to `fn check_if_path_is_moved`.
Fix #44833 (a very specific instance of a very broad bug).
In `check_if_path_is_moved(L)`, check nearest prefix of L with
MovePath, and suffixes of L with MovePaths.
Over the course of review, ariel pointed out a number of issues that
led to this version of the commit:
1. Looking solely at supporting prefixes does not suffice: it
overlooks checking if the path was ever actually initialized in the
first place. So you need to be willing to consider non-supporting
prefixes. Once you are looking at all prefixes, you *could* just
look at the local that forms the base of the projection, but to
handle partial initialization (which still needs to be formally
specified), this code instead looks at the nearest prefix of L that
has an associated MovePath (which, in the limit, will end up being
a local).
2. You also need to consider the suffixes of the given Lvalue, due to
how dataflow is representing partial moves of individual fields out
of struct values.
3. (There was originally a third search, but ariel pointed out that
the first and third could be folded into one.)
Also includes some drive-by refactorings to simplify some method
signatures and prefer `for _ in _` over `loop { }` (at least when it
comes semi-naturally).
2017-10-04 17:46:46 +02:00
|
|
|
/// Stops at the deref of a shared reference.
|
2017-08-21 12:48:33 +02:00
|
|
|
Supporting,
|
|
|
|
}
|
|
|
|
|
2017-11-07 04:44:41 -05:00
|
|
|
impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
MIR-borrowck: Big fix to `fn check_if_path_is_moved`.
Fix #44833 (a very specific instance of a very broad bug).
In `check_if_path_is_moved(L)`, check nearest prefix of L with
MovePath, and suffixes of L with MovePaths.
Over the course of review, ariel pointed out a number of issues that
led to this version of the commit:
1. Looking solely at supporting prefixes does not suffice: it
overlooks checking if the path was ever actually initialized in the
first place. So you need to be willing to consider non-supporting
prefixes. Once you are looking at all prefixes, you *could* just
look at the local that forms the base of the projection, but to
handle partial initialization (which still needs to be formally
specified), this code instead looks at the nearest prefix of L that
has an associated MovePath (which, in the limit, will end up being
a local).
2. You also need to consider the suffixes of the given Lvalue, due to
how dataflow is representing partial moves of individual fields out
of struct values.
3. (There was originally a third search, but ariel pointed out that
the first and third could be folded into one.)
Also includes some drive-by refactorings to simplify some method
signatures and prefer `for _ in _` over `loop { }` (at least when it
comes semi-naturally).
2017-10-04 17:46:46 +02:00
|
|
|
/// Returns an iterator over the prefixes of `lvalue`
|
|
|
|
/// (inclusive) from longest to smallest, potentially
|
|
|
|
/// terminating the iteration early based on `kind`.
|
2017-11-07 04:44:41 -05:00
|
|
|
pub(super) fn prefixes(&self,
|
2017-12-01 14:31:47 +02:00
|
|
|
lvalue: &'cx Place<'tcx>,
|
2017-11-07 04:44:41 -05:00
|
|
|
kind: PrefixSet)
|
|
|
|
-> Prefixes<'cx, 'gcx, 'tcx>
|
2017-08-21 12:48:33 +02:00
|
|
|
{
|
|
|
|
Prefixes { next: Some(lvalue), kind, mir: self.mir, tcx: self.tcx }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-07 04:44:41 -05:00
|
|
|
impl<'cx, 'gcx, 'tcx> Iterator for Prefixes<'cx, 'gcx, 'tcx> {
|
2017-12-01 14:31:47 +02:00
|
|
|
type Item = &'cx Place<'tcx>;
|
2017-08-21 12:48:33 +02:00
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
|
|
let mut cursor = match self.next {
|
|
|
|
None => return None,
|
|
|
|
Some(lvalue) => lvalue,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Post-processing `lvalue`: Enqueue any remaining
|
|
|
|
// work. Also, `lvalue` may not be a prefix itself, but
|
|
|
|
// may hold one further down (e.g. we never return
|
|
|
|
// downcasts here, but may return a base of a downcast).
|
|
|
|
|
|
|
|
'cursor: loop {
|
|
|
|
let proj = match *cursor {
|
2017-12-01 14:31:47 +02:00
|
|
|
Place::Local(_) | // search yielded this leaf
|
|
|
|
Place::Static(_) => {
|
2017-08-21 12:48:33 +02:00
|
|
|
self.next = None;
|
|
|
|
return Some(cursor);
|
|
|
|
}
|
|
|
|
|
2017-12-01 14:31:47 +02:00
|
|
|
Place::Projection(ref proj) => proj,
|
2017-08-21 12:48:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
match proj.elem {
|
|
|
|
ProjectionElem::Field(_/*field*/, _/*ty*/) => {
|
|
|
|
// FIXME: add union handling
|
|
|
|
self.next = Some(&proj.base);
|
|
|
|
return Some(cursor);
|
|
|
|
}
|
|
|
|
ProjectionElem::Downcast(..) |
|
|
|
|
ProjectionElem::Subslice { .. } |
|
|
|
|
ProjectionElem::ConstantIndex { .. } |
|
|
|
|
ProjectionElem::Index(_) => {
|
|
|
|
cursor = &proj.base;
|
|
|
|
continue 'cursor;
|
|
|
|
}
|
|
|
|
ProjectionElem::Deref => {
|
|
|
|
// (handled below)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_eq!(proj.elem, ProjectionElem::Deref);
|
|
|
|
|
|
|
|
match self.kind {
|
|
|
|
PrefixSet::Shallow => {
|
|
|
|
// shallow prefixes are found by stripping away
|
|
|
|
// fields, but stop at *any* dereference.
|
|
|
|
// So we can just stop the traversal now.
|
|
|
|
self.next = None;
|
|
|
|
return Some(cursor);
|
|
|
|
}
|
|
|
|
PrefixSet::All => {
|
|
|
|
// all prefixes: just blindly enqueue the base
|
|
|
|
// of the projection
|
|
|
|
self.next = Some(&proj.base);
|
|
|
|
return Some(cursor);
|
|
|
|
}
|
|
|
|
PrefixSet::Supporting => {
|
|
|
|
// fall through!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_eq!(self.kind, PrefixSet::Supporting);
|
|
|
|
// supporting prefixes: strip away fields and
|
|
|
|
// derefs, except we stop at the deref of a shared
|
|
|
|
// reference.
|
|
|
|
|
|
|
|
let ty = proj.base.ty(self.mir, self.tcx).to_ty(self.tcx);
|
|
|
|
match ty.sty {
|
|
|
|
ty::TyRawPtr(_) |
|
|
|
|
ty::TyRef(_/*rgn*/, ty::TypeAndMut { ty: _, mutbl: hir::MutImmutable }) => {
|
|
|
|
// don't continue traversing over derefs of raw pointers or shared borrows.
|
|
|
|
self.next = None;
|
|
|
|
return Some(cursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
ty::TyRef(_/*rgn*/, ty::TypeAndMut { ty: _, mutbl: hir::MutMutable }) => {
|
|
|
|
self.next = Some(&proj.base);
|
|
|
|
return Some(cursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
ty::TyAdt(..) if ty.is_box() => {
|
|
|
|
self.next = Some(&proj.base);
|
|
|
|
return Some(cursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
_ => panic!("unknown type fed to Projection Deref."),
|
|
|
|
}
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-07 04:44:41 -05:00
|
|
|
impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
2017-11-08 18:32:08 +03:00
|
|
|
fn report_use_of_moved_or_uninitialized(&mut self,
|
2017-07-05 14:52:18 +02:00
|
|
|
_context: Context,
|
MIR: Fix value moved diagnose messages
MIR: adopt borrowck test
Fix trailing whitespace
span_bug! on unexpected action
Make RegionVid use newtype_index!
Closes #45843
Check rvalue aggregates during check_stmt in tycheck, add initial, (not passing) test
Fix failing test
Remove attributes and test comments accidentally left behind, add in span_mirbugs
Normalize LvalueTy for ops and format code to satisfy tidy check
only normalize operand types when in an ADT constructor
avoid early return
handle the active field index in unions
normalize types in ADT constructor
Fixes #45940
Fix borrowck compiler errors for upvars contain "spurious" dereferences
Fixes #46003
added associated function Box::leak
Box::leak - improve documentation
Box::leak - fixed bug in documentation
Box::leak - relaxed constraints wrt. lifetimes
Box::leak - updated documentation
Box::leak - made an oops, fixed now =)
Box::leak: update unstable issue number (46179).
Add test for #44953
Add missing Debug impls to std_unicode
Also adds #![deny(missing_debug_implementations)] so they don't get
missed again.
Amend RELEASES for 1.22.1
and fix the date for 1.22.0
Rename param in `[T]::swap_with_slice` from `src` to `other`.
The idea of ‘source’ and ‘destination’ aren’t very applicable for this
operation since both slices can both be considered sources and
destinations.
Clarify stdin behavior of `Command::output`.
Fixes #44929.
Add hints for the case of confusing enum with its variants
Add failing testcases
Add module population and case of enum in place of expression
Use for_each_child_stable in find_module
Use multiline text for crate conflict diagnostics
Make float::from_bits transmute (and update the documentation to reflect this).
The current implementation/documentation was made to avoid sNaN because of
potential safety issues implied by old/bad LLVM documentation. These issues
aren't real, so we can just make the implementation transmute (as permitted
by the existing documentation of this method).
Also the documentation didn't actually match the behaviour: it said we may
change sNaNs, but in fact we canonicalized *all* NaNs.
Also an example in the documentation was wrong: it said we *always* change
sNaNs, when the documentation was explicitly written to indicate it was
implementation-defined.
This makes to_bits and from_bits perfectly roundtrip cross-platform, except
for one caveat: although the 2008 edition of IEEE-754 specifies how to
interpet the signaling bit, earlier editions didn't. This lead to some platforms
picking the opposite interpretation, so all signaling NaNs on x86/ARM are quiet
on MIPS, and vice-versa.
NaN-boxing is a fairly important optimization, while we don't even guarantee
that float operations properly preserve signalingness. As such, this seems like
the more natural strategy to take (as opposed to trying to mangle the signaling
bit on a per-platform basis).
This implementation is also, of course, faster.
Simplify an Iterator::fold to Iterator::any
This method of once-diagnostics doesn't allow nesting
UI tests extract the regular output from the 'rendered' field in json
Merge cfail and ui tests into ui tests
Add a MIR pass to lower 128-bit operators to lang item calls
Runs only with `-Z lower_128bit_ops` since it's not hooked into targets yet.
Include tuple projections in MIR tests
Add type checking for the lang item
As part of doing so, add more lang items instead of passing u128 to the i128 ones where it doesn't matter in twos-complement.
Handle shifts properly
* The overflow-checking shift items need to take a full 128-bit type, since they need to be able to detect idiocy like `1i128 << (1u128 << 127)`
* The unchecked ones just take u32, like the `*_sh?` methods in core
* Because shift-by-anything is allowed, cast into a new local for every shift
incr.comp.: Make sure we don't lose unused green results from the query cache.
rustbuild: Update LLVM and enable ThinLTO
This commit updates LLVM to fix #45511 (https://reviews.llvm.org/D39981) and
also reenables ThinLTO for libtest now that we shouldn't hit #45768. This also
opportunistically enables ThinLTO for libstd which was previously blocked
(#45661) on test failures related to debuginfo with a presumed cause of #45511.
Closes #45511
std: Flag Windows TLS dtor symbol as #[used]
Turns out ThinLTO was internalizing this symbol and eliminating it. Worse yet if
you compiled with LTO turns out no TLS destructors would run on Windows! The
`#[used]` annotation should be a more bulletproof implementation (in the face of
LTO) of preserving this symbol all the way through in LLVM and ensuring it makes
it all the way to the linker which will take care of it.
Add enum InitializationRequiringAction
Fix tidy tests
2017-11-23 17:06:48 +05:30
|
|
|
desired_action: InitializationRequiringAction,
|
2017-12-01 14:31:47 +02:00
|
|
|
(lvalue, span): (&Place<'tcx>, Span),
|
2017-11-08 18:32:08 +03:00
|
|
|
mpi: MovePathIndex,
|
|
|
|
curr_move_out: &IdxSetBuf<MoveOutIndex>) {
|
|
|
|
|
|
|
|
let mois = self.move_data.path_map[mpi].iter().filter(
|
|
|
|
|moi| curr_move_out.contains(moi)).collect::<Vec<_>>();
|
|
|
|
|
|
|
|
if mois.is_empty() {
|
2017-11-22 17:35:52 +01:00
|
|
|
let item_msg = match self.describe_lvalue(lvalue) {
|
|
|
|
Some(name) => format!("`{}`", name),
|
|
|
|
None => "value".to_owned()
|
|
|
|
};
|
2017-11-08 18:32:08 +03:00
|
|
|
self.tcx.cannot_act_on_uninitialized_variable(span,
|
MIR: Fix value moved diagnose messages
MIR: adopt borrowck test
Fix trailing whitespace
span_bug! on unexpected action
Make RegionVid use newtype_index!
Closes #45843
Check rvalue aggregates during check_stmt in tycheck, add initial, (not passing) test
Fix failing test
Remove attributes and test comments accidentally left behind, add in span_mirbugs
Normalize LvalueTy for ops and format code to satisfy tidy check
only normalize operand types when in an ADT constructor
avoid early return
handle the active field index in unions
normalize types in ADT constructor
Fixes #45940
Fix borrowck compiler errors for upvars contain "spurious" dereferences
Fixes #46003
added associated function Box::leak
Box::leak - improve documentation
Box::leak - fixed bug in documentation
Box::leak - relaxed constraints wrt. lifetimes
Box::leak - updated documentation
Box::leak - made an oops, fixed now =)
Box::leak: update unstable issue number (46179).
Add test for #44953
Add missing Debug impls to std_unicode
Also adds #![deny(missing_debug_implementations)] so they don't get
missed again.
Amend RELEASES for 1.22.1
and fix the date for 1.22.0
Rename param in `[T]::swap_with_slice` from `src` to `other`.
The idea of ‘source’ and ‘destination’ aren’t very applicable for this
operation since both slices can both be considered sources and
destinations.
Clarify stdin behavior of `Command::output`.
Fixes #44929.
Add hints for the case of confusing enum with its variants
Add failing testcases
Add module population and case of enum in place of expression
Use for_each_child_stable in find_module
Use multiline text for crate conflict diagnostics
Make float::from_bits transmute (and update the documentation to reflect this).
The current implementation/documentation was made to avoid sNaN because of
potential safety issues implied by old/bad LLVM documentation. These issues
aren't real, so we can just make the implementation transmute (as permitted
by the existing documentation of this method).
Also the documentation didn't actually match the behaviour: it said we may
change sNaNs, but in fact we canonicalized *all* NaNs.
Also an example in the documentation was wrong: it said we *always* change
sNaNs, when the documentation was explicitly written to indicate it was
implementation-defined.
This makes to_bits and from_bits perfectly roundtrip cross-platform, except
for one caveat: although the 2008 edition of IEEE-754 specifies how to
interpet the signaling bit, earlier editions didn't. This lead to some platforms
picking the opposite interpretation, so all signaling NaNs on x86/ARM are quiet
on MIPS, and vice-versa.
NaN-boxing is a fairly important optimization, while we don't even guarantee
that float operations properly preserve signalingness. As such, this seems like
the more natural strategy to take (as opposed to trying to mangle the signaling
bit on a per-platform basis).
This implementation is also, of course, faster.
Simplify an Iterator::fold to Iterator::any
This method of once-diagnostics doesn't allow nesting
UI tests extract the regular output from the 'rendered' field in json
Merge cfail and ui tests into ui tests
Add a MIR pass to lower 128-bit operators to lang item calls
Runs only with `-Z lower_128bit_ops` since it's not hooked into targets yet.
Include tuple projections in MIR tests
Add type checking for the lang item
As part of doing so, add more lang items instead of passing u128 to the i128 ones where it doesn't matter in twos-complement.
Handle shifts properly
* The overflow-checking shift items need to take a full 128-bit type, since they need to be able to detect idiocy like `1i128 << (1u128 << 127)`
* The unchecked ones just take u32, like the `*_sh?` methods in core
* Because shift-by-anything is allowed, cast into a new local for every shift
incr.comp.: Make sure we don't lose unused green results from the query cache.
rustbuild: Update LLVM and enable ThinLTO
This commit updates LLVM to fix #45511 (https://reviews.llvm.org/D39981) and
also reenables ThinLTO for libtest now that we shouldn't hit #45768. This also
opportunistically enables ThinLTO for libstd which was previously blocked
(#45661) on test failures related to debuginfo with a presumed cause of #45511.
Closes #45511
std: Flag Windows TLS dtor symbol as #[used]
Turns out ThinLTO was internalizing this symbol and eliminating it. Worse yet if
you compiled with LTO turns out no TLS destructors would run on Windows! The
`#[used]` annotation should be a more bulletproof implementation (in the face of
LTO) of preserving this symbol all the way through in LLVM and ensuring it makes
it all the way to the linker which will take care of it.
Add enum InitializationRequiringAction
Fix tidy tests
2017-11-23 17:06:48 +05:30
|
|
|
desired_action.as_noun(),
|
2017-11-22 17:35:52 +01:00
|
|
|
&self.describe_lvalue(lvalue)
|
|
|
|
.unwrap_or("_".to_owned()),
|
2017-11-08 18:32:08 +03:00
|
|
|
Origin::Mir)
|
2017-11-22 17:35:52 +01:00
|
|
|
.span_label(span, format!("use of possibly uninitialized {}", item_msg))
|
2017-11-08 18:32:08 +03:00
|
|
|
.emit();
|
|
|
|
} else {
|
|
|
|
let msg = ""; //FIXME: add "partially " or "collaterally "
|
|
|
|
|
|
|
|
let mut err = self.tcx.cannot_act_on_moved_value(span,
|
MIR: Fix value moved diagnose messages
MIR: adopt borrowck test
Fix trailing whitespace
span_bug! on unexpected action
Make RegionVid use newtype_index!
Closes #45843
Check rvalue aggregates during check_stmt in tycheck, add initial, (not passing) test
Fix failing test
Remove attributes and test comments accidentally left behind, add in span_mirbugs
Normalize LvalueTy for ops and format code to satisfy tidy check
only normalize operand types when in an ADT constructor
avoid early return
handle the active field index in unions
normalize types in ADT constructor
Fixes #45940
Fix borrowck compiler errors for upvars contain "spurious" dereferences
Fixes #46003
added associated function Box::leak
Box::leak - improve documentation
Box::leak - fixed bug in documentation
Box::leak - relaxed constraints wrt. lifetimes
Box::leak - updated documentation
Box::leak - made an oops, fixed now =)
Box::leak: update unstable issue number (46179).
Add test for #44953
Add missing Debug impls to std_unicode
Also adds #![deny(missing_debug_implementations)] so they don't get
missed again.
Amend RELEASES for 1.22.1
and fix the date for 1.22.0
Rename param in `[T]::swap_with_slice` from `src` to `other`.
The idea of ‘source’ and ‘destination’ aren’t very applicable for this
operation since both slices can both be considered sources and
destinations.
Clarify stdin behavior of `Command::output`.
Fixes #44929.
Add hints for the case of confusing enum with its variants
Add failing testcases
Add module population and case of enum in place of expression
Use for_each_child_stable in find_module
Use multiline text for crate conflict diagnostics
Make float::from_bits transmute (and update the documentation to reflect this).
The current implementation/documentation was made to avoid sNaN because of
potential safety issues implied by old/bad LLVM documentation. These issues
aren't real, so we can just make the implementation transmute (as permitted
by the existing documentation of this method).
Also the documentation didn't actually match the behaviour: it said we may
change sNaNs, but in fact we canonicalized *all* NaNs.
Also an example in the documentation was wrong: it said we *always* change
sNaNs, when the documentation was explicitly written to indicate it was
implementation-defined.
This makes to_bits and from_bits perfectly roundtrip cross-platform, except
for one caveat: although the 2008 edition of IEEE-754 specifies how to
interpet the signaling bit, earlier editions didn't. This lead to some platforms
picking the opposite interpretation, so all signaling NaNs on x86/ARM are quiet
on MIPS, and vice-versa.
NaN-boxing is a fairly important optimization, while we don't even guarantee
that float operations properly preserve signalingness. As such, this seems like
the more natural strategy to take (as opposed to trying to mangle the signaling
bit on a per-platform basis).
This implementation is also, of course, faster.
Simplify an Iterator::fold to Iterator::any
This method of once-diagnostics doesn't allow nesting
UI tests extract the regular output from the 'rendered' field in json
Merge cfail and ui tests into ui tests
Add a MIR pass to lower 128-bit operators to lang item calls
Runs only with `-Z lower_128bit_ops` since it's not hooked into targets yet.
Include tuple projections in MIR tests
Add type checking for the lang item
As part of doing so, add more lang items instead of passing u128 to the i128 ones where it doesn't matter in twos-complement.
Handle shifts properly
* The overflow-checking shift items need to take a full 128-bit type, since they need to be able to detect idiocy like `1i128 << (1u128 << 127)`
* The unchecked ones just take u32, like the `*_sh?` methods in core
* Because shift-by-anything is allowed, cast into a new local for every shift
incr.comp.: Make sure we don't lose unused green results from the query cache.
rustbuild: Update LLVM and enable ThinLTO
This commit updates LLVM to fix #45511 (https://reviews.llvm.org/D39981) and
also reenables ThinLTO for libtest now that we shouldn't hit #45768. This also
opportunistically enables ThinLTO for libstd which was previously blocked
(#45661) on test failures related to debuginfo with a presumed cause of #45511.
Closes #45511
std: Flag Windows TLS dtor symbol as #[used]
Turns out ThinLTO was internalizing this symbol and eliminating it. Worse yet if
you compiled with LTO turns out no TLS destructors would run on Windows! The
`#[used]` annotation should be a more bulletproof implementation (in the face of
LTO) of preserving this symbol all the way through in LLVM and ensuring it makes
it all the way to the linker which will take care of it.
Add enum InitializationRequiringAction
Fix tidy tests
2017-11-23 17:06:48 +05:30
|
|
|
desired_action.as_noun(),
|
2017-11-08 18:32:08 +03:00
|
|
|
msg,
|
2017-11-22 17:35:52 +01:00
|
|
|
&self.describe_lvalue(lvalue)
|
|
|
|
.unwrap_or("_".to_owned()),
|
2017-11-08 18:32:08 +03:00
|
|
|
Origin::Mir);
|
MIR: Fix value moved diagnose messages
MIR: adopt borrowck test
Fix trailing whitespace
span_bug! on unexpected action
Make RegionVid use newtype_index!
Closes #45843
Check rvalue aggregates during check_stmt in tycheck, add initial, (not passing) test
Fix failing test
Remove attributes and test comments accidentally left behind, add in span_mirbugs
Normalize LvalueTy for ops and format code to satisfy tidy check
only normalize operand types when in an ADT constructor
avoid early return
handle the active field index in unions
normalize types in ADT constructor
Fixes #45940
Fix borrowck compiler errors for upvars contain "spurious" dereferences
Fixes #46003
added associated function Box::leak
Box::leak - improve documentation
Box::leak - fixed bug in documentation
Box::leak - relaxed constraints wrt. lifetimes
Box::leak - updated documentation
Box::leak - made an oops, fixed now =)
Box::leak: update unstable issue number (46179).
Add test for #44953
Add missing Debug impls to std_unicode
Also adds #![deny(missing_debug_implementations)] so they don't get
missed again.
Amend RELEASES for 1.22.1
and fix the date for 1.22.0
Rename param in `[T]::swap_with_slice` from `src` to `other`.
The idea of ‘source’ and ‘destination’ aren’t very applicable for this
operation since both slices can both be considered sources and
destinations.
Clarify stdin behavior of `Command::output`.
Fixes #44929.
Add hints for the case of confusing enum with its variants
Add failing testcases
Add module population and case of enum in place of expression
Use for_each_child_stable in find_module
Use multiline text for crate conflict diagnostics
Make float::from_bits transmute (and update the documentation to reflect this).
The current implementation/documentation was made to avoid sNaN because of
potential safety issues implied by old/bad LLVM documentation. These issues
aren't real, so we can just make the implementation transmute (as permitted
by the existing documentation of this method).
Also the documentation didn't actually match the behaviour: it said we may
change sNaNs, but in fact we canonicalized *all* NaNs.
Also an example in the documentation was wrong: it said we *always* change
sNaNs, when the documentation was explicitly written to indicate it was
implementation-defined.
This makes to_bits and from_bits perfectly roundtrip cross-platform, except
for one caveat: although the 2008 edition of IEEE-754 specifies how to
interpet the signaling bit, earlier editions didn't. This lead to some platforms
picking the opposite interpretation, so all signaling NaNs on x86/ARM are quiet
on MIPS, and vice-versa.
NaN-boxing is a fairly important optimization, while we don't even guarantee
that float operations properly preserve signalingness. As such, this seems like
the more natural strategy to take (as opposed to trying to mangle the signaling
bit on a per-platform basis).
This implementation is also, of course, faster.
Simplify an Iterator::fold to Iterator::any
This method of once-diagnostics doesn't allow nesting
UI tests extract the regular output from the 'rendered' field in json
Merge cfail and ui tests into ui tests
Add a MIR pass to lower 128-bit operators to lang item calls
Runs only with `-Z lower_128bit_ops` since it's not hooked into targets yet.
Include tuple projections in MIR tests
Add type checking for the lang item
As part of doing so, add more lang items instead of passing u128 to the i128 ones where it doesn't matter in twos-complement.
Handle shifts properly
* The overflow-checking shift items need to take a full 128-bit type, since they need to be able to detect idiocy like `1i128 << (1u128 << 127)`
* The unchecked ones just take u32, like the `*_sh?` methods in core
* Because shift-by-anything is allowed, cast into a new local for every shift
incr.comp.: Make sure we don't lose unused green results from the query cache.
rustbuild: Update LLVM and enable ThinLTO
This commit updates LLVM to fix #45511 (https://reviews.llvm.org/D39981) and
also reenables ThinLTO for libtest now that we shouldn't hit #45768. This also
opportunistically enables ThinLTO for libstd which was previously blocked
(#45661) on test failures related to debuginfo with a presumed cause of #45511.
Closes #45511
std: Flag Windows TLS dtor symbol as #[used]
Turns out ThinLTO was internalizing this symbol and eliminating it. Worse yet if
you compiled with LTO turns out no TLS destructors would run on Windows! The
`#[used]` annotation should be a more bulletproof implementation (in the face of
LTO) of preserving this symbol all the way through in LLVM and ensuring it makes
it all the way to the linker which will take care of it.
Add enum InitializationRequiringAction
Fix tidy tests
2017-11-23 17:06:48 +05:30
|
|
|
|
|
|
|
err.span_label(span, format!("value {} here after move",
|
|
|
|
desired_action.as_verb_in_past_tense()));
|
2017-11-08 18:32:08 +03:00
|
|
|
for moi in mois {
|
|
|
|
let move_msg = ""; //FIXME: add " (into closure)"
|
|
|
|
let move_span = self.mir.source_info(self.move_data.moves[*moi].source).span;
|
|
|
|
if span == move_span {
|
|
|
|
err.span_label(span,
|
|
|
|
format!("value moved{} here in previous iteration of loop",
|
|
|
|
move_msg));
|
|
|
|
} else {
|
|
|
|
err.span_label(move_span, format!("value moved{} here", move_msg));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
//FIXME: add note for closure
|
|
|
|
err.emit();
|
|
|
|
}
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn report_move_out_while_borrowed(&mut self,
|
|
|
|
_context: Context,
|
2017-12-01 14:31:47 +02:00
|
|
|
(lvalue, span): (&Place<'tcx>, Span),
|
2017-11-12 21:49:02 +05:30
|
|
|
borrow: &BorrowData<'tcx>) {
|
2017-11-22 17:35:52 +01:00
|
|
|
let value_msg = match self.describe_lvalue(lvalue) {
|
|
|
|
Some(name) => format!("`{}`", name),
|
|
|
|
None => "value".to_owned()
|
|
|
|
};
|
|
|
|
let borrow_msg = match self.describe_lvalue(&borrow.lvalue) {
|
|
|
|
Some(name) => format!("`{}`", name),
|
|
|
|
None => "value".to_owned()
|
|
|
|
};
|
2017-09-23 11:52:53 -07:00
|
|
|
self.tcx.cannot_move_when_borrowed(span,
|
2017-11-22 17:35:52 +01:00
|
|
|
&self.describe_lvalue(lvalue).unwrap_or("_".to_owned()),
|
2017-09-23 11:52:53 -07:00
|
|
|
Origin::Mir)
|
|
|
|
.span_label(self.retrieve_borrow_span(borrow),
|
2017-11-22 17:35:52 +01:00
|
|
|
format!("borrow of {} occurs here", borrow_msg))
|
|
|
|
.span_label(span, format!("move out of {} occurs here", value_msg))
|
2017-09-23 11:52:53 -07:00
|
|
|
.emit();
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn report_use_while_mutably_borrowed(&mut self,
|
|
|
|
_context: Context,
|
2017-12-01 14:31:47 +02:00
|
|
|
(lvalue, span): (&Place<'tcx>, Span),
|
2017-11-12 21:49:02 +05:30
|
|
|
borrow : &BorrowData<'tcx>) {
|
2017-09-21 16:31:34 +02:00
|
|
|
|
2017-07-05 14:52:18 +02:00
|
|
|
let mut err = self.tcx.cannot_use_when_mutably_borrowed(
|
2017-11-22 17:35:52 +01:00
|
|
|
span,
|
|
|
|
&self.describe_lvalue(lvalue).unwrap_or("_".to_owned()),
|
|
|
|
self.retrieve_borrow_span(borrow),
|
|
|
|
&self.describe_lvalue(&borrow.lvalue).unwrap_or("_".to_owned()),
|
2017-09-28 16:45:09 +02:00
|
|
|
Origin::Mir);
|
2017-09-21 16:31:34 +02:00
|
|
|
|
2017-07-05 14:52:18 +02:00
|
|
|
err.emit();
|
|
|
|
}
|
|
|
|
|
2017-11-13 12:21:05 +09:00
|
|
|
/// Finds the span of arguments of a closure (within `maybe_closure_span`) and its usage of
|
2017-11-11 18:15:26 +09:00
|
|
|
/// the local assigned at `location`.
|
2017-11-13 12:21:05 +09:00
|
|
|
/// This is done by searching in statements succeeding `location`
|
|
|
|
/// and originating from `maybe_closure_span`.
|
2017-11-11 18:15:26 +09:00
|
|
|
fn find_closure_span(
|
|
|
|
&self,
|
|
|
|
maybe_closure_span: Span,
|
|
|
|
location: Location,
|
|
|
|
) -> Option<(Span, Span)> {
|
|
|
|
use rustc::hir::ExprClosure;
|
|
|
|
use rustc::mir::AggregateKind;
|
|
|
|
|
2017-12-01 14:31:47 +02:00
|
|
|
let local = if let StatementKind::Assign(Place::Local(local), _) =
|
2017-11-11 18:15:26 +09:00
|
|
|
self.mir[location.block].statements[location.statement_index].kind
|
|
|
|
{
|
|
|
|
local
|
|
|
|
} else {
|
|
|
|
return None;
|
|
|
|
};
|
|
|
|
|
|
|
|
for stmt in &self.mir[location.block].statements[location.statement_index + 1..] {
|
|
|
|
if maybe_closure_span != stmt.source_info.span {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if let StatementKind::Assign(_, Rvalue::Aggregate(ref kind, ref lvs)) = stmt.kind {
|
|
|
|
if let AggregateKind::Closure(def_id, _) = **kind {
|
|
|
|
debug!("find_closure_span: found closure {:?}", lvs);
|
|
|
|
|
|
|
|
return if let Some(node_id) = self.tcx.hir.as_local_node_id(def_id) {
|
|
|
|
let args_span = if let ExprClosure(_, _, _, span, _) =
|
|
|
|
self.tcx.hir.expect_expr(node_id).node
|
|
|
|
{
|
|
|
|
span
|
|
|
|
} else {
|
|
|
|
return None;
|
|
|
|
};
|
|
|
|
|
2017-11-17 17:19:57 +02:00
|
|
|
self.tcx.with_freevars(node_id, |freevars| {
|
|
|
|
for (v, lv) in freevars.iter().zip(lvs) {
|
|
|
|
match *lv {
|
2017-12-01 14:31:47 +02:00
|
|
|
Operand::Copy(Place::Local(l)) |
|
|
|
|
Operand::Move(Place::Local(l)) if local == l => {
|
2017-11-17 17:19:57 +02:00
|
|
|
debug!(
|
|
|
|
"find_closure_span: found captured local {:?}",
|
|
|
|
l
|
|
|
|
);
|
|
|
|
return Some(v.span);
|
2017-11-11 18:15:26 +09:00
|
|
|
}
|
2017-11-17 17:19:57 +02:00
|
|
|
_ => {}
|
2017-11-11 18:15:26 +09:00
|
|
|
}
|
2017-11-17 17:19:57 +02:00
|
|
|
}
|
|
|
|
None
|
|
|
|
}).map(|var_span| (args_span, var_span))
|
2017-11-11 18:15:26 +09:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
2017-07-05 14:52:18 +02:00
|
|
|
fn report_conflicting_borrow(&mut self,
|
2017-11-11 18:15:26 +09:00
|
|
|
context: Context,
|
2017-12-01 14:31:47 +02:00
|
|
|
common_prefix: &Place<'tcx>,
|
|
|
|
(lvalue, span): (&Place<'tcx>, Span),
|
2017-09-27 10:01:42 +03:00
|
|
|
gen_borrow_kind: BorrowKind,
|
|
|
|
issued_borrow: &BorrowData,
|
2017-10-25 14:17:17 -04:00
|
|
|
end_issued_loan_span: Option<Span>) {
|
2017-10-03 14:00:38 +02:00
|
|
|
use self::prefixes::IsPrefixOf;
|
|
|
|
|
2017-09-27 10:01:42 +03:00
|
|
|
assert!(common_prefix.is_prefix_of(lvalue));
|
|
|
|
assert!(common_prefix.is_prefix_of(&issued_borrow.lvalue));
|
2017-10-03 14:00:38 +02:00
|
|
|
|
2017-09-27 10:01:42 +03:00
|
|
|
let issued_span = self.retrieve_borrow_span(issued_borrow);
|
2017-07-05 14:52:18 +02:00
|
|
|
|
2017-11-11 18:15:26 +09:00
|
|
|
let new_closure_span = self.find_closure_span(span, context.loc);
|
|
|
|
let span = new_closure_span.map(|(args, _)| args).unwrap_or(span);
|
|
|
|
let old_closure_span = self.find_closure_span(issued_span, issued_borrow.location);
|
|
|
|
let issued_span = old_closure_span.map(|(args, _)| args).unwrap_or(issued_span);
|
|
|
|
|
2017-11-22 17:35:52 +01:00
|
|
|
let desc_lvalue = self.describe_lvalue(lvalue).unwrap_or("_".to_owned());
|
2017-11-11 18:15:26 +09:00
|
|
|
|
2017-07-05 14:52:18 +02:00
|
|
|
// FIXME: supply non-"" `opt_via` when appropriate
|
2017-09-27 10:01:42 +03:00
|
|
|
let mut err = match (gen_borrow_kind, "immutable", "mutable",
|
|
|
|
issued_borrow.kind, "immutable", "mutable") {
|
2017-07-05 14:52:18 +02:00
|
|
|
(BorrowKind::Shared, lft, _, BorrowKind::Mut, _, rgt) |
|
2017-08-22 11:23:17 +02:00
|
|
|
(BorrowKind::Mut, _, lft, BorrowKind::Shared, rgt, _) =>
|
2017-07-05 14:52:18 +02:00
|
|
|
self.tcx.cannot_reborrow_already_borrowed(
|
2017-11-11 18:15:26 +09:00
|
|
|
span, &desc_lvalue, "", lft, issued_span,
|
2017-09-27 10:01:42 +03:00
|
|
|
"it", rgt, "", end_issued_loan_span, Origin::Mir),
|
2017-07-05 14:52:18 +02:00
|
|
|
|
2017-08-22 11:23:17 +02:00
|
|
|
(BorrowKind::Mut, _, _, BorrowKind::Mut, _, _) =>
|
|
|
|
self.tcx.cannot_mutably_borrow_multiply(
|
2017-11-11 18:15:26 +09:00
|
|
|
span, &desc_lvalue, "", issued_span,
|
2017-09-27 10:01:42 +03:00
|
|
|
"", end_issued_loan_span, Origin::Mir),
|
2017-08-22 11:23:17 +02:00
|
|
|
|
|
|
|
(BorrowKind::Unique, _, _, BorrowKind::Unique, _, _) =>
|
|
|
|
self.tcx.cannot_uniquely_borrow_by_two_closures(
|
2017-11-11 18:15:26 +09:00
|
|
|
span, &desc_lvalue, issued_span,
|
2017-09-27 10:01:42 +03:00
|
|
|
end_issued_loan_span, Origin::Mir),
|
2017-08-22 11:23:17 +02:00
|
|
|
|
|
|
|
(BorrowKind::Unique, _, _, _, _, _) =>
|
|
|
|
self.tcx.cannot_uniquely_borrow_by_one_closure(
|
2017-11-11 18:15:26 +09:00
|
|
|
span, &desc_lvalue, "",
|
2017-09-27 10:01:42 +03:00
|
|
|
issued_span, "it", "", end_issued_loan_span, Origin::Mir),
|
2017-08-22 11:23:17 +02:00
|
|
|
|
|
|
|
(_, _, _, BorrowKind::Unique, _, _) =>
|
|
|
|
self.tcx.cannot_reborrow_already_uniquely_borrowed(
|
2017-11-11 18:15:26 +09:00
|
|
|
span, &desc_lvalue, "it", "",
|
2017-09-27 10:01:42 +03:00
|
|
|
issued_span, "", end_issued_loan_span, Origin::Mir),
|
2017-08-22 11:23:17 +02:00
|
|
|
|
|
|
|
(BorrowKind::Shared, _, _, BorrowKind::Shared, _, _) =>
|
|
|
|
unreachable!(),
|
2017-07-05 14:52:18 +02:00
|
|
|
};
|
2017-11-11 18:15:26 +09:00
|
|
|
|
|
|
|
if let Some((_, var_span)) = old_closure_span {
|
|
|
|
err.span_label(
|
|
|
|
var_span,
|
|
|
|
format!("previous borrow occurs due to use of `{}` in closure", desc_lvalue),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some((_, var_span)) = new_closure_span {
|
|
|
|
err.span_label(
|
|
|
|
var_span,
|
|
|
|
format!("borrow occurs due to use of `{}` in closure", desc_lvalue),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-07-05 14:52:18 +02:00
|
|
|
err.emit();
|
|
|
|
}
|
|
|
|
|
2017-11-17 00:09:18 +00:00
|
|
|
fn report_borrowed_value_does_not_live_long_enough(&mut self,
|
|
|
|
_: Context,
|
2017-12-01 14:31:47 +02:00
|
|
|
(lvalue, span): (&Place, Span),
|
2017-11-17 00:09:18 +00:00
|
|
|
end_span: Option<Span>) {
|
|
|
|
let proper_span = match *lvalue {
|
2017-12-01 14:31:47 +02:00
|
|
|
Place::Local(local) => self.mir.local_decls[local].source_info.span,
|
2017-11-17 00:09:18 +00:00
|
|
|
_ => span
|
|
|
|
};
|
|
|
|
|
2017-11-17 16:20:34 +00:00
|
|
|
let mut err = self.tcx.path_does_not_live_long_enough(span, "borrowed value", Origin::Mir);
|
2017-11-17 00:09:18 +00:00
|
|
|
err.span_label(proper_span, "temporary value created here");
|
|
|
|
err.span_label(span, "temporary value dropped here while still borrowed");
|
|
|
|
err.note("consider using a `let` binding to increase its lifetime");
|
|
|
|
|
|
|
|
if let Some(end) = end_span {
|
|
|
|
err.span_label(end, "temporary value needs to live until here");
|
|
|
|
}
|
|
|
|
|
|
|
|
err.emit();
|
|
|
|
}
|
|
|
|
|
2017-09-24 15:25:49 +02:00
|
|
|
fn report_illegal_mutation_of_borrowed(&mut self,
|
|
|
|
_: Context,
|
2017-12-01 14:31:47 +02:00
|
|
|
(lvalue, span): (&Place<'tcx>, Span),
|
2017-09-24 15:25:49 +02:00
|
|
|
loan: &BorrowData) {
|
2017-07-05 14:52:18 +02:00
|
|
|
let mut err = self.tcx.cannot_assign_to_borrowed(
|
2017-11-22 17:35:52 +01:00
|
|
|
span,
|
|
|
|
self.retrieve_borrow_span(loan),
|
|
|
|
&self.describe_lvalue(lvalue).unwrap_or("_".to_owned()),
|
|
|
|
Origin::Mir);
|
2017-09-24 15:37:41 +02:00
|
|
|
|
2017-07-05 14:52:18 +02:00
|
|
|
err.emit();
|
|
|
|
}
|
|
|
|
|
2017-09-24 03:56:57 -07:00
|
|
|
fn report_illegal_reassignment(&mut self,
|
|
|
|
_context: Context,
|
2017-12-01 14:31:47 +02:00
|
|
|
(lvalue, span): (&Place<'tcx>, Span),
|
2017-09-24 03:56:57 -07:00
|
|
|
assigned_span: Span) {
|
2017-11-27 08:07:49 +00:00
|
|
|
let mut err = self.tcx.cannot_reassign_immutable(span,
|
2017-11-22 17:35:52 +01:00
|
|
|
&self.describe_lvalue(lvalue).unwrap_or("_".to_owned()),
|
2017-11-27 08:07:49 +00:00
|
|
|
Origin::Mir);
|
|
|
|
err.span_label(span, "cannot assign twice to immutable variable");
|
|
|
|
if span != assigned_span {
|
2017-11-22 17:35:52 +01:00
|
|
|
let value_msg = match self.describe_lvalue(lvalue) {
|
|
|
|
Some(name) => format!("`{}`", name),
|
|
|
|
None => "value".to_owned()
|
|
|
|
};
|
|
|
|
err.span_label(assigned_span, format!("first assignment to {}", value_msg));
|
2017-11-27 08:07:49 +00:00
|
|
|
}
|
|
|
|
err.emit();
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-07 04:44:41 -05:00
|
|
|
impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
2017-11-22 17:35:52 +01:00
|
|
|
// End-user visible description of `lvalue` if one can be found. If the
|
|
|
|
// lvalue is a temporary for instance, None will be returned.
|
2017-12-01 14:31:47 +02:00
|
|
|
fn describe_lvalue(&self, lvalue: &Place<'tcx>) -> Option<String> {
|
2017-07-05 14:52:18 +02:00
|
|
|
let mut buf = String::new();
|
2017-11-22 17:35:52 +01:00
|
|
|
match self.append_lvalue_to_string(lvalue, &mut buf, false) {
|
|
|
|
Ok(()) => Some(buf),
|
|
|
|
Err(()) => None
|
|
|
|
}
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
|
2017-11-19 04:02:05 +05:30
|
|
|
/// If this is a field projection, and the field is being projected from a closure type,
|
|
|
|
/// then returns the index of the field being projected. Note that this closure will always
|
|
|
|
/// be `self` in the current MIR, because that is the only time we directly access the fields
|
|
|
|
/// of a closure type.
|
2017-12-01 14:31:47 +02:00
|
|
|
fn is_upvar_field_projection(&self, lvalue: &Place<'tcx>) -> Option<Field> {
|
2017-11-19 04:02:05 +05:30
|
|
|
match *lvalue {
|
2017-12-01 14:31:47 +02:00
|
|
|
Place::Projection(ref proj) => {
|
2017-11-19 04:02:05 +05:30
|
|
|
match proj.elem {
|
|
|
|
ProjectionElem::Field(field, _ty) => {
|
|
|
|
let is_projection_from_ty_closure = proj.base.ty(self.mir, self.tcx)
|
|
|
|
.to_ty(self.tcx).is_closure();
|
|
|
|
|
|
|
|
if is_projection_from_ty_closure {
|
|
|
|
Some(field)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_ => None
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_ => None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-05 14:52:18 +02:00
|
|
|
// Appends end-user visible description of `lvalue` to `buf`.
|
2017-11-12 21:49:02 +05:30
|
|
|
fn append_lvalue_to_string(&self,
|
2017-12-01 14:31:47 +02:00
|
|
|
lvalue: &Place<'tcx>,
|
2017-11-12 21:49:02 +05:30
|
|
|
buf: &mut String,
|
2017-11-22 17:35:52 +01:00
|
|
|
mut autoderef: bool) -> Result<(), ()> {
|
2017-07-05 14:52:18 +02:00
|
|
|
match *lvalue {
|
2017-12-01 14:31:47 +02:00
|
|
|
Place::Local(local) => {
|
2017-11-22 17:35:52 +01:00
|
|
|
self.append_local_to_string(local, buf,)?;
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
2017-12-01 14:31:47 +02:00
|
|
|
Place::Static(ref static_) => {
|
2017-07-05 14:52:18 +02:00
|
|
|
buf.push_str(&format!("{}", &self.tcx.item_name(static_.def_id)));
|
|
|
|
}
|
2017-12-01 14:31:47 +02:00
|
|
|
Place::Projection(ref proj) => {
|
2017-11-12 21:49:02 +05:30
|
|
|
match proj.elem {
|
2017-10-02 19:36:58 +02:00
|
|
|
ProjectionElem::Deref => {
|
2017-11-19 04:02:05 +05:30
|
|
|
if let Some(field) = self.is_upvar_field_projection(&proj.base) {
|
|
|
|
let var_index = field.index();
|
|
|
|
let name = self.mir.upvar_decls[var_index].debug_name.to_string();
|
|
|
|
if self.mir.upvar_decls[var_index].by_ref {
|
|
|
|
buf.push_str(&name);
|
|
|
|
} else {
|
|
|
|
buf.push_str(&format!("*{}", &name));
|
|
|
|
}
|
2017-10-02 19:36:58 +02:00
|
|
|
} else {
|
2017-11-19 04:02:05 +05:30
|
|
|
if autoderef {
|
2017-11-22 17:35:52 +01:00
|
|
|
self.append_lvalue_to_string(&proj.base, buf, autoderef)?;
|
2017-11-19 04:02:05 +05:30
|
|
|
} else {
|
|
|
|
buf.push_str(&"*");
|
2017-11-22 17:35:52 +01:00
|
|
|
self.append_lvalue_to_string(&proj.base, buf, autoderef)?;
|
2017-11-19 04:02:05 +05:30
|
|
|
}
|
2017-10-02 19:36:58 +02:00
|
|
|
}
|
|
|
|
},
|
2017-11-12 21:49:02 +05:30
|
|
|
ProjectionElem::Downcast(..) => {
|
2017-11-22 17:35:52 +01:00
|
|
|
self.append_lvalue_to_string(&proj.base, buf, autoderef)?;
|
2017-11-12 21:49:02 +05:30
|
|
|
},
|
2017-10-02 19:36:58 +02:00
|
|
|
ProjectionElem::Field(field, _ty) => {
|
|
|
|
autoderef = true;
|
2017-11-12 21:49:02 +05:30
|
|
|
|
2017-11-19 04:02:05 +05:30
|
|
|
if let Some(field) = self.is_upvar_field_projection(lvalue) {
|
|
|
|
let var_index = field.index();
|
|
|
|
let name = self.mir.upvar_decls[var_index].debug_name.to_string();
|
|
|
|
buf.push_str(&name);
|
2017-11-12 21:49:02 +05:30
|
|
|
} else {
|
2017-11-19 04:02:05 +05:30
|
|
|
let field_name = self.describe_field(&proj.base, field);
|
2017-11-22 17:35:52 +01:00
|
|
|
self.append_lvalue_to_string(&proj.base, buf, autoderef)?;
|
2017-11-12 21:49:02 +05:30
|
|
|
buf.push_str(&format!(".{}", field_name));
|
|
|
|
}
|
2017-10-02 19:36:58 +02:00
|
|
|
},
|
|
|
|
ProjectionElem::Index(index) => {
|
|
|
|
autoderef = true;
|
2017-11-12 21:49:02 +05:30
|
|
|
|
2017-11-22 17:35:52 +01:00
|
|
|
self.append_lvalue_to_string(&proj.base, buf, autoderef)?;
|
2017-11-12 21:49:02 +05:30
|
|
|
buf.push_str("[");
|
2017-11-22 17:35:52 +01:00
|
|
|
if let Err(_) = self.append_local_to_string(index, buf) {
|
|
|
|
buf.push_str("..");
|
|
|
|
}
|
2017-11-12 21:49:02 +05:30
|
|
|
buf.push_str("]");
|
2017-10-02 19:36:58 +02:00
|
|
|
},
|
2017-10-06 17:21:06 +02:00
|
|
|
ProjectionElem::ConstantIndex { .. } | ProjectionElem::Subslice { .. } => {
|
mir-borrowck: Autoderef values followed by a constant index, and fix reported lvalue for constant index
Previously the constant index was reported as `[x of y]` or `[-x of y]` where
`x` was the offset and `y` the minimum length of the slice. The minus sign
wasn't in the right case since for `&[_, x, .., _, _]`, the error reported was
`[-1 of 4]`, and for `&[_, _, .., x, _]`, the error reported was `[2 of 4]`.
This commit fixes the sign so that the indexes 1 and -2 are reported, and
remove the ` of y` part of the message to make it more succinct.
2017-10-05 11:03:32 +02:00
|
|
|
autoderef = true;
|
2017-10-06 17:21:06 +02:00
|
|
|
// Since it isn't possible to borrow an element on a particular index and
|
|
|
|
// then use another while the borrow is held, don't output indices details
|
|
|
|
// to avoid confusing the end-user
|
2017-11-22 17:35:52 +01:00
|
|
|
self.append_lvalue_to_string(&proj.base, buf, autoderef)?;
|
2017-11-12 21:49:02 +05:30
|
|
|
buf.push_str(&"[..]");
|
mir-borrowck: Autoderef values followed by a constant index, and fix reported lvalue for constant index
Previously the constant index was reported as `[x of y]` or `[-x of y]` where
`x` was the offset and `y` the minimum length of the slice. The minus sign
wasn't in the right case since for `&[_, x, .., _, _]`, the error reported was
`[-1 of 4]`, and for `&[_, _, .., x, _]`, the error reported was `[2 of 4]`.
This commit fixes the sign so that the indexes 1 and -2 are reported, and
remove the ` of y` part of the message to make it more succinct.
2017-10-05 11:03:32 +02:00
|
|
|
},
|
2017-07-05 14:52:18 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2017-11-22 17:35:52 +01:00
|
|
|
|
|
|
|
Ok(())
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
2017-09-21 16:13:03 +02:00
|
|
|
|
2017-10-06 17:29:14 +02:00
|
|
|
// Appends end-user visible description of the `local` lvalue to `buf`. If `local` doesn't have
|
2017-11-22 17:35:52 +01:00
|
|
|
// a name, then `Err` is returned
|
|
|
|
fn append_local_to_string(&self, local_index: Local, buf: &mut String) -> Result<(), ()> {
|
2017-10-06 17:29:14 +02:00
|
|
|
let local = &self.mir.local_decls[local_index];
|
|
|
|
match local.name {
|
2017-11-22 17:35:52 +01:00
|
|
|
Some(name) => {
|
|
|
|
buf.push_str(&format!("{}", name));
|
|
|
|
Ok(())
|
|
|
|
},
|
|
|
|
None => Err(())
|
2017-10-06 17:29:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-16 17:07:33 +01:00
|
|
|
// End-user visible description of the `field`nth field of `base`
|
2017-12-01 14:31:47 +02:00
|
|
|
fn describe_field(&self, base: &Place, field: Field) -> String {
|
2017-10-02 19:36:58 +02:00
|
|
|
match *base {
|
2017-12-01 14:31:47 +02:00
|
|
|
Place::Local(local) => {
|
2017-10-02 19:36:58 +02:00
|
|
|
let local = &self.mir.local_decls[local];
|
2017-11-16 17:07:33 +01:00
|
|
|
self.describe_field_from_ty(&local.ty, field)
|
2017-10-02 19:36:58 +02:00
|
|
|
},
|
2017-12-01 14:31:47 +02:00
|
|
|
Place::Static(ref static_) => {
|
2017-11-16 17:07:33 +01:00
|
|
|
self.describe_field_from_ty(&static_.ty, field)
|
2017-10-02 19:36:58 +02:00
|
|
|
},
|
2017-12-01 14:31:47 +02:00
|
|
|
Place::Projection(ref proj) => {
|
2017-10-02 19:36:58 +02:00
|
|
|
match proj.elem {
|
|
|
|
ProjectionElem::Deref =>
|
2017-11-16 17:07:33 +01:00
|
|
|
self.describe_field(&proj.base, field),
|
2017-10-06 17:24:23 +02:00
|
|
|
ProjectionElem::Downcast(def, variant_index) =>
|
2017-11-16 17:07:33 +01:00
|
|
|
format!("{}", def.variants[variant_index].fields[field.index()].name),
|
2017-10-06 17:25:41 +02:00
|
|
|
ProjectionElem::Field(_, field_type) =>
|
2017-11-16 17:07:33 +01:00
|
|
|
self.describe_field_from_ty(&field_type, field),
|
2017-10-06 18:23:53 +02:00
|
|
|
ProjectionElem::Index(..)
|
|
|
|
| ProjectionElem::ConstantIndex { .. }
|
|
|
|
| ProjectionElem::Subslice { .. } =>
|
2017-11-16 17:07:33 +01:00
|
|
|
format!("{}", self.describe_field(&proj.base, field)),
|
2017-10-02 19:36:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// End-user visible description of the `field_index`nth field of `ty`
|
2017-11-16 17:07:33 +01:00
|
|
|
fn describe_field_from_ty(&self, ty: &ty::Ty, field: Field) -> String {
|
2017-10-02 19:36:58 +02:00
|
|
|
if ty.is_box() {
|
|
|
|
// If the type is a box, the field is described from the boxed type
|
2017-11-16 17:07:33 +01:00
|
|
|
self.describe_field_from_ty(&ty.boxed_ty(), field)
|
2017-10-02 19:36:58 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
match ty.sty {
|
|
|
|
ty::TyAdt(def, _) => {
|
|
|
|
if def.is_enum() {
|
2017-11-16 17:07:33 +01:00
|
|
|
format!("{}", field.index())
|
2017-10-02 19:36:58 +02:00
|
|
|
}
|
|
|
|
else {
|
2017-11-16 17:07:33 +01:00
|
|
|
format!("{}", def.struct_variant().fields[field.index()].name)
|
2017-10-02 19:36:58 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
ty::TyTuple(_, _) => {
|
2017-11-16 17:07:33 +01:00
|
|
|
format!("{}", field.index())
|
2017-10-02 19:36:58 +02:00
|
|
|
},
|
2017-10-06 17:26:53 +02:00
|
|
|
ty::TyRef(_, tnm) | ty::TyRawPtr(tnm) => {
|
2017-11-16 17:07:33 +01:00
|
|
|
self.describe_field_from_ty(&tnm.ty, field)
|
2017-10-06 17:26:53 +02:00
|
|
|
},
|
2017-10-06 18:23:53 +02:00
|
|
|
ty::TyArray(ty, _) | ty::TySlice(ty) => {
|
2017-11-16 17:07:33 +01:00
|
|
|
self.describe_field_from_ty(&ty, field)
|
2017-11-12 04:38:40 +05:30
|
|
|
},
|
|
|
|
ty::TyClosure(closure_def_id, _) => {
|
|
|
|
// Convert the def-id into a node-id. node-ids are only valid for
|
|
|
|
// the local code in the current crate, so this returns an `Option` in case
|
|
|
|
// the closure comes from another crate. But in that case we wouldn't
|
|
|
|
// be borrowck'ing it, so we can just unwrap:
|
|
|
|
let node_id = self.tcx.hir.as_local_node_id(closure_def_id).unwrap();
|
2017-11-16 17:07:33 +01:00
|
|
|
let freevar = self.tcx.with_freevars(node_id, |fv| fv[field.index()]);
|
2017-11-12 04:38:40 +05:30
|
|
|
|
2017-11-12 21:49:02 +05:30
|
|
|
self.tcx.hir.name(freevar.var_id()).to_string()
|
2017-11-12 04:38:40 +05:30
|
|
|
}
|
2017-10-02 19:36:58 +02:00
|
|
|
_ => {
|
2017-10-04 18:02:36 +02:00
|
|
|
// Might need a revision when the fields in trait RFC is implemented
|
|
|
|
// (https://github.com/rust-lang/rfcs/pull/1546)
|
2017-10-06 17:26:53 +02:00
|
|
|
bug!("End-user description not implemented for field access on `{:?}`", ty.sty);
|
2017-10-02 19:36:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-21 16:13:03 +02:00
|
|
|
// Retrieve span of given borrow from the current MIR representation
|
|
|
|
fn retrieve_borrow_span(&self, borrow: &BorrowData) -> Span {
|
2017-10-04 11:46:35 +02:00
|
|
|
self.mir.source_info(borrow.location).span
|
2017-09-21 16:13:03 +02:00
|
|
|
}
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
|
2017-11-07 04:44:41 -05:00
|
|
|
impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
|
2017-07-05 14:52:18 +02:00
|
|
|
// FIXME (#16118): function intended to allow the borrow checker
|
|
|
|
// to be less precise in its handling of Box while still allowing
|
|
|
|
// moves out of a Box. They should be removed when/if we stop
|
|
|
|
// treating Box specially (e.g. when/if DerefMove is added...)
|
|
|
|
|
2017-12-01 14:31:47 +02:00
|
|
|
fn base_path<'d>(&self, lvalue: &'d Place<'tcx>) -> &'d Place<'tcx> {
|
2017-07-05 14:52:18 +02:00
|
|
|
//! Returns the base of the leftmost (deepest) dereference of an
|
|
|
|
//! Box in `lvalue`. If there is no dereference of an Box
|
|
|
|
//! in `lvalue`, then it just returns `lvalue` itself.
|
|
|
|
|
|
|
|
let mut cursor = lvalue;
|
|
|
|
let mut deepest = lvalue;
|
|
|
|
loop {
|
|
|
|
let proj = match *cursor {
|
2017-12-01 14:31:47 +02:00
|
|
|
Place::Local(..) | Place::Static(..) => return deepest,
|
|
|
|
Place::Projection(ref proj) => proj,
|
2017-07-05 14:52:18 +02:00
|
|
|
};
|
|
|
|
if proj.elem == ProjectionElem::Deref &&
|
|
|
|
lvalue.ty(self.mir, self.tcx).to_ty(self.tcx).is_box()
|
|
|
|
{
|
|
|
|
deepest = &proj.base;
|
|
|
|
}
|
|
|
|
cursor = &proj.base;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
|
|
|
struct Context {
|
|
|
|
kind: ContextKind,
|
|
|
|
loc: Location,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
|
|
|
enum ContextKind {
|
|
|
|
AssignLhs,
|
|
|
|
AssignRhs,
|
|
|
|
SetDiscrim,
|
|
|
|
InlineAsm,
|
|
|
|
SwitchInt,
|
|
|
|
Drop,
|
|
|
|
DropAndReplace,
|
|
|
|
CallOperator,
|
|
|
|
CallOperand,
|
|
|
|
CallDest,
|
|
|
|
Assert,
|
2017-08-16 13:05:48 -07:00
|
|
|
Yield,
|
2017-08-21 12:48:33 +02:00
|
|
|
StorageDead,
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ContextKind {
|
|
|
|
fn new(self, loc: Location) -> Context { Context { kind: self, loc: loc } }
|
|
|
|
}
|
|
|
|
|
2017-10-30 05:50:39 -04:00
|
|
|
impl<'b, 'gcx, 'tcx> InProgress<'b, 'gcx, 'tcx> {
|
|
|
|
pub(super) fn new(borrows: DataflowResults<Borrows<'b, 'gcx, 'tcx>>,
|
|
|
|
inits: DataflowResults<MaybeInitializedLvals<'b, 'gcx, 'tcx>>,
|
2017-11-08 18:32:08 +03:00
|
|
|
uninits: DataflowResults<MaybeUninitializedLvals<'b, 'gcx, 'tcx>>,
|
2017-11-27 08:06:36 +00:00
|
|
|
move_out: DataflowResults<MovingOutStatements<'b, 'gcx, 'tcx>>,
|
|
|
|
ever_inits: DataflowResults<EverInitializedLvals<'b, 'gcx, 'tcx>>)
|
2017-08-19 03:09:55 +03:00
|
|
|
-> Self {
|
2017-07-05 14:52:18 +02:00
|
|
|
InProgress {
|
|
|
|
borrows: FlowInProgress::new(borrows),
|
|
|
|
inits: FlowInProgress::new(inits),
|
|
|
|
uninits: FlowInProgress::new(uninits),
|
2017-11-27 08:06:36 +00:00
|
|
|
move_outs: FlowInProgress::new(move_out),
|
|
|
|
ever_inits: FlowInProgress::new(ever_inits)
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-27 08:06:36 +00:00
|
|
|
fn each_flow<XB, XI, XU, XM, XE>(&mut self,
|
2017-11-08 18:32:08 +03:00
|
|
|
mut xform_borrows: XB,
|
|
|
|
mut xform_inits: XI,
|
|
|
|
mut xform_uninits: XU,
|
2017-11-27 08:06:36 +00:00
|
|
|
mut xform_move_outs: XM,
|
|
|
|
mut xform_ever_inits: XE) where
|
2017-10-30 05:50:39 -04:00
|
|
|
XB: FnMut(&mut FlowInProgress<Borrows<'b, 'gcx, 'tcx>>),
|
|
|
|
XI: FnMut(&mut FlowInProgress<MaybeInitializedLvals<'b, 'gcx, 'tcx>>),
|
|
|
|
XU: FnMut(&mut FlowInProgress<MaybeUninitializedLvals<'b, 'gcx, 'tcx>>),
|
2017-11-08 18:32:08 +03:00
|
|
|
XM: FnMut(&mut FlowInProgress<MovingOutStatements<'b, 'gcx, 'tcx>>),
|
2017-11-27 08:06:36 +00:00
|
|
|
XE: FnMut(&mut FlowInProgress<EverInitializedLvals<'b, 'gcx, 'tcx>>),
|
2017-07-05 14:52:18 +02:00
|
|
|
{
|
|
|
|
xform_borrows(&mut self.borrows);
|
|
|
|
xform_inits(&mut self.inits);
|
|
|
|
xform_uninits(&mut self.uninits);
|
2017-11-08 18:32:08 +03:00
|
|
|
xform_move_outs(&mut self.move_outs);
|
2017-11-27 08:06:36 +00:00
|
|
|
xform_ever_inits(&mut self.ever_inits);
|
2017-07-05 14:52:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn summary(&self) -> String {
|
|
|
|
let mut s = String::new();
|
|
|
|
|
|
|
|
s.push_str("borrows in effect: [");
|
|
|
|
let mut saw_one = false;
|
|
|
|
self.borrows.each_state_bit(|borrow| {
|
|
|
|
if saw_one { s.push_str(", "); };
|
|
|
|
saw_one = true;
|
|
|
|
let borrow_data = &self.borrows.base_results.operator().borrows()[borrow];
|
|
|
|
s.push_str(&format!("{}", borrow_data));
|
|
|
|
});
|
|
|
|
s.push_str("] ");
|
|
|
|
|
|
|
|
s.push_str("borrows generated: [");
|
|
|
|
let mut saw_one = false;
|
|
|
|
self.borrows.each_gen_bit(|borrow| {
|
|
|
|
if saw_one { s.push_str(", "); };
|
|
|
|
saw_one = true;
|
|
|
|
let borrow_data = &self.borrows.base_results.operator().borrows()[borrow];
|
|
|
|
s.push_str(&format!("{}", borrow_data));
|
|
|
|
});
|
|
|
|
s.push_str("] ");
|
|
|
|
|
|
|
|
s.push_str("inits: [");
|
|
|
|
let mut saw_one = false;
|
|
|
|
self.inits.each_state_bit(|mpi_init| {
|
|
|
|
if saw_one { s.push_str(", "); };
|
|
|
|
saw_one = true;
|
|
|
|
let move_path =
|
|
|
|
&self.inits.base_results.operator().move_data().move_paths[mpi_init];
|
|
|
|
s.push_str(&format!("{}", move_path));
|
|
|
|
});
|
|
|
|
s.push_str("] ");
|
|
|
|
|
|
|
|
s.push_str("uninits: [");
|
|
|
|
let mut saw_one = false;
|
|
|
|
self.uninits.each_state_bit(|mpi_uninit| {
|
|
|
|
if saw_one { s.push_str(", "); };
|
|
|
|
saw_one = true;
|
|
|
|
let move_path =
|
|
|
|
&self.uninits.base_results.operator().move_data().move_paths[mpi_uninit];
|
|
|
|
s.push_str(&format!("{}", move_path));
|
|
|
|
});
|
2017-11-08 18:32:08 +03:00
|
|
|
s.push_str("] ");
|
|
|
|
|
|
|
|
s.push_str("move_out: [");
|
|
|
|
let mut saw_one = false;
|
|
|
|
self.move_outs.each_state_bit(|mpi_move_out| {
|
|
|
|
if saw_one { s.push_str(", "); };
|
|
|
|
saw_one = true;
|
|
|
|
let move_out =
|
|
|
|
&self.move_outs.base_results.operator().move_data().moves[mpi_move_out];
|
|
|
|
s.push_str(&format!("{:?}", move_out));
|
|
|
|
});
|
2017-11-27 08:06:36 +00:00
|
|
|
s.push_str("] ");
|
|
|
|
|
|
|
|
s.push_str("ever_init: [");
|
|
|
|
let mut saw_one = false;
|
|
|
|
self.ever_inits.each_state_bit(|mpi_ever_init| {
|
|
|
|
if saw_one { s.push_str(", "); };
|
|
|
|
saw_one = true;
|
|
|
|
let ever_init =
|
|
|
|
&self.ever_inits.base_results.operator().move_data().inits[mpi_ever_init];
|
|
|
|
s.push_str(&format!("{:?}", ever_init));
|
|
|
|
});
|
2017-07-05 14:52:18 +02:00
|
|
|
s.push_str("]");
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-30 05:50:39 -04:00
|
|
|
impl<'b, 'gcx, 'tcx> FlowInProgress<MaybeUninitializedLvals<'b, 'gcx, 'tcx>> {
|
MIR-borrowck: Big fix to `fn check_if_path_is_moved`.
Fix #44833 (a very specific instance of a very broad bug).
In `check_if_path_is_moved(L)`, check nearest prefix of L with
MovePath, and suffixes of L with MovePaths.
Over the course of review, ariel pointed out a number of issues that
led to this version of the commit:
1. Looking solely at supporting prefixes does not suffice: it
overlooks checking if the path was ever actually initialized in the
first place. So you need to be willing to consider non-supporting
prefixes. Once you are looking at all prefixes, you *could* just
look at the local that forms the base of the projection, but to
handle partial initialization (which still needs to be formally
specified), this code instead looks at the nearest prefix of L that
has an associated MovePath (which, in the limit, will end up being
a local).
2. You also need to consider the suffixes of the given Lvalue, due to
how dataflow is representing partial moves of individual fields out
of struct values.
3. (There was originally a third search, but ariel pointed out that
the first and third could be folded into one.)
Also includes some drive-by refactorings to simplify some method
signatures and prefer `for _ in _` over `loop { }` (at least when it
comes semi-naturally).
2017-10-04 17:46:46 +02:00
|
|
|
fn has_any_child_of(&self, mpi: MovePathIndex) -> Option<MovePathIndex> {
|
|
|
|
let move_data = self.base_results.operator().move_data();
|
|
|
|
|
|
|
|
let mut todo = vec![mpi];
|
|
|
|
let mut push_siblings = false; // don't look at siblings of original `mpi`.
|
|
|
|
while let Some(mpi) = todo.pop() {
|
|
|
|
if self.curr_state.contains(&mpi) {
|
|
|
|
return Some(mpi);
|
|
|
|
}
|
|
|
|
let move_path = &move_data.move_paths[mpi];
|
|
|
|
if let Some(child) = move_path.first_child {
|
|
|
|
todo.push(child);
|
|
|
|
}
|
|
|
|
if push_siblings {
|
|
|
|
if let Some(sibling) = move_path.next_sibling {
|
|
|
|
todo.push(sibling);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// after we've processed the original `mpi`, we should
|
|
|
|
// always traverse the siblings of any of its
|
|
|
|
// children.
|
|
|
|
push_siblings = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-05 14:52:18 +02:00
|
|
|
impl<BD> FlowInProgress<BD> where BD: BitDenotation {
|
|
|
|
fn each_state_bit<F>(&self, f: F) where F: FnMut(BD::Idx) {
|
|
|
|
self.curr_state.each_bit(self.base_results.operator().bits_per_block(), f)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn each_gen_bit<F>(&self, f: F) where F: FnMut(BD::Idx) {
|
|
|
|
self.stmt_gen.each_bit(self.base_results.operator().bits_per_block(), f)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn new(results: DataflowResults<BD>) -> Self {
|
|
|
|
let bits_per_block = results.sets().bits_per_block();
|
|
|
|
let curr_state = IdxSetBuf::new_empty(bits_per_block);
|
|
|
|
let stmt_gen = IdxSetBuf::new_empty(bits_per_block);
|
|
|
|
let stmt_kill = IdxSetBuf::new_empty(bits_per_block);
|
|
|
|
FlowInProgress {
|
|
|
|
base_results: results,
|
|
|
|
curr_state: curr_state,
|
|
|
|
stmt_gen: stmt_gen,
|
|
|
|
stmt_kill: stmt_kill,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn reset_to_entry_of(&mut self, bb: BasicBlock) {
|
|
|
|
(*self.curr_state).clone_from(self.base_results.sets().on_entry_set_for(bb.index()));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn reconstruct_statement_effect(&mut self, loc: Location) {
|
|
|
|
self.stmt_gen.reset_to_empty();
|
|
|
|
self.stmt_kill.reset_to_empty();
|
|
|
|
let mut ignored = IdxSetBuf::new_empty(0);
|
|
|
|
let mut sets = BlockSets {
|
|
|
|
on_entry: &mut ignored, gen_set: &mut self.stmt_gen, kill_set: &mut self.stmt_kill,
|
|
|
|
};
|
|
|
|
self.base_results.operator().statement_effect(&mut sets, loc);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn reconstruct_terminator_effect(&mut self, loc: Location) {
|
|
|
|
self.stmt_gen.reset_to_empty();
|
|
|
|
self.stmt_kill.reset_to_empty();
|
|
|
|
let mut ignored = IdxSetBuf::new_empty(0);
|
|
|
|
let mut sets = BlockSets {
|
|
|
|
on_entry: &mut ignored, gen_set: &mut self.stmt_gen, kill_set: &mut self.stmt_kill,
|
|
|
|
};
|
|
|
|
self.base_results.operator().terminator_effect(&mut sets, loc);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn apply_local_effect(&mut self) {
|
|
|
|
self.curr_state.union(&self.stmt_gen);
|
|
|
|
self.curr_state.subtract(&self.stmt_kill);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn elems_incoming(&self) -> indexed_set::Elems<BD::Idx> {
|
|
|
|
let univ = self.base_results.sets().bits_per_block();
|
|
|
|
self.curr_state.elems(univ)
|
|
|
|
}
|
|
|
|
}
|