diff --git a/compiler/rustc_mir_build/src/build/matches/simplify.rs b/compiler/rustc_mir_build/src/build/matches/simplify.rs index 296051b173e..278d7a6374d 100644 --- a/compiler/rustc_mir_build/src/build/matches/simplify.rs +++ b/compiler/rustc_mir_build/src/build/matches/simplify.rs @@ -44,6 +44,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { candidate: &mut Candidate<'pat, 'tcx>, ) -> bool { // repeatedly simplify match pairs until fixed point is reached + debug!("simplify_candidate(candidate={:?})", candidate); + let mut new_bindings = Vec::new(); loop { let match_pairs = mem::take(&mut candidate.match_pairs); @@ -56,7 +58,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let mut changed = false; for match_pair in match_pairs { - match self.simplify_match_pair(match_pair, candidate) { + match self.simplify_match_pair(match_pair, candidate, &mut new_bindings) { Ok(()) => { changed = true; } @@ -65,6 +67,23 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } } } + // issue #69971: the binding order should be right to left if there are more + // bindings after `@` to please the borrow checker + // Ex + // struct NonCopyStruct { + // copy_field: u32, + // } + // + // fn foo1(x: NonCopyStruct) { + // let y @ NonCopyStruct { copy_field: z } = x; + // // the above should turn into + // let z = x.copy_field; + // let y = x; + // } + new_bindings.extend_from_slice(&candidate.bindings); + mem::swap(&mut candidate.bindings, &mut new_bindings); + new_bindings.clear(); + if !changed { // Move or-patterns to the end, because they can result in us // creating additional candidates, so we want to test them as @@ -72,6 +91,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { candidate .match_pairs .sort_by_key(|pair| matches!(*pair.pattern.kind, PatKind::Or { .. })); + debug!("simplify_candidate: simplifed {:?}", candidate); return false; // if we were not able to simplify any, done. } } @@ -104,6 +124,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { &mut self, match_pair: MatchPair<'pat, 'tcx>, candidate: &mut Candidate<'pat, 'tcx>, + bindings: &mut Vec>, ) -> Result<(), MatchPair<'pat, 'tcx>> { let tcx = self.hir.tcx(); match *match_pair.pattern.kind { @@ -131,20 +152,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } PatKind::Binding { name, mutability, mode, var, ty, ref subpattern, is_primary: _ } => { - // issue #69971: the binding order should be right to left if there are more - // bindings after `@` to please the borrow checker - // Ex - // struct NonCopyStruct { - // copy_field: u32, - // } - // - // fn foo1(x: NonCopyStruct) { - // let y @ NonCopyStruct { copy_field: z } = x; - // // the above should turn into - // let z = x.copy_field; - // let y = x; - // } - candidate.bindings.insert(0, Binding { + bindings.push(Binding { name, mutability, span: match_pair.pattern.span, diff --git a/src/test/mir-opt/exponential_or.match_tuple.SimplifyCfg-initial.after.mir b/src/test/mir-opt/exponential_or.match_tuple.SimplifyCfg-initial.after.mir index f83acf723f5..0db0f8349bb 100644 --- a/src/test/mir-opt/exponential_or.match_tuple.SimplifyCfg-initial.after.mir +++ b/src/test/mir-opt/exponential_or.match_tuple.SimplifyCfg-initial.after.mir @@ -61,10 +61,10 @@ fn match_tuple(_1: (u32, bool, Option, u32)) -> u32 { } bb9: { - StorageLive(_8); // scope 0 at $DIR/exponential-or.rs:8:57: 8:78 - _8 = (_1.3: u32); // scope 0 at $DIR/exponential-or.rs:8:57: 8:78 StorageLive(_7); // scope 0 at $DIR/exponential-or.rs:8:10: 8:21 _7 = (_1.0: u32); // scope 0 at $DIR/exponential-or.rs:8:10: 8:21 + StorageLive(_8); // scope 0 at $DIR/exponential-or.rs:8:57: 8:78 + _8 = (_1.3: u32); // scope 0 at $DIR/exponential-or.rs:8:57: 8:78 StorageLive(_9); // scope 1 at $DIR/exponential-or.rs:8:83: 8:84 _9 = _7; // scope 1 at $DIR/exponential-or.rs:8:83: 8:84 StorageLive(_10); // scope 1 at $DIR/exponential-or.rs:8:87: 8:88 @@ -72,8 +72,8 @@ fn match_tuple(_1: (u32, bool, Option, u32)) -> u32 { _0 = BitXor(move _9, move _10); // scope 1 at $DIR/exponential-or.rs:8:83: 8:88 StorageDead(_10); // scope 1 at $DIR/exponential-or.rs:8:87: 8:88 StorageDead(_9); // scope 1 at $DIR/exponential-or.rs:8:87: 8:88 - StorageDead(_7); // scope 0 at $DIR/exponential-or.rs:8:87: 8:88 StorageDead(_8); // scope 0 at $DIR/exponential-or.rs:8:87: 8:88 + StorageDead(_7); // scope 0 at $DIR/exponential-or.rs:8:87: 8:88 goto -> bb10; // scope 0 at $DIR/exponential-or.rs:7:5: 10:6 } diff --git a/src/test/mir-opt/issue_73223.main.PreCodegen.64bit.diff b/src/test/mir-opt/issue_73223.main.PreCodegen.64bit.diff index 08ad18fd0a7..23aefe07892 100644 --- a/src/test/mir-opt/issue_73223.main.PreCodegen.64bit.diff +++ b/src/test/mir-opt/issue_73223.main.PreCodegen.64bit.diff @@ -89,10 +89,10 @@ // + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL // + literal: Const { ty: &i32, val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main), const_param_did: None }, [], Some(promoted[1])) } (_5.1: &i32) = move _6; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL - StorageLive(_8); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL - _8 = (_5.1: &i32); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL StorageLive(_7); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL _7 = (_5.0: &i32); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL + StorageLive(_8); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL + _8 = (_5.1: &i32); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL StorageLive(_9); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL StorageLive(_10); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL StorageLive(_11); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL @@ -106,8 +106,8 @@ bb1: { StorageDead(_9); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL - StorageDead(_7); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL StorageDead(_8); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL + StorageDead(_7); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL _0 = const (); // scope 0 at $DIR/issue-73223.rs:1:11: 9:2 StorageDead(_1); // scope 0 at $DIR/issue-73223.rs:9:1: 9:2 return; // scope 0 at $DIR/issue-73223.rs:9:2: 9:2 @@ -133,8 +133,8 @@ _19 = &_20; // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL (_17.1: &&i32) = move _19; // scope 4 at $SRC_DIR/std/src/macros.rs:LL:COL StorageDead(_19); // scope 4 at $SRC_DIR/std/src/macros.rs:LL:COL - _28 = (_17.1: &&i32); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL _25 = (_17.0: &&i32); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL + _28 = (_17.1: &&i32); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL _24 = <&i32 as Debug>::fmt as for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> (Pointer(ReifyFnPointer)); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL // mir::Constant // + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL diff --git a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff index 9a825abd261..b9cb58e14c4 100644 --- a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff +++ b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff @@ -138,10 +138,10 @@ (_9.1: &i32) = move _11; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL StorageDead(_11); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL StorageDead(_10); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL - StorageLive(_14); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL - _14 = (_9.1: &i32); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL StorageLive(_13); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL _13 = (_9.0: &i32); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL + StorageLive(_14); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL + _14 = (_9.1: &i32); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL StorageLive(_15); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL StorageLive(_16); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL StorageLive(_17); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL @@ -159,8 +159,8 @@ bb3: { _8 = const (); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL StorageDead(_15); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL - StorageDead(_13); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL StorageDead(_14); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL + StorageDead(_13); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL StorageDead(_9); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL StorageDead(_8); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL _0 = const (); // scope 0 at $DIR/issue-73223.rs:1:11: 9:2 @@ -205,10 +205,10 @@ (_31.1: &&i32) = move _34; // scope 4 at $SRC_DIR/std/src/macros.rs:LL:COL StorageDead(_34); // scope 4 at $SRC_DIR/std/src/macros.rs:LL:COL StorageDead(_32); // scope 4 at $SRC_DIR/std/src/macros.rs:LL:COL - StorageLive(_37); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL - _37 = (_31.1: &&i32); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL StorageLive(_36); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL _36 = (_31.0: &&i32); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL + StorageLive(_37); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL + _37 = (_31.1: &&i32); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL StorageLive(_38); // scope 5 at $SRC_DIR/std/src/macros.rs:LL:COL StorageLive(_39); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL _39 = _36; // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL @@ -284,8 +284,8 @@ _30 = [move _38, move _41]; // scope 5 at $SRC_DIR/std/src/macros.rs:LL:COL StorageDead(_41); // scope 5 at $SRC_DIR/std/src/macros.rs:LL:COL StorageDead(_38); // scope 5 at $SRC_DIR/std/src/macros.rs:LL:COL - StorageDead(_36); // scope 4 at $SRC_DIR/std/src/macros.rs:LL:COL StorageDead(_37); // scope 4 at $SRC_DIR/std/src/macros.rs:LL:COL + StorageDead(_36); // scope 4 at $SRC_DIR/std/src/macros.rs:LL:COL _29 = &_30; // scope 4 at $SRC_DIR/std/src/macros.rs:LL:COL _28 = _29; // scope 4 at $SRC_DIR/std/src/macros.rs:LL:COL _27 = move _28 as &[std::fmt::ArgumentV1] (Pointer(Unsize)); // scope 4 at $SRC_DIR/std/src/macros.rs:LL:COL diff --git a/src/test/mir-opt/issue_76432.test.SimplifyComparisonIntegral.diff b/src/test/mir-opt/issue_76432.test.SimplifyComparisonIntegral.diff index c4582cc6b52..499134b6991 100644 --- a/src/test/mir-opt/issue_76432.test.SimplifyComparisonIntegral.diff +++ b/src/test/mir-opt/issue_76432.test.SimplifyComparisonIntegral.diff @@ -78,12 +78,12 @@ } bb2: { - StorageLive(_15); // scope 1 at $DIR/issue_76432.rs:9:26: 9:32 - _15 = &(*_2)[2 of 3]; // scope 1 at $DIR/issue_76432.rs:9:26: 9:32 - StorageLive(_14); // scope 1 at $DIR/issue_76432.rs:9:18: 9:24 - _14 = &(*_2)[1 of 3]; // scope 1 at $DIR/issue_76432.rs:9:18: 9:24 StorageLive(_13); // scope 1 at $DIR/issue_76432.rs:9:10: 9:16 _13 = &(*_2)[0 of 3]; // scope 1 at $DIR/issue_76432.rs:9:10: 9:16 + StorageLive(_14); // scope 1 at $DIR/issue_76432.rs:9:18: 9:24 + _14 = &(*_2)[1 of 3]; // scope 1 at $DIR/issue_76432.rs:9:18: 9:24 + StorageLive(_15); // scope 1 at $DIR/issue_76432.rs:9:26: 9:32 + _15 = &(*_2)[2 of 3]; // scope 1 at $DIR/issue_76432.rs:9:26: 9:32 StorageLive(_16); // scope 2 at $DIR/issue_76432.rs:9:38: 9:52 StorageLive(_17); // scope 2 at $DIR/issue_76432.rs:9:38: 9:52 _17 = &raw const (*_13); // scope 2 at $DIR/issue_76432.rs:9:38: 9:40 @@ -103,9 +103,9 @@ StorageDead(_18); // scope 2 at $DIR/issue_76432.rs:9:84: 9:85 StorageDead(_17); // scope 2 at $DIR/issue_76432.rs:9:84: 9:85 StorageDead(_16); // scope 2 at $DIR/issue_76432.rs:9:84: 9:85 - StorageDead(_13); // scope 1 at $DIR/issue_76432.rs:9:84: 9:85 - StorageDead(_14); // scope 1 at $DIR/issue_76432.rs:9:84: 9:85 StorageDead(_15); // scope 1 at $DIR/issue_76432.rs:9:84: 9:85 + StorageDead(_14); // scope 1 at $DIR/issue_76432.rs:9:84: 9:85 + StorageDead(_13); // scope 1 at $DIR/issue_76432.rs:9:84: 9:85 StorageDead(_9); // scope 1 at $DIR/issue_76432.rs:11:6: 11:7 _0 = const (); // scope 0 at $DIR/issue_76432.rs:6:44: 12:2 StorageDead(_5); // scope 0 at $DIR/issue_76432.rs:12:1: 12:2 diff --git a/src/test/mir-opt/match_arm_scopes.complicated_match.SimplifyCfg-initial.after-ElaborateDrops.after.diff b/src/test/mir-opt/match_arm_scopes.complicated_match.SimplifyCfg-initial.after-ElaborateDrops.after.diff index 4d13cd54b21..4e7cd77035e 100644 --- a/src/test/mir-opt/match_arm_scopes.complicated_match.SimplifyCfg-initial.after-ElaborateDrops.after.diff +++ b/src/test/mir-opt/match_arm_scopes.complicated_match.SimplifyCfg-initial.after-ElaborateDrops.after.diff @@ -59,10 +59,10 @@ - } - - bb6: { - StorageLive(_16); // scope 0 at $DIR/match-arm-scopes.rs:16:35: 16:36 - _16 = move (_2.2: std::string::String); // scope 0 at $DIR/match-arm-scopes.rs:16:35: 16:36 StorageLive(_15); // scope 0 at $DIR/match-arm-scopes.rs:16:32: 16:33 _15 = (_2.1: bool); // scope 0 at $DIR/match-arm-scopes.rs:16:32: 16:33 + StorageLive(_16); // scope 0 at $DIR/match-arm-scopes.rs:16:35: 16:36 + _16 = move (_2.2: std::string::String); // scope 0 at $DIR/match-arm-scopes.rs:16:35: 16:36 - goto -> bb21; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 17:6 + goto -> bb16; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 17:6 } @@ -70,17 +70,16 @@ - bb7: { + bb4: { _0 = const 1_i32; // scope 1 at $DIR/match-arm-scopes.rs:15:77: 15:78 - StorageDead(_5); // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 - drop(_7) -> [return: bb20, unwind: bb27]; // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 + drop(_7) -> [return: bb15, unwind: bb22]; // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 } - bb8: { + bb5: { - StorageLive(_8); // scope 0 at $DIR/match-arm-scopes.rs:15:20: 15:21 - _8 = &(_2.2: std::string::String); // scope 0 at $DIR/match-arm-scopes.rs:15:20: 15:21 StorageLive(_6); // scope 0 at $DIR/match-arm-scopes.rs:15:17: 15:18 _6 = &(_2.1: bool); // scope 0 at $DIR/match-arm-scopes.rs:15:17: 15:18 + StorageLive(_8); // scope 0 at $DIR/match-arm-scopes.rs:15:20: 15:21 + _8 = &(_2.2: std::string::String); // scope 0 at $DIR/match-arm-scopes.rs:15:20: 15:21 - _3 = &shallow (_2.0: bool); // scope 0 at $DIR/match-arm-scopes.rs:14:11: 14:16 - _4 = &shallow (_2.1: bool); // scope 0 at $DIR/match-arm-scopes.rs:14:11: 14:16 StorageLive(_9); // scope 0 at $DIR/match-arm-scopes.rs:15:42: 15:73 @@ -117,12 +116,12 @@ StorageDead(_9); // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 - FakeRead(ForMatchGuard, _3); // scope 0 at $DIR/match-arm-scopes.rs:15:72: 15:73 - FakeRead(ForMatchGuard, _4); // scope 0 at $DIR/match-arm-scopes.rs:15:72: 15:73 -- FakeRead(ForGuardBinding, _8); // scope 0 at $DIR/match-arm-scopes.rs:15:72: 15:73 - FakeRead(ForGuardBinding, _6); // scope 0 at $DIR/match-arm-scopes.rs:15:72: 15:73 - StorageLive(_7); // scope 0 at $DIR/match-arm-scopes.rs:15:20: 15:21 - _7 = move (_2.2: std::string::String); // scope 0 at $DIR/match-arm-scopes.rs:15:20: 15:21 +- FakeRead(ForGuardBinding, _8); // scope 0 at $DIR/match-arm-scopes.rs:15:72: 15:73 StorageLive(_5); // scope 0 at $DIR/match-arm-scopes.rs:15:17: 15:18 _5 = (_2.1: bool); // scope 0 at $DIR/match-arm-scopes.rs:15:17: 15:18 + StorageLive(_7); // scope 0 at $DIR/match-arm-scopes.rs:15:20: 15:21 + _7 = move (_2.2: std::string::String); // scope 0 at $DIR/match-arm-scopes.rs:15:20: 15:21 - goto -> bb7; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 17:6 + goto -> bb4; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 17:6 } @@ -130,18 +129,18 @@ - bb13: { + bb9: { StorageDead(_9); // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 - StorageDead(_6); // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 StorageDead(_8); // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 + StorageDead(_6); // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 - falseEdge -> [real: bb2, imaginary: bb3]; // scope 0 at $DIR/match-arm-scopes.rs:15:42: 15:73 + goto -> bb1; // scope 0 at $DIR/match-arm-scopes.rs:15:42: 15:73 } - bb14: { + bb10: { - StorageLive(_8); // scope 0 at $DIR/match-arm-scopes.rs:15:36: 15:37 - _8 = &(_2.2: std::string::String); // scope 0 at $DIR/match-arm-scopes.rs:15:36: 15:37 StorageLive(_6); // scope 0 at $DIR/match-arm-scopes.rs:15:26: 15:27 _6 = &(_2.0: bool); // scope 0 at $DIR/match-arm-scopes.rs:15:26: 15:27 + StorageLive(_8); // scope 0 at $DIR/match-arm-scopes.rs:15:36: 15:37 + _8 = &(_2.2: std::string::String); // scope 0 at $DIR/match-arm-scopes.rs:15:36: 15:37 - _3 = &shallow (_2.0: bool); // scope 0 at $DIR/match-arm-scopes.rs:14:11: 14:16 - _4 = &shallow (_2.1: bool); // scope 0 at $DIR/match-arm-scopes.rs:14:11: 14:16 StorageLive(_12); // scope 0 at $DIR/match-arm-scopes.rs:15:42: 15:73 @@ -178,12 +177,12 @@ StorageDead(_12); // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 - FakeRead(ForMatchGuard, _3); // scope 0 at $DIR/match-arm-scopes.rs:15:72: 15:73 - FakeRead(ForMatchGuard, _4); // scope 0 at $DIR/match-arm-scopes.rs:15:72: 15:73 -- FakeRead(ForGuardBinding, _8); // scope 0 at $DIR/match-arm-scopes.rs:15:72: 15:73 - FakeRead(ForGuardBinding, _6); // scope 0 at $DIR/match-arm-scopes.rs:15:72: 15:73 - StorageLive(_7); // scope 0 at $DIR/match-arm-scopes.rs:15:36: 15:37 - _7 = move (_2.2: std::string::String); // scope 0 at $DIR/match-arm-scopes.rs:15:36: 15:37 +- FakeRead(ForGuardBinding, _8); // scope 0 at $DIR/match-arm-scopes.rs:15:72: 15:73 StorageLive(_5); // scope 0 at $DIR/match-arm-scopes.rs:15:26: 15:27 _5 = (_2.0: bool); // scope 0 at $DIR/match-arm-scopes.rs:15:26: 15:27 + StorageLive(_7); // scope 0 at $DIR/match-arm-scopes.rs:15:36: 15:37 + _7 = move (_2.2: std::string::String); // scope 0 at $DIR/match-arm-scopes.rs:15:36: 15:37 - goto -> bb7; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 17:6 + goto -> bb4; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 17:6 } @@ -191,8 +190,8 @@ - bb19: { + bb14: { StorageDead(_12); // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 - StorageDead(_6); // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 StorageDead(_8); // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 + StorageDead(_6); // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 - falseEdge -> [real: bb4, imaginary: bb5]; // scope 0 at $DIR/match-arm-scopes.rs:15:42: 15:73 + goto -> bb2; // scope 0 at $DIR/match-arm-scopes.rs:15:42: 15:73 } @@ -200,8 +199,9 @@ - bb20: { + bb15: { StorageDead(_7); // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 - StorageDead(_6); // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 + StorageDead(_5); // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 StorageDead(_8); // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 + StorageDead(_6); // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 - goto -> bb24; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 17:6 + goto -> bb19; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 17:6 } @@ -209,17 +209,16 @@ - bb21: { + bb16: { _0 = const 2_i32; // scope 2 at $DIR/match-arm-scopes.rs:16:41: 16:42 - StorageDead(_15); // scope 0 at $DIR/match-arm-scopes.rs:16:41: 16:42 - drop(_16) -> [return: bb23, unwind: bb27]; // scope 0 at $DIR/match-arm-scopes.rs:16:41: 16:42 + drop(_16) -> [return: bb18, unwind: bb22]; // scope 0 at $DIR/match-arm-scopes.rs:16:41: 16:42 } - bb22: { + bb17: { - StorageLive(_16); // scope 0 at $DIR/match-arm-scopes.rs:16:19: 16:20 - _16 = move (_2.2: std::string::String); // scope 0 at $DIR/match-arm-scopes.rs:16:19: 16:20 StorageLive(_15); // scope 0 at $DIR/match-arm-scopes.rs:16:16: 16:17 _15 = (_2.1: bool); // scope 0 at $DIR/match-arm-scopes.rs:16:16: 16:17 + StorageLive(_16); // scope 0 at $DIR/match-arm-scopes.rs:16:19: 16:20 + _16 = move (_2.2: std::string::String); // scope 0 at $DIR/match-arm-scopes.rs:16:19: 16:20 - goto -> bb21; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 17:6 + goto -> bb16; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 17:6 } @@ -227,6 +226,7 @@ - bb23: { + bb18: { StorageDead(_16); // scope 0 at $DIR/match-arm-scopes.rs:16:41: 16:42 + StorageDead(_15); // scope 0 at $DIR/match-arm-scopes.rs:16:41: 16:42 - goto -> bb24; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 17:6 + goto -> bb19; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 17:6 } @@ -239,8 +239,8 @@ - bb25: { + bb20: { - StorageDead(_6); // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 StorageDead(_8); // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 + StorageDead(_6); // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 - drop(_2) -> [return: bb26, unwind: bb28]; // scope 0 at $DIR/match-arm-scopes.rs:18:1: 18:2 + drop(_2) -> [return: bb21, unwind: bb23]; // scope 0 at $DIR/match-arm-scopes.rs:18:1: 18:2 } diff --git a/src/test/ui/borrowck/borrowck-move-error-with-note.stderr b/src/test/ui/borrowck/borrowck-move-error-with-note.stderr index de410a8b312..ead02414a62 100644 --- a/src/test/ui/borrowck/borrowck-move-error-with-note.stderr +++ b/src/test/ui/borrowck/borrowck-move-error-with-note.stderr @@ -1,4 +1,4 @@ -error[E0507]: cannot move out of `f.1` which is behind a shared reference +error[E0507]: cannot move out of `f.0` which is behind a shared reference --> $DIR/borrowck-move-error-with-note.rs:11:11 | LL | match *f { diff --git a/src/test/ui/borrowck/borrowck-slice-pattern-element-loan-slice.stderr b/src/test/ui/borrowck/borrowck-slice-pattern-element-loan-slice.stderr index f7fa467c468..d3388e071aa 100644 --- a/src/test/ui/borrowck/borrowck-slice-pattern-element-loan-slice.stderr +++ b/src/test/ui/borrowck/borrowck-slice-pattern-element-loan-slice.stderr @@ -32,23 +32,23 @@ error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as im --> $DIR/borrowck-slice-pattern-element-loan-slice.rs:25:23 | LL | if let [.., _, ref from_end4, ref from_end3, _, ref from_end1] = *s { - | ------------- immutable borrow occurs here + | ------------- immutable borrow occurs here ... LL | if let [_, _, ref mut from_begin2, ..] = *s { | ^^^^^^^^^^^^^^^^^^^ mutable borrow occurs here LL | nop(&[from_begin2, from_end1, from_end3, from_end4]); - | --------- immutable borrow later used here + | --------- immutable borrow later used here error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as immutable --> $DIR/borrowck-slice-pattern-element-loan-slice.rs:28:26 | LL | if let [.., _, ref from_end4, ref from_end3, _, ref from_end1] = *s { - | ------------- immutable borrow occurs here + | ------------- immutable borrow occurs here ... LL | if let [_, _, _, ref mut from_begin3, ..] = *s { | ^^^^^^^^^^^^^^^^^^^ mutable borrow occurs here LL | nop(&[from_begin3, from_end1, from_end3, from_end4]); - | --------- immutable borrow later used here + | --------- immutable borrow later used here error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as immutable --> $DIR/borrowck-slice-pattern-element-loan-slice.rs:33:21 @@ -75,12 +75,12 @@ error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as im --> $DIR/borrowck-slice-pattern-element-loan-slice.rs:39:21 | LL | if let [ref from_begin0, ref from_begin1, _, ref from_begin3, _, ..] = *s { - | --------------- immutable borrow occurs here + | --------------- immutable borrow occurs here ... LL | if let [.., ref mut from_end4, _, _, _] = *s { | ^^^^^^^^^^^^^^^^^ mutable borrow occurs here LL | nop(&[from_begin0, from_begin1, from_begin3, from_end4]); - | ----------- immutable borrow later used here + | ----------- immutable borrow later used here error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as immutable --> $DIR/borrowck-slice-pattern-element-loan-slice.rs:47:20 diff --git a/src/test/ui/nll/move-errors.stderr b/src/test/ui/nll/move-errors.stderr index b69ed0bb875..0df326425ad 100644 --- a/src/test/ui/nll/move-errors.stderr +++ b/src/test/ui/nll/move-errors.stderr @@ -97,18 +97,6 @@ LL | B::U(D(s)) => (), | data moved here | move occurs because `s` has type `String`, which does not implement the `Copy` trait -error[E0507]: cannot move out of `*x.1` which is behind a shared reference - --> $DIR/move-errors.rs:92:11 - | -LL | match x { - | ^ -... -LL | (D(s), &t) => (), - | - - | | - | data moved here - | move occurs because `t` has type `String`, which does not implement the `Copy` trait - error[E0509]: cannot move out of type `D`, which implements the `Drop` trait --> $DIR/move-errors.rs:92:11 | @@ -121,6 +109,18 @@ LL | (D(s), &t) => (), | data moved here | move occurs because `s` has type `String`, which does not implement the `Copy` trait +error[E0507]: cannot move out of `*x.1` which is behind a shared reference + --> $DIR/move-errors.rs:92:11 + | +LL | match x { + | ^ +... +LL | (D(s), &t) => (), + | - + | | + | data moved here + | move occurs because `t` has type `String`, which does not implement the `Copy` trait + error[E0509]: cannot move out of type `F`, which implements the `Drop` trait --> $DIR/move-errors.rs:102:11 | diff --git a/src/test/ui/pattern/bindings-after-at/borrowck-move-and-move.stderr b/src/test/ui/pattern/bindings-after-at/borrowck-move-and-move.stderr index b9be8968823..482ebd9b423 100644 --- a/src/test/ui/pattern/bindings-after-at/borrowck-move-and-move.stderr +++ b/src/test/ui/pattern/bindings-after-at/borrowck-move-and-move.stderr @@ -11,9 +11,9 @@ error[E0382]: use of partially moved value --> $DIR/borrowck-move-and-move.rs:15:9 | LL | let a @ (b, c) = (U, U); - | ^^^^^-^^^^ - | | | - | | value partially moved here + | ^^^^^^^^-^ + | | | + | | value partially moved here | value used here after partial move | = note: partial move occurs because value has type `U`, which does not implement the `Copy` trait @@ -22,9 +22,9 @@ error[E0382]: use of partially moved value --> $DIR/borrowck-move-and-move.rs:17:9 | LL | let a @ (b, c) = (u(), u()); - | ^^^^^-^^^^ - | | | - | | value partially moved here + | ^^^^^^^^-^ + | | | + | | value partially moved here | value used here after partial move | = note: partial move occurs because value has type `U`, which does not implement the `Copy` trait @@ -63,9 +63,9 @@ error[E0382]: use of partially moved value --> $DIR/borrowck-move-and-move.rs:27:9 | LL | xs @ [a, .., b] => {} - | ^^^^^^-^^^^^^^^ - | | | - | | value partially moved here + | ^^^^^^^^^^^^^-^ + | | | + | | value partially moved here | value used here after partial move | = note: partial move occurs because value has type `U`, which does not implement the `Copy` trait diff --git a/src/test/ui/pattern/bindings-after-at/borrowck-pat-by-move-and-ref-inverse.stderr b/src/test/ui/pattern/bindings-after-at/borrowck-pat-by-move-and-ref-inverse.stderr index 4a126a22192..c1ea5d8ec6d 100644 --- a/src/test/ui/pattern/bindings-after-at/borrowck-pat-by-move-and-ref-inverse.stderr +++ b/src/test/ui/pattern/bindings-after-at/borrowck-pat-by-move-and-ref-inverse.stderr @@ -262,9 +262,9 @@ error[E0382]: use of partially moved value --> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:26:9 | LL | let a @ (mut b @ ref mut c, d @ ref e) = (U, U); - | ^^^^^-----------------^^^^^^^^^^^^ - | | | - | | value partially moved here + | ^^^^^^^^^^^^^^^^^^^^^^^^---------^ + | | | + | | value partially moved here | value used here after partial move | = note: partial move occurs because value has type `U`, which does not implement the `Copy` trait @@ -273,9 +273,9 @@ error[E0382]: use of partially moved value --> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:35:9 | LL | let a @ (mut b @ ref mut c, d @ ref e) = (u(), u()); - | ^^^^^-----------------^^^^^^^^^^^^ - | | | - | | value partially moved here + | ^^^^^^^^^^^^^^^^^^^^^^^^---------^ + | | | + | | value partially moved here | value used here after partial move | = note: partial move occurs because value has type `U`, which does not implement the `Copy` trait @@ -284,39 +284,39 @@ error[E0382]: use of partially moved value --> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:49:9 | LL | a @ Some((mut b @ ref mut c, d @ ref e)) => {} - | ^^^^^^^^^^-----------------^^^^^^^^^^^^^ - | | | - | | value partially moved here + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------^^ + | | | + | | value partially moved here | value used here after partial move | = note: partial move occurs because value has type `U`, which does not implement the `Copy` trait help: borrow this field in the pattern to avoid moving the value | -LL | a @ Some((ref mut b @ ref mut c, d @ ref e)) => {} - | ^^^ +LL | a @ Some((mut b @ ref mut c, ref d @ ref e)) => {} + | ^^^ error[E0382]: use of partially moved value --> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:67:9 | LL | a @ Some((mut b @ ref mut c, d @ ref e)) => {} - | ^^^^^^^^^^-----------------^^^^^^^^^^^^^ - | | | - | | value partially moved here + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------^^ + | | | + | | value partially moved here | value used here after partial move | = note: partial move occurs because value has type `U`, which does not implement the `Copy` trait help: borrow this field in the pattern to avoid moving the value | -LL | a @ Some((ref mut b @ ref mut c, d @ ref e)) => {} - | ^^^ +LL | a @ Some((mut b @ ref mut c, ref d @ ref e)) => {} + | ^^^ error[E0382]: use of partially moved value --> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:16:11 | LL | fn f2(mut a @ (b @ ref c, mut d @ ref e): (U, U)) {} - | ^^^^^^^^^---------^^^^^^^^^^^^^^^^ - | | | - | | value partially moved here + | ^^^^^^^^^^^^^^^^^^^^-------------^ + | | | + | | value partially moved here | value used here after partial move | = note: partial move occurs because value has type `U`, which does not implement the `Copy` trait diff --git a/src/test/ui/pattern/bindings-after-at/borrowck-pat-by-move-and-ref.stderr b/src/test/ui/pattern/bindings-after-at/borrowck-pat-by-move-and-ref.stderr index 9113821d746..a39ff8774f7 100644 --- a/src/test/ui/pattern/bindings-after-at/borrowck-pat-by-move-and-ref.stderr +++ b/src/test/ui/pattern/bindings-after-at/borrowck-pat-by-move-and-ref.stderr @@ -237,9 +237,9 @@ error[E0382]: borrow of partially moved value --> $DIR/borrowck-pat-by-move-and-ref.rs:32:9 | LL | let ref mut a @ [b, mut c] = [U, U]; - | ^^^^^^^^^^^^^-^^^^^^^^ - | | | - | | value partially moved here + | ^^^^^^^^^^^^^^^^-----^ + | | | + | | value partially moved here | value borrowed here after partial move | = note: partial move occurs because value has type `U`, which does not implement the `Copy` trait @@ -279,9 +279,9 @@ error[E0382]: borrow of partially moved value --> $DIR/borrowck-pat-by-move-and-ref.rs:44:9 | LL | let ref mut a @ [b, mut c] = [u(), u()]; - | ^^^^^^^^^^^^^-^^^^^^^^ - | | | - | | value partially moved here + | ^^^^^^^^^^^^^^^^-----^ + | | | + | | value partially moved here | value borrowed here after partial move | = note: partial move occurs because value has type `U`, which does not implement the `Copy` trait @@ -290,16 +290,16 @@ error[E0382]: borrow of partially moved value --> $DIR/borrowck-pat-by-move-and-ref.rs:61:9 | LL | ref mut a @ Some([b, mut c]) => {} - | ^^^^^^^^^^^^^^^^^^-^^^^^^^^^ - | | | - | | value partially moved here + | ^^^^^^^^^^^^^^^^^^^^^-----^^ + | | | + | | value partially moved here | value borrowed here after partial move | = note: partial move occurs because value has type `U`, which does not implement the `Copy` trait help: borrow this field in the pattern to avoid moving the value | -LL | ref mut a @ Some([ref b, mut c]) => {} - | ^^^ +LL | ref mut a @ Some([b, ref mut c]) => {} + | ^^^ error[E0382]: borrow of partially moved value --> $DIR/borrowck-pat-by-move-and-ref.rs:67:9 @@ -350,16 +350,16 @@ error[E0382]: borrow of partially moved value --> $DIR/borrowck-pat-by-move-and-ref.rs:82:9 | LL | ref mut a @ Some([b, mut c]) => {} - | ^^^^^^^^^^^^^^^^^^-^^^^^^^^^ - | | | - | | value partially moved here + | ^^^^^^^^^^^^^^^^^^^^^-----^^ + | | | + | | value partially moved here | value borrowed here after partial move | = note: partial move occurs because value has type `U`, which does not implement the `Copy` trait help: borrow this field in the pattern to avoid moving the value | -LL | ref mut a @ Some([ref b, mut c]) => {} - | ^^^ +LL | ref mut a @ Some([b, ref mut c]) => {} + | ^^^ error[E0382]: borrow of moved value --> $DIR/borrowck-pat-by-move-and-ref.rs:13:11 @@ -397,9 +397,9 @@ error[E0382]: borrow of partially moved value --> $DIR/borrowck-pat-by-move-and-ref.rs:22:11 | LL | fn f3(ref mut a @ [b, mut c]: [U; 2]) {} - | ^^^^^^^^^^^^^-^^^^^^^^ - | | | - | | value partially moved here + | ^^^^^^^^^^^^^^^^-----^ + | | | + | | value partially moved here | value borrowed here after partial move | = note: partial move occurs because value has type `U`, which does not implement the `Copy` trait diff --git a/src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-and-ref.stderr b/src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-and-ref.stderr index d9b59504419..26182a1bc74 100644 --- a/src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-and-ref.stderr +++ b/src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-and-ref.stderr @@ -442,12 +442,12 @@ error[E0502]: cannot borrow value as immutable because it is also borrowed as mu --> $DIR/borrowck-pat-ref-mut-and-ref.rs:123:9 | LL | let ref a @ (ref mut b, ref mut c) = (U, U); - | ^^^^^^^^^^^^^^^^^^^^---------^ - | | | - | | mutable borrow occurs here + | ^^^^^^^^^---------^^^^^^^^^^^^ + | | | + | | mutable borrow occurs here | immutable borrow occurs here ... -LL | *c = U; +LL | *b = U; | ------ mutable borrow later used here error[E0502]: cannot borrow value as immutable because it is also borrowed as mutable @@ -466,12 +466,12 @@ error[E0502]: cannot borrow value as immutable because it is also borrowed as mu --> $DIR/borrowck-pat-ref-mut-and-ref.rs:135:9 | LL | let ref a @ (ref mut b, ref mut c) = (U, U); - | ^^^^^^^^^^^^^^^^^^^^---------^ - | | | - | | mutable borrow occurs here + | ^^^^^^^^^---------^^^^^^^^^^^^ + | | | + | | mutable borrow occurs here | immutable borrow occurs here -... -LL | *c = U; +LL | +LL | *b = U; | ------ mutable borrow later used here error[E0382]: borrow of moved value diff --git a/src/test/ui/pattern/move-ref-patterns/move-ref-patterns-dynamic-semantics.rs b/src/test/ui/pattern/move-ref-patterns/move-ref-patterns-dynamic-semantics.rs index fdf92b66945..1d6d9acead1 100644 --- a/src/test/ui/pattern/move-ref-patterns/move-ref-patterns-dynamic-semantics.rs +++ b/src/test/ui/pattern/move-ref-patterns/move-ref-patterns-dynamic-semantics.rs @@ -74,6 +74,6 @@ fn main() { }; lam((mk(19), mk(20), mk(21), mk(22))); } - let expected = [2, 3, 6, 5, 7, 8, 12, 11, 9, 10, 13, 18, 14, 15, 16, 17, 19, 21, 20, 22, 4, 1]; + let expected = [2, 3, 6, 5, 7, 8, 12, 11, 9, 10, 18, 13, 14, 15, 16, 17, 21, 19, 20, 22, 4, 1]; assert_eq!(&*d.borrow(), &expected); } diff --git a/src/test/ui/span/dropck_direct_cycle_with_drop.stderr b/src/test/ui/span/dropck_direct_cycle_with_drop.stderr index e01c1f87428..07ae138ac71 100644 --- a/src/test/ui/span/dropck_direct_cycle_with_drop.stderr +++ b/src/test/ui/span/dropck_direct_cycle_with_drop.stderr @@ -8,7 +8,9 @@ LL | } | - | | | `d2` dropped here while still borrowed - | borrow might be used here, when `d2` is dropped and runs the `Drop` code for type `D` + | borrow might be used here, when `d1` is dropped and runs the `Drop` code for type `D` + | + = note: values in a scope are dropped in the opposite order they are defined error[E0597]: `d1` does not live long enough --> $DIR/dropck_direct_cycle_with_drop.rs:38:19 @@ -20,9 +22,7 @@ LL | } | - | | | `d1` dropped here while still borrowed - | borrow might be used here, when `d2` is dropped and runs the `Drop` code for type `D` - | - = note: values in a scope are dropped in the opposite order they are defined + | borrow might be used here, when `d1` is dropped and runs the `Drop` code for type `D` error: aborting due to 2 previous errors diff --git a/src/test/ui/span/send-is-not-static-std-sync-2.stderr b/src/test/ui/span/send-is-not-static-std-sync-2.stderr index e4aa2aed24e..bcd07e11647 100644 --- a/src/test/ui/span/send-is-not-static-std-sync-2.stderr +++ b/src/test/ui/span/send-is-not-static-std-sync-2.stderr @@ -24,7 +24,7 @@ error[E0597]: `x` does not live long enough --> $DIR/send-is-not-static-std-sync-2.rs:31:25 | LL | let (_tx, rx) = { - | -- borrow later used here + | --- borrow later used here ... LL | let _ = tx.send(&x); | ^^ borrowed value does not live long enough