Rollup merge of #111952 - cjgillot:drop-replace, r=WaffleLapkin

Remove DesugaringKind::Replace.

A simple boolean flag is enough.
This commit is contained in:
Guillaume Gomez 2023-05-27 13:38:31 +02:00 committed by GitHub
commit ddb5424569
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 78 additions and 82 deletions

View file

@ -1635,34 +1635,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
}) })
} }
/// Reports StorageDeadOrDrop of `place` conflicts with `borrow`.
///
/// Depending on the origin of the StorageDeadOrDrop, this may be
/// reported as either a drop or an illegal mutation of a borrowed value.
/// The latter is preferred when the this is a drop triggered by a
/// reassignment, as it's more user friendly to report a problem with the
/// explicit assignment than the implicit drop.
#[instrument(level = "debug", skip(self))]
pub(crate) fn report_storage_dead_or_drop_of_borrowed(
&mut self,
location: Location,
place_span: (Place<'tcx>, Span),
borrow: &BorrowData<'tcx>,
) {
// It's sufficient to check the last desugaring as Replace is the last
// one to be applied.
if let Some(DesugaringKind::Replace) = place_span.1.desugaring_kind() {
self.report_illegal_mutation_of_borrowed(location, place_span, borrow)
} else {
self.report_borrowed_value_does_not_live_long_enough(
location,
borrow,
place_span,
Some(WriteKind::StorageDeadOrDrop),
)
}
}
/// This means that some data referenced by `borrow` needs to live /// This means that some data referenced by `borrow` needs to live
/// past the point where the StorageDeadOrDrop of `place` occurs. /// past the point where the StorageDeadOrDrop of `place` occurs.
/// This is usually interpreted as meaning that `place` has too /// This is usually interpreted as meaning that `place` has too

View file

@ -641,13 +641,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let Some(hir::Node::Item(item)) = node else { return; }; let Some(hir::Node::Item(item)) = node else { return; };
let hir::ItemKind::Fn(.., body_id) = item.kind else { return; }; let hir::ItemKind::Fn(.., body_id) = item.kind else { return; };
let body = self.infcx.tcx.hir().body(body_id); let body = self.infcx.tcx.hir().body(body_id);
let mut assign_span = span;
// Drop desugaring is done at MIR build so it's not in the HIR
if let Some(DesugaringKind::Replace) = span.desugaring_kind() {
assign_span.remove_mark();
}
let mut v = V { assign_span, err, ty, suggested: false }; let mut v = V { assign_span: span, err, ty, suggested: false };
v.visit_body(body); v.visit_body(body);
if !v.suggested { if !v.suggested {
err.help(format!( err.help(format!(

View file

@ -112,11 +112,13 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
TerminatorKind::SwitchInt { discr, targets: _ } => { TerminatorKind::SwitchInt { discr, targets: _ } => {
self.consume_operand(location, discr); self.consume_operand(location, discr);
} }
TerminatorKind::Drop { place: drop_place, target: _, unwind: _ } => { TerminatorKind::Drop { place: drop_place, target: _, unwind: _, replace } => {
let write_kind =
if *replace { WriteKind::Replace } else { WriteKind::StorageDeadOrDrop };
self.access_place( self.access_place(
location, location,
*drop_place, *drop_place,
(AccessDepth::Drop, Write(WriteKind::StorageDeadOrDrop)), (AccessDepth::Drop, Write(write_kind)),
LocalMutationIsAllowed::Yes, LocalMutationIsAllowed::Yes,
); );
} }

View file

@ -685,17 +685,19 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
TerminatorKind::SwitchInt { discr, targets: _ } => { TerminatorKind::SwitchInt { discr, targets: _ } => {
self.consume_operand(loc, (discr, span), flow_state); self.consume_operand(loc, (discr, span), flow_state);
} }
TerminatorKind::Drop { place, target: _, unwind: _ } => { TerminatorKind::Drop { place, target: _, unwind: _, replace } => {
debug!( debug!(
"visit_terminator_drop \ "visit_terminator_drop \
loc: {:?} term: {:?} place: {:?} span: {:?}", loc: {:?} term: {:?} place: {:?} span: {:?}",
loc, term, place, span loc, term, place, span
); );
let write_kind =
if *replace { WriteKind::Replace } else { WriteKind::StorageDeadOrDrop };
self.access_place( self.access_place(
loc, loc,
(*place, span), (*place, span),
(AccessDepth::Drop, Write(WriteKind::StorageDeadOrDrop)), (AccessDepth::Drop, Write(write_kind)),
LocalMutationIsAllowed::Yes, LocalMutationIsAllowed::Yes,
flow_state, flow_state,
); );
@ -885,6 +887,7 @@ enum ReadKind {
#[derive(Copy, Clone, PartialEq, Eq, Debug)] #[derive(Copy, Clone, PartialEq, Eq, Debug)]
enum WriteKind { enum WriteKind {
StorageDeadOrDrop, StorageDeadOrDrop,
Replace,
MutableBorrow(BorrowKind), MutableBorrow(BorrowKind),
Mutate, Mutate,
Move, Move,
@ -1132,13 +1135,21 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
this.buffer_error(err); this.buffer_error(err);
} }
WriteKind::StorageDeadOrDrop => this WriteKind::StorageDeadOrDrop => this
.report_storage_dead_or_drop_of_borrowed(location, place_span, borrow), .report_borrowed_value_does_not_live_long_enough(
location,
borrow,
place_span,
Some(WriteKind::StorageDeadOrDrop),
),
WriteKind::Mutate => { WriteKind::Mutate => {
this.report_illegal_mutation_of_borrowed(location, place_span, borrow) this.report_illegal_mutation_of_borrowed(location, place_span, borrow)
} }
WriteKind::Move => { WriteKind::Move => {
this.report_move_out_while_borrowed(location, place_span, borrow) this.report_move_out_while_borrowed(location, place_span, borrow)
} }
WriteKind::Replace => {
this.report_illegal_mutation_of_borrowed(location, place_span, borrow)
}
} }
Control::Break Control::Break
} }
@ -1982,12 +1993,14 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
Reservation( Reservation(
WriteKind::Move WriteKind::Move
| WriteKind::Replace
| WriteKind::StorageDeadOrDrop | WriteKind::StorageDeadOrDrop
| WriteKind::MutableBorrow(BorrowKind::Shared) | WriteKind::MutableBorrow(BorrowKind::Shared)
| WriteKind::MutableBorrow(BorrowKind::Shallow), | WriteKind::MutableBorrow(BorrowKind::Shallow),
) )
| Write( | Write(
WriteKind::Move WriteKind::Move
| WriteKind::Replace
| WriteKind::StorageDeadOrDrop | WriteKind::StorageDeadOrDrop
| WriteKind::MutableBorrow(BorrowKind::Shared) | WriteKind::MutableBorrow(BorrowKind::Shared)
| WriteKind::MutableBorrow(BorrowKind::Shallow), | WriteKind::MutableBorrow(BorrowKind::Shallow),

View file

@ -473,7 +473,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
| TerminatorKind::GeneratorDrop => { | TerminatorKind::GeneratorDrop => {
bug!("shouldn't exist at codegen {:?}", bb_data.terminator()); bug!("shouldn't exist at codegen {:?}", bb_data.terminator());
} }
TerminatorKind::Drop { place, target, unwind: _ } => { TerminatorKind::Drop { place, target, unwind: _, replace: _ } => {
let drop_place = codegen_place(fx, *place); let drop_place = codegen_place(fx, *place);
crate::abi::codegen_drop(fx, source_info, drop_place); crate::abi::codegen_drop(fx, source_info, drop_place);

View file

@ -1256,7 +1256,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
MergingSucc::False MergingSucc::False
} }
mir::TerminatorKind::Drop { place, target, unwind } => { mir::TerminatorKind::Drop { place, target, unwind, replace: _ } => {
self.codegen_drop_terminator(helper, bx, place, target, unwind, mergeable_succ()) self.codegen_drop_terminator(helper, bx, place, target, unwind, mergeable_succ())
} }

View file

@ -114,7 +114,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
} }
} }
Drop { place, target, unwind } => { Drop { place, target, unwind, replace: _ } => {
let frame = self.frame(); let frame = self.frame();
let ty = place.ty(&frame.body.local_decls, *self.tcx).ty; let ty = place.ty(&frame.body.local_decls, *self.tcx).ty;
let ty = self.subst_from_frame_and_normalize_erasing_regions(frame, ty)?; let ty = self.subst_from_frame_and_normalize_erasing_regions(frame, ty)?;

View file

@ -603,7 +603,11 @@ pub enum TerminatorKind<'tcx> {
/// > The drop glue is executed if, among all statements executed within this `Body`, an assignment to /// > The drop glue is executed if, among all statements executed within this `Body`, an assignment to
/// > the place or one of its "parents" occurred more recently than a move out of it. This does not /// > the place or one of its "parents" occurred more recently than a move out of it. This does not
/// > consider indirect assignments. /// > consider indirect assignments.
Drop { place: Place<'tcx>, target: BasicBlock, unwind: UnwindAction }, ///
/// The `replace` flag indicates whether this terminator was created as part of an assignment.
/// This should only be used for diagnostic purposes, and does not have any operational
/// meaning.
Drop { place: Place<'tcx>, target: BasicBlock, unwind: UnwindAction, replace: bool },
/// Roughly speaking, evaluates the `func` operand and the arguments, and starts execution of /// Roughly speaking, evaluates the `func` operand and the arguments, and starts execution of
/// the referred to function. The operand types must match the argument types of the function. /// the referred to function. The operand types must match the argument types of the function.

View file

@ -504,6 +504,7 @@ macro_rules! make_mir_visitor {
place, place,
target: _, target: _,
unwind: _, unwind: _,
replace: _,
} => { } => {
self.visit_place( self.visit_place(
place, place,

View file

@ -57,6 +57,7 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
place: self.parse_place(args[0])?, place: self.parse_place(args[0])?,
target: self.parse_block(args[1])?, target: self.parse_block(args[1])?,
unwind: UnwindAction::Continue, unwind: UnwindAction::Continue,
replace: false,
}) })
}, },
@call("mir_call", args) => { @call("mir_call", args) => {

View file

@ -725,6 +725,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
place: to_drop, place: to_drop,
target: success, target: success,
unwind: UnwindAction::Continue, unwind: UnwindAction::Continue,
replace: false,
}, },
); );
this.diverge_from(block); this.diverge_from(block);

View file

@ -91,7 +91,7 @@ use rustc_middle::middle::region;
use rustc_middle::mir::*; use rustc_middle::mir::*;
use rustc_middle::thir::{Expr, LintLevel}; use rustc_middle::thir::{Expr, LintLevel};
use rustc_span::{DesugaringKind, Span, DUMMY_SP}; use rustc_span::{Span, DUMMY_SP};
#[derive(Debug)] #[derive(Debug)]
pub struct Scopes<'tcx> { pub struct Scopes<'tcx> {
@ -371,6 +371,7 @@ impl DropTree {
// The caller will handle this if needed. // The caller will handle this if needed.
unwind: UnwindAction::Terminate, unwind: UnwindAction::Terminate,
place: drop_data.0.local.into(), place: drop_data.0.local.into(),
replace: false,
}; };
cfg.terminate(block, drop_data.0.source_info, terminator); cfg.terminate(block, drop_data.0.source_info, terminator);
} }
@ -1128,9 +1129,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
place: Place<'tcx>, place: Place<'tcx>,
value: Rvalue<'tcx>, value: Rvalue<'tcx>,
) -> BlockAnd<()> { ) -> BlockAnd<()> {
let span = self.tcx.with_stable_hashing_context(|hcx| {
span.mark_with_reason(None, DesugaringKind::Replace, self.tcx.sess.edition(), hcx)
});
let source_info = self.source_info(span); let source_info = self.source_info(span);
// create the new block for the assignment // create the new block for the assignment
@ -1148,6 +1146,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
place, place,
target: assign, target: assign,
unwind: UnwindAction::Cleanup(assign_unwind), unwind: UnwindAction::Cleanup(assign_unwind),
replace: true,
}, },
); );
self.diverge_from(block); self.diverge_from(block);
@ -1261,6 +1260,7 @@ fn build_scope_drops<'tcx>(
place: local.into(), place: local.into(),
target: next, target: next,
unwind: UnwindAction::Continue, unwind: UnwindAction::Continue,
replace: false,
}, },
); );
block = next; block = next;

View file

@ -237,6 +237,7 @@ where
place: self.place, place: self.place,
target: self.succ, target: self.succ,
unwind: self.unwind.into_action(), unwind: self.unwind.into_action(),
replace: false,
}, },
); );
} }
@ -719,6 +720,7 @@ where
place: tcx.mk_place_deref(ptr), place: tcx.mk_place_deref(ptr),
target: loop_block, target: loop_block,
unwind: unwind.into_action(), unwind: unwind.into_action(),
replace: false,
}, },
); );
@ -963,8 +965,12 @@ where
} }
fn drop_block(&mut self, target: BasicBlock, unwind: Unwind) -> BasicBlock { fn drop_block(&mut self, target: BasicBlock, unwind: Unwind) -> BasicBlock {
let block = let block = TerminatorKind::Drop {
TerminatorKind::Drop { place: self.place, target, unwind: unwind.into_action() }; place: self.place,
target,
unwind: unwind.into_action(),
replace: false,
};
self.new_block(unwind, block) self.new_block(unwind, block)
} }

View file

@ -479,7 +479,7 @@ impl Direction for Forward {
Goto { target } => propagate(target, exit_state), Goto { target } => propagate(target, exit_state),
Assert { target, unwind, expected: _, msg: _, cond: _ } Assert { target, unwind, expected: _, msg: _, cond: _ }
| Drop { target, unwind, place: _ } | Drop { target, unwind, place: _, replace: _ }
| FalseUnwind { real_target: target, unwind } => { | FalseUnwind { real_target: target, unwind } => {
if let UnwindAction::Cleanup(unwind) = unwind { if let UnwindAction::Cleanup(unwind) = unwind {
propagate(unwind, exit_state); propagate(unwind, exit_state);

View file

@ -80,7 +80,7 @@ fn add_move_for_packed_drop<'tcx>(
is_cleanup: bool, is_cleanup: bool,
) { ) {
debug!("add_move_for_packed_drop({:?} @ {:?})", terminator, loc); debug!("add_move_for_packed_drop({:?} @ {:?})", terminator, loc);
let TerminatorKind::Drop { ref place, target, unwind } = terminator.kind else { let TerminatorKind::Drop { ref place, target, unwind, replace } = terminator.kind else {
unreachable!(); unreachable!();
}; };
@ -98,6 +98,11 @@ fn add_move_for_packed_drop<'tcx>(
patch.add_assign(loc, Place::from(temp), Rvalue::Use(Operand::Move(*place))); patch.add_assign(loc, Place::from(temp), Rvalue::Use(Operand::Move(*place)));
patch.patch_terminator( patch.patch_terminator(
loc.block, loc.block,
TerminatorKind::Drop { place: Place::from(temp), target: storage_dead_block, unwind }, TerminatorKind::Drop {
place: Place::from(temp),
target: storage_dead_block,
unwind,
replace,
},
); );
} }

View file

@ -14,7 +14,7 @@ use rustc_mir_dataflow::un_derefer::UnDerefer;
use rustc_mir_dataflow::MoveDataParamEnv; use rustc_mir_dataflow::MoveDataParamEnv;
use rustc_mir_dataflow::{on_all_children_bits, on_all_drop_children_bits}; use rustc_mir_dataflow::{on_all_children_bits, on_all_drop_children_bits};
use rustc_mir_dataflow::{Analysis, ResultsCursor}; use rustc_mir_dataflow::{Analysis, ResultsCursor};
use rustc_span::{DesugaringKind, Span}; use rustc_span::Span;
use rustc_target::abi::{FieldIdx, VariantIdx}; use rustc_target::abi::{FieldIdx, VariantIdx};
use std::fmt; use std::fmt;
@ -401,7 +401,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
let terminator = data.terminator(); let terminator = data.terminator();
match terminator.kind { match terminator.kind {
TerminatorKind::Drop { mut place, target, unwind } => { TerminatorKind::Drop { mut place, target, unwind, replace } => {
if let Some(new_place) = self.un_derefer.derefer(place.as_ref(), self.body) { if let Some(new_place) = self.un_derefer.derefer(place.as_ref(), self.body) {
place = new_place; place = new_place;
} }
@ -434,10 +434,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
) )
} }
LookupResult::Parent(..) => { LookupResult::Parent(..) => {
if !matches!( if !replace {
terminator.source_info.span.desugaring_kind(),
Some(DesugaringKind::Replace),
) {
self.tcx.sess.delay_span_bug( self.tcx.sess.delay_span_bug(
terminator.source_info.span, terminator.source_info.span,
format!("drop of untracked value {:?}", bb), format!("drop of untracked value {:?}", bb),

View file

@ -1045,7 +1045,10 @@ fn elaborate_generator_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
for (block, block_data) in body.basic_blocks.iter_enumerated() { for (block, block_data) in body.basic_blocks.iter_enumerated() {
let (target, unwind, source_info) = match block_data.terminator() { let (target, unwind, source_info) = match block_data.terminator() {
Terminator { source_info, kind: TerminatorKind::Drop { place, target, unwind } } => { Terminator {
source_info,
kind: TerminatorKind::Drop { place, target, unwind, replace: _ },
} => {
if let Some(local) = place.as_local() { if let Some(local) = place.as_local() {
if local == SELF_ARG { if local == SELF_ARG {
(target, unwind, source_info) (target, unwind, source_info)
@ -1304,6 +1307,7 @@ fn insert_clean_drop(body: &mut Body<'_>) -> BasicBlock {
place: Place::from(SELF_ARG), place: Place::from(SELF_ARG),
target: return_block, target: return_block,
unwind: UnwindAction::Continue, unwind: UnwindAction::Continue,
replace: false,
}; };
let source_info = SourceInfo::outermost(body.span); let source_info = SourceInfo::outermost(body.span);

View file

@ -449,7 +449,7 @@ impl<'tcx> Inliner<'tcx> {
checker.visit_basic_block_data(bb, blk); checker.visit_basic_block_data(bb, blk);
let term = blk.terminator(); let term = blk.terminator();
if let TerminatorKind::Drop { ref place, target, unwind } = term.kind { if let TerminatorKind::Drop { ref place, target, unwind, replace: _ } = term.kind {
work_list.push(target); work_list.push(target);
// If the place doesn't actually need dropping, treat it like a regular goto. // If the place doesn't actually need dropping, treat it like a regular goto.
@ -457,8 +457,8 @@ impl<'tcx> Inliner<'tcx> {
.callee .callee
.subst_mir(self.tcx, ty::EarlyBinder(&place.ty(callee_body, tcx).ty)); .subst_mir(self.tcx, ty::EarlyBinder(&place.ty(callee_body, tcx).ty));
if ty.needs_drop(tcx, self.param_env) && let UnwindAction::Cleanup(unwind) = unwind { if ty.needs_drop(tcx, self.param_env) && let UnwindAction::Cleanup(unwind) = unwind {
work_list.push(unwind); work_list.push(unwind);
} }
} else if callee_attrs.instruction_set != self.codegen_fn_attrs.instruction_set } else if callee_attrs.instruction_set != self.codegen_fn_attrs.instruction_set
&& matches!(term.kind, TerminatorKind::InlineAsm { .. }) && matches!(term.kind, TerminatorKind::InlineAsm { .. })
{ {

View file

@ -544,6 +544,7 @@ impl<'tcx> CloneShimBuilder<'tcx> {
place: dest_field, place: dest_field,
target: unwind, target: unwind,
unwind: UnwindAction::Terminate, unwind: UnwindAction::Terminate,
replace: false,
}, },
true, true,
); );
@ -800,6 +801,7 @@ fn build_call_shim<'tcx>(
place: rcvr_place(), place: rcvr_place(),
target: BasicBlock::new(2), target: BasicBlock::new(2),
unwind: UnwindAction::Continue, unwind: UnwindAction::Continue,
replace: false,
}, },
false, false,
); );
@ -815,6 +817,7 @@ fn build_call_shim<'tcx>(
place: rcvr_place(), place: rcvr_place(),
target: BasicBlock::new(4), target: BasicBlock::new(4),
unwind: UnwindAction::Terminate, unwind: UnwindAction::Terminate,
replace: false,
}, },
true, true,
); );

View file

@ -309,7 +309,7 @@ fn rustc_terminator_to_terminator(
Terminate => Terminator::Abort, Terminate => Terminator::Abort,
Return => Terminator::Return, Return => Terminator::Return,
Unreachable => Terminator::Unreachable, Unreachable => Terminator::Unreachable,
Drop { place, target, unwind } => Terminator::Drop { Drop { place, target, unwind, replace: _ } => Terminator::Drop {
place: rustc_place_to_place(place), place: rustc_place_to_place(place),
target: target.as_usize(), target: target.as_usize(),
unwind: rustc_unwind_to_unwind(unwind), unwind: rustc_unwind_to_unwind(unwind),

View file

@ -1147,7 +1147,6 @@ pub enum DesugaringKind {
Await, Await,
ForLoop, ForLoop,
WhileLoop, WhileLoop,
Replace,
} }
impl DesugaringKind { impl DesugaringKind {
@ -1163,7 +1162,6 @@ impl DesugaringKind {
DesugaringKind::OpaqueTy => "`impl Trait`", DesugaringKind::OpaqueTy => "`impl Trait`",
DesugaringKind::ForLoop => "`for` loop", DesugaringKind::ForLoop => "`for` loop",
DesugaringKind::WhileLoop => "`while` loop", DesugaringKind::WhileLoop => "`while` loop",
DesugaringKind::Replace => "drop and replace",
} }
} }
} }

View file

@ -8,7 +8,6 @@ fn a() {
//~^ NOTE `vec[_]` is borrowed here //~^ NOTE `vec[_]` is borrowed here
vec[0] = Box::new(4); //~ ERROR cannot assign vec[0] = Box::new(4); //~ ERROR cannot assign
//~^ NOTE `vec[_]` is assigned to here //~^ NOTE `vec[_]` is assigned to here
//~| NOTE in this expansion of desugaring of drop and replace
_a.use_ref(); _a.use_ref();
//~^ NOTE borrow later used here //~^ NOTE borrow later used here
} }
@ -23,7 +22,6 @@ fn b() {
//~^ `vec[_]` is borrowed here //~^ `vec[_]` is borrowed here
vec[0] = Box::new(4); //~ ERROR cannot assign vec[0] = Box::new(4); //~ ERROR cannot assign
//~^ NOTE `vec[_]` is assigned to here //~^ NOTE `vec[_]` is assigned to here
//~| NOTE in this expansion of desugaring of drop and replace
_b.use_ref(); _b.use_ref();
//~^ NOTE borrow later used here //~^ NOTE borrow later used here
} }

View file

@ -6,24 +6,24 @@ LL | [box ref _a, _, _] => {
LL | LL |
LL | vec[0] = Box::new(4); LL | vec[0] = Box::new(4);
| ^^^^^^ `vec[_]` is assigned to here but it was already borrowed | ^^^^^^ `vec[_]` is assigned to here but it was already borrowed
... LL |
LL | _a.use_ref(); LL | _a.use_ref();
| ------------ borrow later used here | ------------ borrow later used here
error[E0506]: cannot assign to `vec[_]` because it is borrowed error[E0506]: cannot assign to `vec[_]` because it is borrowed
--> $DIR/borrowck-vec-pattern-nesting.rs:24:13 --> $DIR/borrowck-vec-pattern-nesting.rs:23:13
| |
LL | &mut [ref _b @ ..] => { LL | &mut [ref _b @ ..] => {
| ------ `vec[_]` is borrowed here | ------ `vec[_]` is borrowed here
LL | LL |
LL | vec[0] = Box::new(4); LL | vec[0] = Box::new(4);
| ^^^^^^ `vec[_]` is assigned to here but it was already borrowed | ^^^^^^ `vec[_]` is assigned to here but it was already borrowed
... LL |
LL | _b.use_ref(); LL | _b.use_ref();
| ------------ borrow later used here | ------------ borrow later used here
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
--> $DIR/borrowck-vec-pattern-nesting.rs:36:11 --> $DIR/borrowck-vec-pattern-nesting.rs:34:11
| |
LL | match vec { LL | match vec {
| ^^^ cannot move out of here | ^^^ cannot move out of here
@ -41,7 +41,7 @@ LL + [_a,
| |
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
--> $DIR/borrowck-vec-pattern-nesting.rs:48:13 --> $DIR/borrowck-vec-pattern-nesting.rs:46:13
| |
LL | let a = vec[0]; LL | let a = vec[0];
| ^^^^^^ | ^^^^^^
@ -55,7 +55,7 @@ LL | let a = &vec[0];
| + | +
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
--> $DIR/borrowck-vec-pattern-nesting.rs:57:11 --> $DIR/borrowck-vec-pattern-nesting.rs:55:11
| |
LL | match vec { LL | match vec {
| ^^^ cannot move out of here | ^^^ cannot move out of here
@ -73,7 +73,7 @@ LL + [
| |
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
--> $DIR/borrowck-vec-pattern-nesting.rs:67:13 --> $DIR/borrowck-vec-pattern-nesting.rs:65:13
| |
LL | let a = vec[0]; LL | let a = vec[0];
| ^^^^^^ | ^^^^^^
@ -87,7 +87,7 @@ LL | let a = &vec[0];
| + | +
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
--> $DIR/borrowck-vec-pattern-nesting.rs:76:11 --> $DIR/borrowck-vec-pattern-nesting.rs:74:11
| |
LL | match vec { LL | match vec {
| ^^^ cannot move out of here | ^^^ cannot move out of here
@ -106,7 +106,7 @@ LL + [_a, _b, _c] => {}
| |
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
--> $DIR/borrowck-vec-pattern-nesting.rs:87:13 --> $DIR/borrowck-vec-pattern-nesting.rs:85:13
| |
LL | let a = vec[0]; LL | let a = vec[0];
| ^^^^^^ | ^^^^^^

View file

@ -5,7 +5,6 @@ fn test_drop_replace() {
b = Box::new(1); //~ NOTE first assignment b = Box::new(1); //~ NOTE first assignment
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b` b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
//~| NOTE cannot assign twice to immutable //~| NOTE cannot assign twice to immutable
//~| NOTE in this expansion of desugaring of drop and replace
} }
fn test_call() { fn test_call() {
@ -14,14 +13,12 @@ fn test_call() {
//~| SUGGESTION mut b //~| SUGGESTION mut b
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b` b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
//~| NOTE cannot assign twice to immutable //~| NOTE cannot assign twice to immutable
//~| NOTE in this expansion of desugaring of drop and replace
} }
fn test_args(b: Box<i32>) { //~ HELP consider making this binding mutable fn test_args(b: Box<i32>) { //~ HELP consider making this binding mutable
//~| SUGGESTION mut b //~| SUGGESTION mut b
b = Box::new(2); //~ ERROR cannot assign to immutable argument `b` b = Box::new(2); //~ ERROR cannot assign to immutable argument `b`
//~| NOTE cannot assign to immutable argument //~| NOTE cannot assign to immutable argument
//~| NOTE in this expansion of desugaring of drop and replace
} }
fn main() {} fn main() {}

View file

@ -10,7 +10,7 @@ LL | b = Box::new(2);
| ^ cannot assign twice to immutable variable | ^ cannot assign twice to immutable variable
error[E0384]: cannot assign twice to immutable variable `b` error[E0384]: cannot assign twice to immutable variable `b`
--> $DIR/issue-45199.rs:15:5 --> $DIR/issue-45199.rs:14:5
| |
LL | let b = Box::new(1); LL | let b = Box::new(1);
| - | -
@ -22,7 +22,7 @@ LL | b = Box::new(2);
| ^ cannot assign twice to immutable variable | ^ cannot assign twice to immutable variable
error[E0384]: cannot assign to immutable argument `b` error[E0384]: cannot assign to immutable argument `b`
--> $DIR/issue-45199.rs:22:5 --> $DIR/issue-45199.rs:20:5
| |
LL | fn test_args(b: Box<i32>) { LL | fn test_args(b: Box<i32>) {
| - help: consider making this binding mutable: `mut b` | - help: consider making this binding mutable: `mut b`

View file

@ -5,7 +5,6 @@ fn test() {
drop(b); drop(b);
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b` b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
//~| NOTE cannot assign twice to immutable //~| NOTE cannot assign twice to immutable
//~| NOTE in this expansion of desugaring of drop and replace
drop(b); drop(b);
} }