Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 14c54b6

Browse files
committedMar 5, 2023
Auto merge of #107844 - Zeegomo:no-drop-and-rep, r=cjgillot
Desugaring of drop and replace at MIR build This commit desugars the drop and replace deriving from an assignment at MIR build, avoiding the construction of the `DropAndReplace` terminator (which will be removed in a following PR). In order to retain the same error messages for replaces a new `DesugaringKind::Replace` variant is introduced. The changes in the borrowck are also useful for future work in moving drop elaboration before borrowck, as no `DropAndReplace` would be present there anymore. Notes on test diffs: * `tests/ui/borrowck/issue-58776-borrowck-scans-children`: the assignment deriving from the desugaring kills the borrow. * `tests/ui/async-await/async-fn-size-uninit-locals.rs`, `tests/mir-opt/issue_41110.test.ElaborateDrops.after.mir`, `tests/mir-opt/issue_41888.main.ElaborateDrops.after.mir`: drop elaboration generates (or reads from) a useless drop flag due to an issue with the dataflow analysis. Will be fixed independently by #106430. See #104488 for more context
2 parents 35636f9 + d1f7fa5 commit 14c54b6

22 files changed

+281
-152
lines changed
 

‎compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,6 +1467,32 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
14671467

14681468
/// Reports StorageDeadOrDrop of `place` conflicts with `borrow`.
14691469
///
1470+
/// Depending on the origin of the StorageDeadOrDrop, this may be
1471+
/// reported as either a drop or an illegal mutation of a borrowed value.
1472+
/// The latter is preferred when the this is a drop triggered by a
1473+
/// reassignment, as it's more user friendly to report a problem with the
1474+
/// explicit assignment than the implicit drop.
1475+
#[instrument(level = "debug", skip(self))]
1476+
pub(crate) fn report_storage_dead_or_drop_of_borrowed(
1477+
&mut self,
1478+
location: Location,
1479+
place_span: (Place<'tcx>, Span),
1480+
borrow: &BorrowData<'tcx>,
1481+
) {
1482+
// It's sufficient to check the last desugaring as Replace is the last
1483+
// one to be applied.
1484+
if let Some(DesugaringKind::Replace) = place_span.1.desugaring_kind() {
1485+
self.report_illegal_mutation_of_borrowed(location, place_span, borrow)
1486+
} else {
1487+
self.report_borrowed_value_does_not_live_long_enough(
1488+
location,
1489+
borrow,
1490+
place_span,
1491+
Some(WriteKind::StorageDeadOrDrop),
1492+
)
1493+
}
1494+
}
1495+
14701496
/// This means that some data referenced by `borrow` needs to live
14711497
/// past the point where the StorageDeadOrDrop of `place` occurs.
14721498
/// This is usually interpreted as meaning that `place` has too

‎compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,20 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
925925
return OtherUse(use_span);
926926
}
927927

928-
for stmt in &self.body[location.block].statements[location.statement_index + 1..] {
928+
// drop and replace might have moved the assignment to the next block
929+
let maybe_additional_statement =
930+
if let TerminatorKind::Drop { target: drop_target, .. } =
931+
self.body[location.block].terminator().kind
932+
{
933+
self.body[drop_target].statements.first()
934+
} else {
935+
None
936+
};
937+
938+
let statements =
939+
self.body[location.block].statements[location.statement_index + 1..].iter();
940+
941+
for stmt in statements.chain(maybe_additional_statement) {
929942
if let StatementKind::Assign(box (_, Rvalue::Aggregate(kind, places))) = &stmt.kind {
930943
let (&def_id, is_generator) = match kind {
931944
box AggregateKind::Closure(def_id, _) => (def_id, false),

‎compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
828828
let Some(hir::Node::Item(item)) = node else { return; };
829829
let hir::ItemKind::Fn(.., body_id) = item.kind else { return; };
830830
let body = self.infcx.tcx.hir().body(body_id);
831-
let mut v = V { assign_span: span, err, ty, suggested: false };
831+
let mut assign_span = span;
832+
// Drop desugaring is done at MIR build so it's not in the HIR
833+
if let Some(DesugaringKind::Replace) = span.desugaring_kind() {
834+
assign_span.remove_mark();
835+
}
836+
837+
let mut v = V { assign_span, err, ty, suggested: false };
832838
v.visit_body(body);
833839
if !v.suggested {
834840
err.help(&format!(

‎compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,12 +1185,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11851185
this.buffer_error(err);
11861186
}
11871187
WriteKind::StorageDeadOrDrop => this
1188-
.report_borrowed_value_does_not_live_long_enough(
1189-
location,
1190-
borrow,
1191-
place_span,
1192-
Some(kind),
1193-
),
1188+
.report_storage_dead_or_drop_of_borrowed(location, place_span, borrow),
11941189
WriteKind::Mutate => {
11951190
this.report_illegal_mutation_of_borrowed(location, place_span, borrow)
11961191
}

‎compiler/rustc_mir_build/src/build/expr/stmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
4040
// Generate better code for things that don't need to be
4141
// dropped.
4242
if lhs.ty.needs_drop(this.tcx, this.param_env) {
43-
let rhs = unpack!(block = this.as_local_operand(block, rhs));
43+
let rhs = unpack!(block = this.as_local_rvalue(block, rhs));
4444
let lhs = unpack!(block = this.as_place(block, lhs));
4545
unpack!(block = this.build_drop_and_replace(block, lhs_span, lhs, rhs));
4646
} else {

‎compiler/rustc_mir_build/src/build/scope.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ use rustc_middle::middle::region;
9191
use rustc_middle::mir::*;
9292
use rustc_middle::thir::{Expr, LintLevel};
9393

94-
use rustc_span::{Span, DUMMY_SP};
94+
use rustc_span::{DesugaringKind, Span, DUMMY_SP};
9595

9696
#[derive(Debug)]
9797
pub struct Scopes<'tcx> {
@@ -1118,24 +1118,35 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
11181118
}
11191119

11201120
/// Utility function for *non*-scope code to build their own drops
1121+
/// Force a drop at this point in the MIR by creating a new block.
11211122
pub(crate) fn build_drop_and_replace(
11221123
&mut self,
11231124
block: BasicBlock,
11241125
span: Span,
11251126
place: Place<'tcx>,
1126-
value: Operand<'tcx>,
1127+
value: Rvalue<'tcx>,
11271128
) -> BlockAnd<()> {
1129+
let span = self.tcx.with_stable_hashing_context(|hcx| {
1130+
span.mark_with_reason(None, DesugaringKind::Replace, self.tcx.sess.edition(), hcx)
1131+
});
11281132
let source_info = self.source_info(span);
1129-
let next_target = self.cfg.start_new_block();
1133+
1134+
// create the new block for the assignment
1135+
let assign = self.cfg.start_new_block();
1136+
self.cfg.push_assign(assign, source_info, place, value.clone());
1137+
1138+
// create the new block for the assignment in the case of unwinding
1139+
let assign_unwind = self.cfg.start_new_cleanup_block();
1140+
self.cfg.push_assign(assign_unwind, source_info, place, value.clone());
11301141

11311142
self.cfg.terminate(
11321143
block,
11331144
source_info,
1134-
TerminatorKind::DropAndReplace { place, value, target: next_target, unwind: None },
1145+
TerminatorKind::Drop { place, target: assign, unwind: Some(assign_unwind) },
11351146
);
11361147
self.diverge_from(block);
11371148

1138-
next_target.unit()
1149+
assign.unit()
11391150
}
11401151

11411152
/// Creates an `Assert` terminator and return the success block.
@@ -1413,8 +1424,15 @@ impl<'tcx> DropTreeBuilder<'tcx> for Unwind {
14131424
fn add_entry(cfg: &mut CFG<'tcx>, from: BasicBlock, to: BasicBlock) {
14141425
let term = &mut cfg.block_data_mut(from).terminator_mut();
14151426
match &mut term.kind {
1416-
TerminatorKind::Drop { unwind, .. }
1417-
| TerminatorKind::DropAndReplace { unwind, .. }
1427+
TerminatorKind::Drop { unwind, .. } => {
1428+
if let Some(unwind) = *unwind {
1429+
let source_info = term.source_info;
1430+
cfg.terminate(unwind, source_info, TerminatorKind::Goto { target: to });
1431+
} else {
1432+
*unwind = Some(to);
1433+
}
1434+
}
1435+
TerminatorKind::DropAndReplace { unwind, .. }
14181436
| TerminatorKind::FalseUnwind { unwind, .. }
14191437
| TerminatorKind::Call { cleanup: unwind, .. }
14201438
| TerminatorKind::Assert { cleanup: unwind, .. }

‎compiler/rustc_mir_transform/src/elaborate_drops.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_mir_dataflow::un_derefer::UnDerefer;
1414
use rustc_mir_dataflow::MoveDataParamEnv;
1515
use rustc_mir_dataflow::{on_all_children_bits, on_all_drop_children_bits};
1616
use rustc_mir_dataflow::{Analysis, ResultsCursor};
17-
use rustc_span::Span;
17+
use rustc_span::{DesugaringKind, Span};
1818
use rustc_target::abi::VariantIdx;
1919
use std::fmt;
2020

@@ -425,10 +425,19 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
425425
bb,
426426
),
427427
LookupResult::Parent(..) => {
428-
self.tcx.sess.delay_span_bug(
429-
terminator.source_info.span,
430-
&format!("drop of untracked value {:?}", bb),
431-
);
428+
if !matches!(
429+
terminator.source_info.span.desugaring_kind(),
430+
Some(DesugaringKind::Replace),
431+
) {
432+
self.tcx.sess.delay_span_bug(
433+
terminator.source_info.span,
434+
&format!("drop of untracked value {:?}", bb),
435+
);
436+
}
437+
// A drop and replace behind a pointer/array/whatever.
438+
// The borrow checker requires that these locations are initialized before the assignment,
439+
// so we just leave an unconditional drop.
440+
assert!(!data.is_cleanup);
432441
}
433442
}
434443
}

‎compiler/rustc_span/src/hygiene.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,7 @@ pub enum DesugaringKind {
11511151
Await,
11521152
ForLoop,
11531153
WhileLoop,
1154+
Replace,
11541155
}
11551156

11561157
impl DesugaringKind {
@@ -1166,6 +1167,7 @@ impl DesugaringKind {
11661167
DesugaringKind::OpaqueTy => "`impl Trait`",
11671168
DesugaringKind::ForLoop => "`for` loop",
11681169
DesugaringKind::WhileLoop => "`while` loop",
1170+
DesugaringKind::Replace => "drop and replace",
11691171
}
11701172
}
11711173
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
- // MIR for `main` before ElaborateDrops
2+
+ // MIR for `main` after ElaborateDrops
3+
4+
fn main() -> () {
5+
let mut _0: (); // return place in scope 0 at $DIR/basic_assignment.rs:+0:11: +0:11
6+
let _1: bool; // in scope 0 at $DIR/basic_assignment.rs:+1:9: +1:17
7+
let mut _3: bool; // in scope 0 at $DIR/basic_assignment.rs:+6:16: +6:24
8+
let mut _6: std::option::Option<std::boxed::Box<u32>>; // in scope 0 at $DIR/basic_assignment.rs:+13:14: +13:20
9+
scope 1 {
10+
debug nodrop_x => _1; // in scope 1 at $DIR/basic_assignment.rs:+1:9: +1:17
11+
let _2: bool; // in scope 1 at $DIR/basic_assignment.rs:+2:9: +2:17
12+
scope 2 {
13+
debug nodrop_y => _2; // in scope 2 at $DIR/basic_assignment.rs:+2:9: +2:17
14+
let _4: std::option::Option<std::boxed::Box<u32>>; // in scope 2 at $DIR/basic_assignment.rs:+8:9: +8:15
15+
scope 3 {
16+
debug drop_x => _4; // in scope 3 at $DIR/basic_assignment.rs:+8:9: +8:15
17+
let _5: std::option::Option<std::boxed::Box<u32>>; // in scope 3 at $DIR/basic_assignment.rs:+9:9: +9:15
18+
scope 4 {
19+
debug drop_y => _5; // in scope 4 at $DIR/basic_assignment.rs:+9:9: +9:15
20+
}
21+
}
22+
}
23+
}
24+
25+
bb0: {
26+
StorageLive(_1); // scope 0 at $DIR/basic_assignment.rs:+1:9: +1:17
27+
_1 = const false; // scope 0 at $DIR/basic_assignment.rs:+1:20: +1:25
28+
StorageLive(_2); // scope 1 at $DIR/basic_assignment.rs:+2:9: +2:17
29+
StorageLive(_3); // scope 2 at $DIR/basic_assignment.rs:+6:16: +6:24
30+
_3 = _1; // scope 2 at $DIR/basic_assignment.rs:+6:16: +6:24
31+
_2 = move _3; // scope 2 at $DIR/basic_assignment.rs:+6:5: +6:24
32+
StorageDead(_3); // scope 2 at $DIR/basic_assignment.rs:+6:23: +6:24
33+
StorageLive(_4); // scope 2 at $DIR/basic_assignment.rs:+8:9: +8:15
34+
_4 = Option::<Box<u32>>::None; // scope 2 at $DIR/basic_assignment.rs:+8:36: +8:40
35+
StorageLive(_5); // scope 3 at $DIR/basic_assignment.rs:+9:9: +9:15
36+
StorageLive(_6); // scope 4 at $DIR/basic_assignment.rs:+13:14: +13:20
37+
_6 = move _4; // scope 4 at $DIR/basic_assignment.rs:+13:14: +13:20
38+
- drop(_5) -> [return: bb1, unwind: bb2]; // scope 4 at $DIR/basic_assignment.rs:+13:5: +13:11
39+
+ goto -> bb1; // scope 4 at $DIR/basic_assignment.rs:+13:5: +13:11
40+
}
41+
42+
bb1: {
43+
_5 = move _6; // scope 4 at $DIR/basic_assignment.rs:+13:5: +13:11
44+
- drop(_6) -> [return: bb3, unwind: bb6]; // scope 4 at $DIR/basic_assignment.rs:+13:19: +13:20
45+
+ goto -> bb3; // scope 4 at $DIR/basic_assignment.rs:+13:19: +13:20
46+
}
47+
48+
bb2 (cleanup): {
49+
_5 = move _6; // scope 4 at $DIR/basic_assignment.rs:+13:5: +13:11
50+
drop(_6) -> bb6; // scope 4 at $DIR/basic_assignment.rs:+13:19: +13:20
51+
}
52+
53+
bb3: {
54+
StorageDead(_6); // scope 4 at $DIR/basic_assignment.rs:+13:19: +13:20
55+
_0 = const (); // scope 0 at $DIR/basic_assignment.rs:+0:11: +14:2
56+
drop(_5) -> [return: bb4, unwind: bb7]; // scope 3 at $DIR/basic_assignment.rs:+14:1: +14:2
57+
}
58+
59+
bb4: {
60+
StorageDead(_5); // scope 3 at $DIR/basic_assignment.rs:+14:1: +14:2
61+
- drop(_4) -> bb5; // scope 2 at $DIR/basic_assignment.rs:+14:1: +14:2
62+
+ goto -> bb5; // scope 2 at $DIR/basic_assignment.rs:+14:1: +14:2
63+
}
64+
65+
bb5: {
66+
StorageDead(_4); // scope 2 at $DIR/basic_assignment.rs:+14:1: +14:2
67+
StorageDead(_2); // scope 1 at $DIR/basic_assignment.rs:+14:1: +14:2
68+
StorageDead(_1); // scope 0 at $DIR/basic_assignment.rs:+14:1: +14:2
69+
return; // scope 0 at $DIR/basic_assignment.rs:+14:2: +14:2
70+
}
71+
72+
bb6 (cleanup): {
73+
drop(_5) -> bb7; // scope 3 at $DIR/basic_assignment.rs:+14:1: +14:2
74+
}
75+
76+
bb7 (cleanup): {
77+
- drop(_4) -> bb8; // scope 2 at $DIR/basic_assignment.rs:+14:1: +14:2
78+
+ goto -> bb8; // scope 2 at $DIR/basic_assignment.rs:+14:1: +14:2
79+
}
80+
81+
bb8 (cleanup): {
82+
resume; // scope 0 at $DIR/basic_assignment.rs:+0:1: +14:2
83+
}
84+
}
85+

‎tests/mir-opt/basic_assignment.main.SimplifyCfg-initial.after.mir

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// MIR for `main` after SimplifyCfg-initial
22

33
| User Type Annotations
4-
| 0: user_ty: Canonical { max_universe: U0, variables: [], value: Ty(std::option::Option<std::boxed::Box<u32>>) }, span: $DIR/basic_assignment.rs:18:17: 18:33, inferred_ty: std::option::Option<std::boxed::Box<u32>>
5-
| 1: user_ty: Canonical { max_universe: U0, variables: [], value: Ty(std::option::Option<std::boxed::Box<u32>>) }, span: $DIR/basic_assignment.rs:18:17: 18:33, inferred_ty: std::option::Option<std::boxed::Box<u32>>
4+
| 0: user_ty: Canonical { max_universe: U0, variables: [], value: Ty(std::option::Option<std::boxed::Box<u32>>) }, span: $DIR/basic_assignment.rs:20:17: 20:33, inferred_ty: std::option::Option<std::boxed::Box<u32>>
5+
| 1: user_ty: Canonical { max_universe: U0, variables: [], value: Ty(std::option::Option<std::boxed::Box<u32>>) }, span: $DIR/basic_assignment.rs:20:17: 20:33, inferred_ty: std::option::Option<std::boxed::Box<u32>>
66
|
77
fn main() -> () {
88
let mut _0: (); // return place in scope 0 at $DIR/basic_assignment.rs:+0:11: +0:11
@@ -41,35 +41,37 @@ fn main() -> () {
4141
StorageLive(_5); // scope 3 at $DIR/basic_assignment.rs:+9:9: +9:15
4242
StorageLive(_6); // scope 4 at $DIR/basic_assignment.rs:+13:14: +13:20
4343
_6 = move _4; // scope 4 at $DIR/basic_assignment.rs:+13:14: +13:20
44-
replace(_5 <- move _6) -> [return: bb1, unwind: bb5]; // scope 4 at $DIR/basic_assignment.rs:+13:5: +13:11
44+
drop(_5) -> [return: bb1, unwind: bb2]; // scope 4 at $DIR/basic_assignment.rs:+13:5: +13:11
4545
}
4646

4747
bb1: {
48-
drop(_6) -> [return: bb2, unwind: bb6]; // scope 4 at $DIR/basic_assignment.rs:+13:19: +13:20
48+
_5 = move _6; // scope 4 at $DIR/basic_assignment.rs:+13:5: +13:11
49+
drop(_6) -> [return: bb3, unwind: bb6]; // scope 4 at $DIR/basic_assignment.rs:+13:19: +13:20
4950
}
5051

51-
bb2: {
52+
bb2 (cleanup): {
53+
_5 = move _6; // scope 4 at $DIR/basic_assignment.rs:+13:5: +13:11
54+
drop(_6) -> bb6; // scope 4 at $DIR/basic_assignment.rs:+13:19: +13:20
55+
}
56+
57+
bb3: {
5258
StorageDead(_6); // scope 4 at $DIR/basic_assignment.rs:+13:19: +13:20
5359
_0 = const (); // scope 0 at $DIR/basic_assignment.rs:+0:11: +14:2
54-
drop(_5) -> [return: bb3, unwind: bb7]; // scope 3 at $DIR/basic_assignment.rs:+14:1: +14:2
60+
drop(_5) -> [return: bb4, unwind: bb7]; // scope 3 at $DIR/basic_assignment.rs:+14:1: +14:2
5561
}
5662

57-
bb3: {
63+
bb4: {
5864
StorageDead(_5); // scope 3 at $DIR/basic_assignment.rs:+14:1: +14:2
59-
drop(_4) -> [return: bb4, unwind: bb8]; // scope 2 at $DIR/basic_assignment.rs:+14:1: +14:2
65+
drop(_4) -> [return: bb5, unwind: bb8]; // scope 2 at $DIR/basic_assignment.rs:+14:1: +14:2
6066
}
6167

62-
bb4: {
68+
bb5: {
6369
StorageDead(_4); // scope 2 at $DIR/basic_assignment.rs:+14:1: +14:2
6470
StorageDead(_2); // scope 1 at $DIR/basic_assignment.rs:+14:1: +14:2
6571
StorageDead(_1); // scope 0 at $DIR/basic_assignment.rs:+14:1: +14:2
6672
return; // scope 0 at $DIR/basic_assignment.rs:+14:2: +14:2
6773
}
6874

69-
bb5 (cleanup): {
70-
drop(_6) -> bb6; // scope 4 at $DIR/basic_assignment.rs:+13:19: +13:20
71-
}
72-
7375
bb6 (cleanup): {
7476
drop(_5) -> bb7; // scope 3 at $DIR/basic_assignment.rs:+14:1: +14:2
7577
}

‎tests/mir-opt/basic_assignment.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
// needs-unwind
12
// this tests move up progration, which is not yet implemented
23

4+
// EMIT_MIR basic_assignment.main.ElaborateDrops.diff
35
// EMIT_MIR basic_assignment.main.SimplifyCfg-initial.after.mir
46

57
// Check codegen for assignments (`a = b`) where the left-hand-side is

‎tests/mir-opt/issue_41110.test.ElaborateDrops.diff

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,37 +38,39 @@
3838
StorageLive(_5); // scope 2 at $DIR/issue_41110.rs:+4:9: +4:10
3939
+ _6 = const false; // scope 2 at $DIR/issue_41110.rs:+4:9: +4:10
4040
_5 = move _1; // scope 2 at $DIR/issue_41110.rs:+4:9: +4:10
41-
- replace(_2 <- move _5) -> [return: bb2, unwind: bb6]; // scope 2 at $DIR/issue_41110.rs:+4:5: +4:6
42-
+ goto -> bb12; // scope 2 at $DIR/issue_41110.rs:+4:5: +4:6
41+
- drop(_2) -> [return: bb2, unwind: bb3]; // scope 2 at $DIR/issue_41110.rs:+4:5: +4:6
42+
+ goto -> bb2; // scope 2 at $DIR/issue_41110.rs:+4:5: +4:6
4343
}
4444

4545
bb2: {
46-
- drop(_5) -> [return: bb3, unwind: bb8]; // scope 2 at $DIR/issue_41110.rs:+4:9: +4:10
47-
+ goto -> bb3; // scope 2 at $DIR/issue_41110.rs:+4:9: +4:10
46+
_2 = move _5; // scope 2 at $DIR/issue_41110.rs:+4:5: +4:6
47+
- drop(_5) -> [return: bb4, unwind: bb8]; // scope 2 at $DIR/issue_41110.rs:+4:9: +4:10
48+
+ goto -> bb4; // scope 2 at $DIR/issue_41110.rs:+4:9: +4:10
49+
}
50+
51+
bb3 (cleanup): {
52+
_2 = move _5; // scope 2 at $DIR/issue_41110.rs:+4:5: +4:6
53+
drop(_5) -> bb8; // scope 2 at $DIR/issue_41110.rs:+4:9: +4:10
4854
}
4955

50-
bb3: {
56+
bb4: {
5157
StorageDead(_5); // scope 2 at $DIR/issue_41110.rs:+4:9: +4:10
5258
_0 = const (); // scope 0 at $DIR/issue_41110.rs:+0:15: +5:2
53-
drop(_2) -> [return: bb4, unwind: bb9]; // scope 1 at $DIR/issue_41110.rs:+5:1: +5:2
59+
drop(_2) -> [return: bb5, unwind: bb9]; // scope 1 at $DIR/issue_41110.rs:+5:1: +5:2
5460
}
5561

56-
bb4: {
62+
bb5: {
5763
StorageDead(_2); // scope 1 at $DIR/issue_41110.rs:+5:1: +5:2
58-
- drop(_1) -> bb5; // scope 0 at $DIR/issue_41110.rs:+5:1: +5:2
59-
+ goto -> bb5; // scope 0 at $DIR/issue_41110.rs:+5:1: +5:2
64+
- drop(_1) -> bb6; // scope 0 at $DIR/issue_41110.rs:+5:1: +5:2
65+
+ goto -> bb6; // scope 0 at $DIR/issue_41110.rs:+5:1: +5:2
6066
}
6167

62-
bb5: {
68+
bb6: {
6369
+ _6 = const false; // scope 0 at $DIR/issue_41110.rs:+5:1: +5:2
6470
StorageDead(_1); // scope 0 at $DIR/issue_41110.rs:+5:1: +5:2
6571
return; // scope 0 at $DIR/issue_41110.rs:+5:2: +5:2
6672
}
6773

68-
bb6 (cleanup): {
69-
drop(_5) -> bb8; // scope 2 at $DIR/issue_41110.rs:+4:9: +4:10
70-
}
71-
7274
bb7 (cleanup): {
7375
- drop(_4) -> bb8; // scope 2 at $DIR/issue_41110.rs:+3:11: +3:12
7476
+ goto -> bb8; // scope 2 at $DIR/issue_41110.rs:+3:11: +3:12
@@ -81,29 +83,19 @@
8183

8284
bb9 (cleanup): {
8385
- drop(_1) -> bb10; // scope 0 at $DIR/issue_41110.rs:+5:1: +5:2
84-
+ goto -> bb14; // scope 0 at $DIR/issue_41110.rs:+5:1: +5:2
86+
+ goto -> bb12; // scope 0 at $DIR/issue_41110.rs:+5:1: +5:2
8587
}
8688

8789
bb10 (cleanup): {
8890
resume; // scope 0 at $DIR/issue_41110.rs:+0:1: +5:2
8991
+ }
9092
+
9193
+ bb11 (cleanup): {
92-
+ _2 = move _5; // scope 2 at $DIR/issue_41110.rs:+4:5: +4:6
93-
+ goto -> bb10; // scope 2 at $DIR/issue_41110.rs:+4:5: +4:6
94-
+ }
95-
+
96-
+ bb12: {
97-
+ _2 = move _5; // scope 2 at $DIR/issue_41110.rs:+4:5: +4:6
98-
+ goto -> bb2; // scope 2 at $DIR/issue_41110.rs:+4:5: +4:6
99-
+ }
100-
+
101-
+ bb13 (cleanup): {
10294
+ drop(_1) -> bb10; // scope 0 at $DIR/issue_41110.rs:+5:1: +5:2
10395
+ }
10496
+
105-
+ bb14 (cleanup): {
106-
+ switchInt(_6) -> [0: bb10, otherwise: bb13]; // scope 0 at $DIR/issue_41110.rs:+5:1: +5:2
97+
+ bb12 (cleanup): {
98+
+ switchInt(_6) -> [0: bb10, otherwise: bb11]; // scope 0 at $DIR/issue_41110.rs:+5:1: +5:2
10799
}
108100
}
109101

‎tests/mir-opt/issue_41888.main.ElaborateDrops.diff

Lines changed: 40 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
}
3535

3636
bb1: {
37-
switchInt(move _2) -> [0: bb7, otherwise: bb2]; // scope 1 at $DIR/issue_41888.rs:+2:8: +2:14
37+
switchInt(move _2) -> [0: bb8, otherwise: bb2]; // scope 1 at $DIR/issue_41888.rs:+2:8: +2:14
3838
}
3939

4040
bb2: {
@@ -43,58 +43,63 @@
4343
_4 = K; // scope 1 at $DIR/issue_41888.rs:+3:18: +3:19
4444
_3 = E::F(move _4); // scope 1 at $DIR/issue_41888.rs:+3:13: +3:20
4545
StorageDead(_4); // scope 1 at $DIR/issue_41888.rs:+3:19: +3:20
46-
- replace(_1 <- move _3) -> [return: bb3, unwind: bb10]; // scope 1 at $DIR/issue_41888.rs:+3:9: +3:10
47-
+ goto -> bb14; // scope 1 at $DIR/issue_41888.rs:+3:9: +3:10
46+
- drop(_1) -> [return: bb3, unwind: bb4]; // scope 1 at $DIR/issue_41888.rs:+3:9: +3:10
47+
+ goto -> bb3; // scope 1 at $DIR/issue_41888.rs:+3:9: +3:10
4848
}
4949

5050
bb3: {
51-
- drop(_3) -> [return: bb4, unwind: bb11]; // scope 1 at $DIR/issue_41888.rs:+3:19: +3:20
52-
+ goto -> bb4; // scope 1 at $DIR/issue_41888.rs:+3:19: +3:20
51+
+ _7 = const true; // scope 1 at $DIR/issue_41888.rs:+3:9: +3:10
52+
+ _8 = const true; // scope 1 at $DIR/issue_41888.rs:+3:9: +3:10
53+
+ _9 = const true; // scope 1 at $DIR/issue_41888.rs:+3:9: +3:10
54+
_1 = move _3; // scope 1 at $DIR/issue_41888.rs:+3:9: +3:10
55+
- drop(_3) -> [return: bb5, unwind: bb11]; // scope 1 at $DIR/issue_41888.rs:+3:19: +3:20
56+
+ goto -> bb5; // scope 1 at $DIR/issue_41888.rs:+3:19: +3:20
57+
}
58+
59+
bb4 (cleanup): {
60+
_1 = move _3; // scope 1 at $DIR/issue_41888.rs:+3:9: +3:10
61+
drop(_3) -> bb11; // scope 1 at $DIR/issue_41888.rs:+3:19: +3:20
5362
}
5463

55-
bb4: {
64+
bb5: {
5665
StorageDead(_3); // scope 1 at $DIR/issue_41888.rs:+3:19: +3:20
5766
_5 = discriminant(_1); // scope 2 at $DIR/issue_41888.rs:+4:16: +4:24
58-
switchInt(move _5) -> [0: bb5, otherwise: bb6]; // scope 2 at $DIR/issue_41888.rs:+4:16: +4:24
67+
switchInt(move _5) -> [0: bb6, otherwise: bb7]; // scope 2 at $DIR/issue_41888.rs:+4:16: +4:24
5968
}
6069

61-
bb5: {
70+
bb6: {
6271
StorageLive(_6); // scope 2 at $DIR/issue_41888.rs:+4:21: +4:23
6372
+ _9 = const false; // scope 2 at $DIR/issue_41888.rs:+4:21: +4:23
6473
_6 = move ((_1 as F).0: K); // scope 2 at $DIR/issue_41888.rs:+4:21: +4:23
6574
_0 = const (); // scope 2 at $DIR/issue_41888.rs:+4:29: +7:10
6675
StorageDead(_6); // scope 1 at $DIR/issue_41888.rs:+7:9: +7:10
67-
goto -> bb8; // scope 1 at $DIR/issue_41888.rs:+4:9: +7:10
76+
goto -> bb9; // scope 1 at $DIR/issue_41888.rs:+4:9: +7:10
6877
}
6978

70-
bb6: {
79+
bb7: {
7180
_0 = const (); // scope 1 at $DIR/issue_41888.rs:+7:10: +7:10
72-
goto -> bb8; // scope 1 at $DIR/issue_41888.rs:+4:9: +7:10
81+
goto -> bb9; // scope 1 at $DIR/issue_41888.rs:+4:9: +7:10
7382
}
7483

75-
bb7: {
84+
bb8: {
7685
_0 = const (); // scope 1 at $DIR/issue_41888.rs:+8:6: +8:6
77-
goto -> bb8; // scope 1 at $DIR/issue_41888.rs:+2:5: +8:6
86+
goto -> bb9; // scope 1 at $DIR/issue_41888.rs:+2:5: +8:6
7887
}
7988

80-
bb8: {
89+
bb9: {
8190
StorageDead(_2); // scope 1 at $DIR/issue_41888.rs:+8:5: +8:6
82-
- drop(_1) -> bb9; // scope 0 at $DIR/issue_41888.rs:+9:1: +9:2
83-
+ goto -> bb20; // scope 0 at $DIR/issue_41888.rs:+9:1: +9:2
91+
- drop(_1) -> bb10; // scope 0 at $DIR/issue_41888.rs:+9:1: +9:2
92+
+ goto -> bb18; // scope 0 at $DIR/issue_41888.rs:+9:1: +9:2
8493
}
8594

86-
bb9: {
95+
bb10: {
8796
+ _7 = const false; // scope 0 at $DIR/issue_41888.rs:+9:1: +9:2
8897
+ _8 = const false; // scope 0 at $DIR/issue_41888.rs:+9:1: +9:2
8998
+ _9 = const false; // scope 0 at $DIR/issue_41888.rs:+9:1: +9:2
9099
StorageDead(_1); // scope 0 at $DIR/issue_41888.rs:+9:1: +9:2
91100
return; // scope 0 at $DIR/issue_41888.rs:+9:2: +9:2
92101
}
93102

94-
bb10 (cleanup): {
95-
drop(_3) -> bb11; // scope 1 at $DIR/issue_41888.rs:+3:19: +3:20
96-
}
97-
98103
bb11 (cleanup): {
99104
- drop(_1) -> bb12; // scope 0 at $DIR/issue_41888.rs:+9:1: +9:2
100105
+ goto -> bb12; // scope 0 at $DIR/issue_41888.rs:+9:1: +9:2
@@ -104,55 +109,39 @@
104109
resume; // scope 0 at $DIR/issue_41888.rs:+0:1: +9:2
105110
+ }
106111
+
107-
+ bb13 (cleanup): {
108-
+ _7 = const true; // scope 1 at $DIR/issue_41888.rs:+3:9: +3:10
109-
+ _8 = const true; // scope 1 at $DIR/issue_41888.rs:+3:9: +3:10
110-
+ _9 = const true; // scope 1 at $DIR/issue_41888.rs:+3:9: +3:10
111-
+ _1 = move _3; // scope 1 at $DIR/issue_41888.rs:+3:9: +3:10
112-
+ goto -> bb12; // scope 1 at $DIR/issue_41888.rs:+3:9: +3:10
113-
+ }
114-
+
115-
+ bb14: {
116-
+ _7 = const true; // scope 1 at $DIR/issue_41888.rs:+3:9: +3:10
117-
+ _8 = const true; // scope 1 at $DIR/issue_41888.rs:+3:9: +3:10
118-
+ _9 = const true; // scope 1 at $DIR/issue_41888.rs:+3:9: +3:10
119-
+ _1 = move _3; // scope 1 at $DIR/issue_41888.rs:+3:9: +3:10
120-
+ goto -> bb3; // scope 1 at $DIR/issue_41888.rs:+3:9: +3:10
121-
+ }
122-
+
123-
+ bb15: {
112+
+ bb13: {
124113
+ _7 = const false; // scope 0 at $DIR/issue_41888.rs:+9:1: +9:2
125-
+ goto -> bb9; // scope 0 at $DIR/issue_41888.rs:+9:1: +9:2
114+
+ goto -> bb10; // scope 0 at $DIR/issue_41888.rs:+9:1: +9:2
126115
+ }
127116
+
128-
+ bb16 (cleanup): {
117+
+ bb14 (cleanup): {
129118
+ goto -> bb12; // scope 0 at $DIR/issue_41888.rs:+9:1: +9:2
130119
+ }
131120
+
132-
+ bb17: {
133-
+ drop(_1) -> [return: bb15, unwind: bb12]; // scope 0 at $DIR/issue_41888.rs:+9:1: +9:2
121+
+ bb15: {
122+
+ drop(_1) -> [return: bb13, unwind: bb12]; // scope 0 at $DIR/issue_41888.rs:+9:1: +9:2
134123
+ }
135124
+
136-
+ bb18 (cleanup): {
125+
+ bb16 (cleanup): {
137126
+ drop(_1) -> bb12; // scope 0 at $DIR/issue_41888.rs:+9:1: +9:2
138127
+ }
139128
+
140-
+ bb19: {
129+
+ bb17: {
141130
+ _10 = discriminant(_1); // scope 0 at $DIR/issue_41888.rs:+9:1: +9:2
142-
+ switchInt(move _10) -> [0: bb15, otherwise: bb17]; // scope 0 at $DIR/issue_41888.rs:+9:1: +9:2
131+
+ switchInt(move _10) -> [0: bb13, otherwise: bb15]; // scope 0 at $DIR/issue_41888.rs:+9:1: +9:2
143132
+ }
144133
+
145-
+ bb20: {
146-
+ switchInt(_7) -> [0: bb15, otherwise: bb19]; // scope 0 at $DIR/issue_41888.rs:+9:1: +9:2
134+
+ bb18: {
135+
+ switchInt(_7) -> [0: bb13, otherwise: bb17]; // scope 0 at $DIR/issue_41888.rs:+9:1: +9:2
147136
+ }
148137
+
149-
+ bb21 (cleanup): {
138+
+ bb19 (cleanup): {
150139
+ _11 = discriminant(_1); // scope 0 at $DIR/issue_41888.rs:+9:1: +9:2
151-
+ switchInt(move _11) -> [0: bb16, otherwise: bb18]; // scope 0 at $DIR/issue_41888.rs:+9:1: +9:2
140+
+ switchInt(move _11) -> [0: bb14, otherwise: bb16]; // scope 0 at $DIR/issue_41888.rs:+9:1: +9:2
152141
+ }
153142
+
154-
+ bb22 (cleanup): {
155-
+ switchInt(_7) -> [0: bb12, otherwise: bb21]; // scope 0 at $DIR/issue_41888.rs:+9:1: +9:2
143+
+ bb20 (cleanup): {
144+
+ switchInt(_7) -> [0: bb12, otherwise: bb19]; // scope 0 at $DIR/issue_41888.rs:+9:1: +9:2
156145
}
157146
}
158147

‎tests/mir-opt/packed_struct_drop_aligned.main.SimplifyCfg-elaborate-drops.after.mir

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,28 @@ fn main() -> () {
2828
StorageDead(_5); // scope 1 at $DIR/packed_struct_drop_aligned.rs:+2:28: +2:29
2929
StorageLive(_6); // scope 1 at $DIR/packed_struct_drop_aligned.rs:+2:5: +2:8
3030
_6 = move (_1.0: Aligned); // scope 1 at $DIR/packed_struct_drop_aligned.rs:+2:5: +2:8
31-
drop(_6) -> [return: bb4, unwind: bb3]; // scope 1 at $DIR/packed_struct_drop_aligned.rs:+2:5: +2:8
31+
drop(_6) -> [return: bb4, unwind: bb1]; // scope 1 at $DIR/packed_struct_drop_aligned.rs:+2:5: +2:8
3232
}
3333

34-
bb1: {
35-
StorageDead(_1); // scope 0 at $DIR/packed_struct_drop_aligned.rs:+3:1: +3:2
36-
return; // scope 0 at $DIR/packed_struct_drop_aligned.rs:+3:2: +3:2
34+
bb1 (cleanup): {
35+
(_1.0: Aligned) = move _4; // scope 1 at $DIR/packed_struct_drop_aligned.rs:+2:5: +2:8
36+
drop(_1) -> bb3; // scope 0 at $DIR/packed_struct_drop_aligned.rs:+3:1: +3:2
3737
}
3838

39-
bb2 (cleanup): {
40-
resume; // scope 0 at $DIR/packed_struct_drop_aligned.rs:+0:1: +3:2
39+
bb2: {
40+
StorageDead(_1); // scope 0 at $DIR/packed_struct_drop_aligned.rs:+3:1: +3:2
41+
return; // scope 0 at $DIR/packed_struct_drop_aligned.rs:+3:2: +3:2
4142
}
4243

4344
bb3 (cleanup): {
44-
(_1.0: Aligned) = move _4; // scope 1 at $DIR/packed_struct_drop_aligned.rs:+2:5: +2:8
45-
drop(_1) -> bb2; // scope 0 at $DIR/packed_struct_drop_aligned.rs:+3:1: +3:2
45+
resume; // scope 0 at $DIR/packed_struct_drop_aligned.rs:+0:1: +3:2
4646
}
4747

4848
bb4: {
4949
StorageDead(_6); // scope 1 at $DIR/packed_struct_drop_aligned.rs:+2:5: +2:8
5050
(_1.0: Aligned) = move _4; // scope 1 at $DIR/packed_struct_drop_aligned.rs:+2:5: +2:8
5151
StorageDead(_4); // scope 1 at $DIR/packed_struct_drop_aligned.rs:+2:28: +2:29
5252
_0 = const (); // scope 0 at $DIR/packed_struct_drop_aligned.rs:+0:11: +3:2
53-
drop(_1) -> [return: bb1, unwind: bb2]; // scope 0 at $DIR/packed_struct_drop_aligned.rs:+3:1: +3:2
53+
drop(_1) -> [return: bb2, unwind: bb3]; // scope 0 at $DIR/packed_struct_drop_aligned.rs:+3:1: +3:2
5454
}
5555
}

‎tests/run-make/coverage-reports/expected_show_coverage.closure.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
29| 1| some_string = Some(String::from("the string content"));
3030
30| 1| let
3131
31| 1| a
32-
32| 1| =
33-
33| 1| ||
32+
32| | =
33+
33| | ||
3434
34| 0| {
3535
35| 0| let mut countdown = 0;
3636
36| 0| if is_false {

‎tests/ui/borrowck/borrowck-vec-pattern-nesting.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ fn a() {
88
//~^ NOTE `vec[_]` is borrowed here
99
vec[0] = Box::new(4); //~ ERROR cannot assign
1010
//~^ NOTE `vec[_]` is assigned to here
11+
//~| NOTE in this expansion of desugaring of drop and replace
1112
_a.use_ref();
1213
//~^ NOTE borrow later used here
1314
}
@@ -22,6 +23,7 @@ fn b() {
2223
//~^ `vec[_]` is borrowed here
2324
vec[0] = Box::new(4); //~ ERROR cannot assign
2425
//~^ NOTE `vec[_]` is assigned to here
26+
//~| NOTE in this expansion of desugaring of drop and replace
2527
_b.use_ref();
2628
//~^ NOTE borrow later used here
2729
}

‎tests/ui/borrowck/borrowck-vec-pattern-nesting.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@ LL | [box ref _a, _, _] => {
66
LL |
77
LL | vec[0] = Box::new(4);
88
| ^^^^^^ `vec[_]` is assigned to here but it was already borrowed
9-
LL |
9+
...
1010
LL | _a.use_ref();
1111
| ------------ borrow later used here
1212

1313
error[E0506]: cannot assign to `vec[_]` because it is borrowed
14-
--> $DIR/borrowck-vec-pattern-nesting.rs:23:13
14+
--> $DIR/borrowck-vec-pattern-nesting.rs:24:13
1515
|
1616
LL | &mut [ref _b @ ..] => {
1717
| ------ `vec[_]` is borrowed here
1818
LL |
1919
LL | vec[0] = Box::new(4);
2020
| ^^^^^^ `vec[_]` is assigned to here but it was already borrowed
21-
LL |
21+
...
2222
LL | _b.use_ref();
2323
| ------------ borrow later used here
2424

2525
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
26-
--> $DIR/borrowck-vec-pattern-nesting.rs:34:11
26+
--> $DIR/borrowck-vec-pattern-nesting.rs:36:11
2727
|
2828
LL | match vec {
2929
| ^^^ cannot move out of here
@@ -41,7 +41,7 @@ LL + [_a,
4141
|
4242

4343
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
44-
--> $DIR/borrowck-vec-pattern-nesting.rs:46:13
44+
--> $DIR/borrowck-vec-pattern-nesting.rs:48:13
4545
|
4646
LL | let a = vec[0];
4747
| ^^^^^^
@@ -55,7 +55,7 @@ LL | let a = &vec[0];
5555
| +
5656

5757
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
58-
--> $DIR/borrowck-vec-pattern-nesting.rs:55:11
58+
--> $DIR/borrowck-vec-pattern-nesting.rs:57:11
5959
|
6060
LL | match vec {
6161
| ^^^ cannot move out of here
@@ -73,7 +73,7 @@ LL + [
7373
|
7474

7575
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
76-
--> $DIR/borrowck-vec-pattern-nesting.rs:65:13
76+
--> $DIR/borrowck-vec-pattern-nesting.rs:67:13
7777
|
7878
LL | let a = vec[0];
7979
| ^^^^^^
@@ -87,7 +87,7 @@ LL | let a = &vec[0];
8787
| +
8888

8989
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
90-
--> $DIR/borrowck-vec-pattern-nesting.rs:74:11
90+
--> $DIR/borrowck-vec-pattern-nesting.rs:76:11
9191
|
9292
LL | match vec {
9393
| ^^^ cannot move out of here
@@ -106,7 +106,7 @@ LL + [_a, _b, _c] => {}
106106
|
107107

108108
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
109-
--> $DIR/borrowck-vec-pattern-nesting.rs:85:13
109+
--> $DIR/borrowck-vec-pattern-nesting.rs:87:13
110110
|
111111
LL | let a = vec[0];
112112
| ^^^^^^

‎tests/ui/borrowck/issue-45199.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ fn test_drop_replace() {
55
b = Box::new(1); //~ NOTE first assignment
66
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
77
//~| NOTE cannot assign twice to immutable
8+
//~| NOTE in this expansion of desugaring of drop and replace
89
}
910

1011
fn test_call() {
@@ -13,12 +14,14 @@ fn test_call() {
1314
//~| SUGGESTION mut b
1415
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
1516
//~| NOTE cannot assign twice to immutable
17+
//~| NOTE in this expansion of desugaring of drop and replace
1618
}
1719

1820
fn test_args(b: Box<i32>) { //~ HELP consider making this binding mutable
1921
//~| SUGGESTION mut b
2022
b = Box::new(2); //~ ERROR cannot assign to immutable argument `b`
2123
//~| NOTE cannot assign to immutable argument
24+
//~| NOTE in this expansion of desugaring of drop and replace
2225
}
2326

2427
fn main() {}

‎tests/ui/borrowck/issue-45199.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LL | b = Box::new(2);
1010
| ^ cannot assign twice to immutable variable
1111

1212
error[E0384]: cannot assign twice to immutable variable `b`
13-
--> $DIR/issue-45199.rs:14:5
13+
--> $DIR/issue-45199.rs:15:5
1414
|
1515
LL | let b = Box::new(1);
1616
| -
@@ -22,7 +22,7 @@ LL | b = Box::new(2);
2222
| ^ cannot assign twice to immutable variable
2323

2424
error[E0384]: cannot assign to immutable argument `b`
25-
--> $DIR/issue-45199.rs:20:5
25+
--> $DIR/issue-45199.rs:22:5
2626
|
2727
LL | fn test_args(b: Box<i32>) {
2828
| - help: consider making this binding mutable: `mut b`

‎tests/ui/borrowck/issue-58776-borrowck-scans-children.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ fn main() {
55
greeting = "DEALLOCATED".to_string();
66
//~^ ERROR cannot assign
77
drop(greeting);
8-
//~^ ERROR cannot move
98

109
println!("thread result: {:?}", res);
1110
}

‎tests/ui/borrowck/issue-58776-borrowck-scans-children.stderr

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,6 @@ LL | greeting = "DEALLOCATED".to_string();
1212
LL | println!("thread result: {:?}", res);
1313
| --- borrow later used here
1414

15-
error[E0505]: cannot move out of `greeting` because it is borrowed
16-
--> $DIR/issue-58776-borrowck-scans-children.rs:7:10
17-
|
18-
LL | let res = (|| (|| &greeting)())();
19-
| -- -------- borrow occurs due to use in closure
20-
| |
21-
| borrow of `greeting` occurs here
22-
...
23-
LL | drop(greeting);
24-
| ^^^^^^^^ move out of `greeting` occurs here
25-
...
26-
LL | println!("thread result: {:?}", res);
27-
| --- borrow later used here
28-
29-
error: aborting due to 2 previous errors
15+
error: aborting due to previous error
3016

31-
Some errors have detailed explanations: E0505, E0506.
32-
For more information about an error, try `rustc --explain E0505`.
17+
For more information about this error, try `rustc --explain E0506`.

‎tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-drop.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ fn test() {
55
drop(b);
66
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
77
//~| NOTE cannot assign twice to immutable
8+
//~| NOTE in this expansion of desugaring of drop and replace
89
drop(b);
910
}
1011

0 commit comments

Comments
 (0)
Please sign in to comment.