From ec28dc7aa7668b7646de369467386903ac69bafe Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 15 Oct 2022 09:00:32 +0000 Subject: [PATCH] Use `PlaceMention` for match scrutinees. --- .../rustc_mir_build/src/build/matches/mod.rs | 62 ++++---- ...await.b-{closure#0}.coroutine_resume.0.mir | 4 + .../issue_101867.main.built.after.mir | 2 +- .../building/issue_49232.main.built.after.mir | 2 +- ...n_conditional.test_complex.built.after.mir | 4 +- ...se_edges.full_tested_match.built.after.mir | 3 +- ...e_edges.full_tested_match2.built.after.mir | 3 +- .../match_false_edges.main.built.after.mir | 2 +- .../simple_match.match_bool.built.after.mir | 2 +- ...smute.unreachable_box.ConstProp.32bit.diff | 3 + ...smute.unreachable_box.ConstProp.64bit.diff | 3 + ...reachable_box.DataflowConstProp.32bit.diff | 2 + ...reachable_box.DataflowConstProp.64bit.diff | 2 + ...complex_case.main.Derefer.panic-abort.diff | 2 + ...omplex_case.main.Derefer.panic-unwind.diff | 2 + ...minator_test.main.Derefer.panic-abort.diff | 10 +- ...inator_test.main.Derefer.panic-unwind.diff | 10 +- ....match_tuple.SimplifyCfg-initial.after.mir | 2 +- ...41888.main.ElaborateDrops.panic-abort.diff | 1 + ...1888.main.ElaborateDrops.panic-unwind.diff | 1 + ...test.ElaborateDrops.before.panic-abort.mir | 1 + ...est.ElaborateDrops.before.panic-unwind.mir | 1 + tests/mir-opt/issue_72181_1.f.built.after.mir | 1 + .../issue_99325.main.built.after.32bit.mir | 4 +- .../issue_99325.main.built.after.64bit.mir | 4 +- ...inhabited.LowerIntrinsics.panic-abort.diff | 3 + ...nhabited.LowerIntrinsics.panic-unwind.diff | 3 + ...inhabited.LowerIntrinsics.panic-abort.diff | 1 + ...nhabited.LowerIntrinsics.panic-unwind.diff | 1 + ...inhabited.LowerIntrinsics.panic-abort.diff | 1 + ...nhabited.LowerIntrinsics.panic-unwind.diff | 1 + ...fg-initial.after-ElaborateDrops.after.diff | 2 +- ...fg-initial.after-ElaborateDrops.after.diff | 2 +- ...ch_test.main.SimplifyCfg-initial.after.mir | 2 +- ...guard.CleanupPostBorrowck.panic-abort.diff | 3 +- ...uard.CleanupPostBorrowck.panic-unwind.diff | 3 +- tests/ui/binding/issue-53114-borrow-checks.rs | 9 +- .../binding/issue-53114-borrow-checks.stderr | 81 ---------- .../borrowck-move-out-from-array-match.rs | 10 +- .../borrowck-move-out-from-array-match.stderr | 40 ++--- ...ck-move-out-from-array-no-overlap-match.rs | 10 +- ...ove-out-from-array-no-overlap-match.stderr | 138 ------------------ .../borrowck-move-out-from-array-use-match.rs | 10 +- ...rowck-move-out-from-array-use-match.stderr | 50 +++---- ...ove-out-from-array-use-no-overlap-match.rs | 10 +- ...out-from-array-use-no-overlap-match.stderr | 138 ------------------ .../borrowck/issue-62107-match-arm-scopes.rs | 2 +- .../issue-62107-match-arm-scopes.stderr | 5 +- tests/ui/borrowck/let_underscore_temporary.rs | 38 +++++ .../borrowck/let_underscore_temporary.stderr | 40 ++++- ..._refers_to_static_cross_crate.32bit.stderr | 5 + ..._refers_to_static_cross_crate.64bit.stderr | 5 + tests/ui/error-codes/E0396.rs | 2 + tests/ui/error-codes/E0396.stderr | 24 ++- .../move-guard-if-let-chain.stderr | 14 +- .../dbg-macro-move-semantics.stderr | 5 +- 56 files changed, 290 insertions(+), 501 deletions(-) delete mode 100644 tests/ui/binding/issue-53114-borrow-checks.stderr delete mode 100644 tests/ui/borrowck/borrowck-move-out-from-array-no-overlap-match.stderr delete mode 100644 tests/ui/borrowck/borrowck-move-out-from-array-use-no-overlap-match.stderr diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs index 24c6e0eae36..3d057b9b845 100644 --- a/compiler/rustc_mir_build/src/build/matches/mod.rs +++ b/compiler/rustc_mir_build/src/build/matches/mod.rs @@ -223,6 +223,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let fake_borrow_temps = self.lower_match_tree( block, scrutinee_span, + &scrutinee_place, match_start_span, match_has_guard, &mut candidates, @@ -246,26 +247,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { scrutinee_span: Span, ) -> BlockAnd> { let scrutinee_place_builder = unpack!(block = self.as_place_builder(block, scrutinee)); - // Matching on a `scrutinee_place` with an uninhabited type doesn't - // generate any memory reads by itself, and so if the place "expression" - // contains unsafe operations like raw pointer dereferences or union - // field projections, we wouldn't know to require an `unsafe` block - // around a `match` equivalent to `std::intrinsics::unreachable()`. - // See issue #47412 for this hole being discovered in the wild. - // - // HACK(eddyb) Work around the above issue by adding a dummy inspection - // of `scrutinee_place`, specifically by applying `ReadForMatch`. - // - // NOTE: ReadForMatch also checks that the scrutinee is initialized. - // This is currently needed to not allow matching on an uninitialized, - // uninhabited value. If we get never patterns, those will check that - // the place is initialized, and so this read would only be used to - // check safety. - let cause_matched_place = FakeReadCause::ForMatchedPlace(None); - let source_info = self.source_info(scrutinee_span); - if let Some(scrutinee_place) = scrutinee_place_builder.try_to_place(self) { - self.cfg.push_fake_read(block, source_info, cause_matched_place, scrutinee_place); + let source_info = self.source_info(scrutinee_span); + self.cfg.push_place_mention(block, source_info, scrutinee_place); } block.and(scrutinee_place_builder) @@ -304,6 +288,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { &mut self, block: BasicBlock, scrutinee_span: Span, + scrutinee_place_builder: &PlaceBuilder<'tcx>, match_start_span: Span, match_has_guard: bool, candidates: &mut [&mut Candidate<'pat, 'tcx>], @@ -331,6 +316,33 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // otherwise block. Match checking will ensure this is actually // unreachable. let source_info = self.source_info(scrutinee_span); + + // Matching on a `scrutinee_place` with an uninhabited type doesn't + // generate any memory reads by itself, and so if the place "expression" + // contains unsafe operations like raw pointer dereferences or union + // field projections, we wouldn't know to require an `unsafe` block + // around a `match` equivalent to `std::intrinsics::unreachable()`. + // See issue #47412 for this hole being discovered in the wild. + // + // HACK(eddyb) Work around the above issue by adding a dummy inspection + // of `scrutinee_place`, specifically by applying `ReadForMatch`. + // + // NOTE: ReadForMatch also checks that the scrutinee is initialized. + // This is currently needed to not allow matching on an uninitialized, + // uninhabited value. If we get never patterns, those will check that + // the place is initialized, and so this read would only be used to + // check safety. + let cause_matched_place = FakeReadCause::ForMatchedPlace(None); + + if let Some(scrutinee_place) = scrutinee_place_builder.try_to_place(self) { + self.cfg.push_fake_read( + otherwise_block, + source_info, + cause_matched_place, + scrutinee_place, + ); + } + self.cfg.terminate(otherwise_block, source_info, TerminatorKind::Unreachable); } @@ -599,13 +611,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } _ => { - let place_builder = unpack!(block = self.as_place_builder(block, initializer)); - - if let Some(place) = place_builder.try_to_place(self) { - let source_info = self.source_info(initializer.span); - self.cfg.push_place_mention(block, source_info, place); - } - + let place_builder = + unpack!(block = self.lower_scrutinee(block, initializer, initializer.span)); self.place_into_pattern(block, &irrefutable_pat, place_builder, true) } } @@ -622,6 +629,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let fake_borrow_temps = self.lower_match_tree( block, irrefutable_pat.span, + &initializer, irrefutable_pat.span, false, &mut [&mut candidate], @@ -1837,6 +1845,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let fake_borrow_temps = self.lower_match_tree( block, pat.span, + &expr_place_builder, pat.span, false, &mut [&mut guard_candidate, &mut otherwise_candidate], @@ -2338,6 +2347,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let fake_borrow_temps = this.lower_match_tree( block, initializer_span, + &scrutinee, pattern.span, false, &mut [&mut candidate, &mut wildcard], diff --git a/tests/mir-opt/building/async_await.b-{closure#0}.coroutine_resume.0.mir b/tests/mir-opt/building/async_await.b-{closure#0}.coroutine_resume.0.mir index f64b540c3a5..396e4a378f6 100644 --- a/tests/mir-opt/building/async_await.b-{closure#0}.coroutine_resume.0.mir +++ b/tests/mir-opt/building/async_await.b-{closure#0}.coroutine_resume.0.mir @@ -127,6 +127,7 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body@$DIR/async_await.rs:15:18: 18:2}>, bb3: { StorageDead(_5); + PlaceMention(_4); nop; (((*(_1.0: &mut {async fn body@$DIR/async_await.rs:15:18: 18:2})) as variant#3).0: {async fn body@$DIR/async_await.rs:12:14: 12:16}) = move _4; goto -> bb4; @@ -162,6 +163,7 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body@$DIR/async_await.rs:15:18: 18:2}>, bb7: { StorageDead(_13); StorageDead(_10); + PlaceMention(_9); _16 = discriminant(_9); switchInt(move _16) -> [0: bb10, 1: bb8, otherwise: bb9]; } @@ -223,6 +225,7 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body@$DIR/async_await.rs:15:18: 18:2}>, bb15: { StorageDead(_22); + PlaceMention(_21); nop; (((*(_1.0: &mut {async fn body@$DIR/async_await.rs:15:18: 18:2})) as variant#4).0: {async fn body@$DIR/async_await.rs:12:14: 12:16}) = move _21; goto -> bb16; @@ -258,6 +261,7 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body@$DIR/async_await.rs:15:18: 18:2}>, bb19: { StorageDead(_29); StorageDead(_26); + PlaceMention(_25); _32 = discriminant(_25); switchInt(move _32) -> [0: bb21, 1: bb20, otherwise: bb9]; } diff --git a/tests/mir-opt/building/issue_101867.main.built.after.mir b/tests/mir-opt/building/issue_101867.main.built.after.mir index fb60f0f0c2b..57f8cca9abc 100644 --- a/tests/mir-opt/building/issue_101867.main.built.after.mir +++ b/tests/mir-opt/building/issue_101867.main.built.after.mir @@ -25,7 +25,7 @@ fn main() -> () { FakeRead(ForLet(None), _1); AscribeUserType(_1, o, UserTypeProjection { base: UserType(1), projs: [] }); StorageLive(_5); - FakeRead(ForMatchedPlace(None), _1); + PlaceMention(_1); _6 = discriminant(_1); switchInt(move _6) -> [1: bb4, otherwise: bb3]; } diff --git a/tests/mir-opt/building/issue_49232.main.built.after.mir b/tests/mir-opt/building/issue_49232.main.built.after.mir index f809132bc63..ac50b388910 100644 --- a/tests/mir-opt/building/issue_49232.main.built.after.mir +++ b/tests/mir-opt/building/issue_49232.main.built.after.mir @@ -24,7 +24,7 @@ fn main() -> () { StorageLive(_2); StorageLive(_3); _3 = const true; - FakeRead(ForMatchedPlace(None), _3); + PlaceMention(_3); switchInt(_3) -> [0: bb3, otherwise: bb4]; } diff --git a/tests/mir-opt/building/logical_or_in_conditional.test_complex.built.after.mir b/tests/mir-opt/building/logical_or_in_conditional.test_complex.built.after.mir index 096aaec4a38..7407e7a8b2a 100644 --- a/tests/mir-opt/building/logical_or_in_conditional.test_complex.built.after.mir +++ b/tests/mir-opt/building/logical_or_in_conditional.test_complex.built.after.mir @@ -23,7 +23,7 @@ fn test_complex() -> () { } bb1: { - FakeRead(ForMatchedPlace(None), _2); + PlaceMention(_2); _3 = discriminant(_2); switchInt(move _3) -> [0: bb2, otherwise: bb3]; } @@ -151,7 +151,7 @@ fn test_complex() -> () { } bb25: { - FakeRead(ForMatchedPlace(None), _12); + PlaceMention(_12); _13 = discriminant(_12); switchInt(move _13) -> [1: bb27, otherwise: bb26]; } diff --git a/tests/mir-opt/building/match_false_edges.full_tested_match.built.after.mir b/tests/mir-opt/building/match_false_edges.full_tested_match.built.after.mir index bd4cd4eb678..1946c70e476 100644 --- a/tests/mir-opt/building/match_false_edges.full_tested_match.built.after.mir +++ b/tests/mir-opt/building/match_false_edges.full_tested_match.built.after.mir @@ -26,7 +26,7 @@ fn full_tested_match() -> () { StorageLive(_1); StorageLive(_2); _2 = Option::::Some(const 42_i32); - FakeRead(ForMatchedPlace(None), _2); + PlaceMention(_2); _3 = discriminant(_2); switchInt(move _3) -> [0: bb1, 1: bb2, otherwise: bb4]; } @@ -45,6 +45,7 @@ fn full_tested_match() -> () { } bb4: { + FakeRead(ForMatchedPlace(None), _2); unreachable; } diff --git a/tests/mir-opt/building/match_false_edges.full_tested_match2.built.after.mir b/tests/mir-opt/building/match_false_edges.full_tested_match2.built.after.mir index 595e3ab9224..b6175b05156 100644 --- a/tests/mir-opt/building/match_false_edges.full_tested_match2.built.after.mir +++ b/tests/mir-opt/building/match_false_edges.full_tested_match2.built.after.mir @@ -26,7 +26,7 @@ fn full_tested_match2() -> () { StorageLive(_1); StorageLive(_2); _2 = Option::::Some(const 42_i32); - FakeRead(ForMatchedPlace(None), _2); + PlaceMention(_2); _3 = discriminant(_2); switchInt(move _3) -> [0: bb1, 1: bb2, otherwise: bb4]; } @@ -51,6 +51,7 @@ fn full_tested_match2() -> () { } bb4: { + FakeRead(ForMatchedPlace(None), _2); unreachable; } diff --git a/tests/mir-opt/building/match_false_edges.main.built.after.mir b/tests/mir-opt/building/match_false_edges.main.built.after.mir index 91fe2f90e35..0b57d1b97e1 100644 --- a/tests/mir-opt/building/match_false_edges.main.built.after.mir +++ b/tests/mir-opt/building/match_false_edges.main.built.after.mir @@ -37,7 +37,7 @@ fn main() -> () { StorageLive(_1); StorageLive(_2); _2 = Option::::Some(const 1_i32); - FakeRead(ForMatchedPlace(None), _2); + PlaceMention(_2); _4 = discriminant(_2); switchInt(move _4) -> [1: bb2, otherwise: bb1]; } diff --git a/tests/mir-opt/building/simple_match.match_bool.built.after.mir b/tests/mir-opt/building/simple_match.match_bool.built.after.mir index c89ea2b6c85..06de4c51051 100644 --- a/tests/mir-opt/building/simple_match.match_bool.built.after.mir +++ b/tests/mir-opt/building/simple_match.match_bool.built.after.mir @@ -5,7 +5,7 @@ fn match_bool(_1: bool) -> usize { let mut _0: usize; bb0: { - FakeRead(ForMatchedPlace(None), _1); + PlaceMention(_1); switchInt(_1) -> [0: bb2, otherwise: bb1]; } diff --git a/tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.32bit.diff b/tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.32bit.diff index 100982382dd..16519749b82 100644 --- a/tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.32bit.diff +++ b/tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.32bit.diff @@ -4,6 +4,7 @@ fn unreachable_box() -> ! { let mut _0: !; let _1: std::boxed::Box; + let mut _2: *const Never; scope 1 { debug x => _1; } @@ -13,7 +14,9 @@ bb0: { StorageLive(_1); - _1 = const 1_usize as std::boxed::Box (Transmute); +- _2 = (((_1.0: std::ptr::Unique).0: std::ptr::NonNull).0: *const Never); + _1 = const Box::(Unique:: {{ pointer: NonNull:: {{ pointer: {0x1 as *const Never} }}, _marker: PhantomData:: }}, std::alloc::Global); ++ _2 = const {0x1 as *const Never}; unreachable; } } diff --git a/tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.64bit.diff b/tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.64bit.diff index 100982382dd..16519749b82 100644 --- a/tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.64bit.diff +++ b/tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.64bit.diff @@ -4,6 +4,7 @@ fn unreachable_box() -> ! { let mut _0: !; let _1: std::boxed::Box; + let mut _2: *const Never; scope 1 { debug x => _1; } @@ -13,7 +14,9 @@ bb0: { StorageLive(_1); - _1 = const 1_usize as std::boxed::Box (Transmute); +- _2 = (((_1.0: std::ptr::Unique).0: std::ptr::NonNull).0: *const Never); + _1 = const Box::(Unique:: {{ pointer: NonNull:: {{ pointer: {0x1 as *const Never} }}, _marker: PhantomData:: }}, std::alloc::Global); ++ _2 = const {0x1 as *const Never}; unreachable; } } diff --git a/tests/mir-opt/dataflow-const-prop/transmute.unreachable_box.DataflowConstProp.32bit.diff b/tests/mir-opt/dataflow-const-prop/transmute.unreachable_box.DataflowConstProp.32bit.diff index d0c298ba233..5d17c47ae66 100644 --- a/tests/mir-opt/dataflow-const-prop/transmute.unreachable_box.DataflowConstProp.32bit.diff +++ b/tests/mir-opt/dataflow-const-prop/transmute.unreachable_box.DataflowConstProp.32bit.diff @@ -4,6 +4,7 @@ fn unreachable_box() -> ! { let mut _0: !; let _1: std::boxed::Box; + let mut _2: *const Never; scope 1 { debug x => _1; } @@ -14,6 +15,7 @@ StorageLive(_1); - _1 = const 1_usize as std::boxed::Box (Transmute); + _1 = const Box::(Unique:: {{ pointer: NonNull:: {{ pointer: {0x1 as *const Never} }}, _marker: PhantomData:: }}, std::alloc::Global); + _2 = (((_1.0: std::ptr::Unique).0: std::ptr::NonNull).0: *const Never); unreachable; } } diff --git a/tests/mir-opt/dataflow-const-prop/transmute.unreachable_box.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/transmute.unreachable_box.DataflowConstProp.64bit.diff index d0c298ba233..5d17c47ae66 100644 --- a/tests/mir-opt/dataflow-const-prop/transmute.unreachable_box.DataflowConstProp.64bit.diff +++ b/tests/mir-opt/dataflow-const-prop/transmute.unreachable_box.DataflowConstProp.64bit.diff @@ -4,6 +4,7 @@ fn unreachable_box() -> ! { let mut _0: !; let _1: std::boxed::Box; + let mut _2: *const Never; scope 1 { debug x => _1; } @@ -14,6 +15,7 @@ StorageLive(_1); - _1 = const 1_usize as std::boxed::Box (Transmute); + _1 = const Box::(Unique:: {{ pointer: NonNull:: {{ pointer: {0x1 as *const Never} }}, _marker: PhantomData:: }}, std::alloc::Global); + _2 = (((_1.0: std::ptr::Unique).0: std::ptr::NonNull).0: *const Never); unreachable; } } diff --git a/tests/mir-opt/derefer_complex_case.main.Derefer.panic-abort.diff b/tests/mir-opt/derefer_complex_case.main.Derefer.panic-abort.diff index 1f3b3ad649d..0fad716a2cb 100644 --- a/tests/mir-opt/derefer_complex_case.main.Derefer.panic-abort.diff +++ b/tests/mir-opt/derefer_complex_case.main.Derefer.panic-abort.diff @@ -35,6 +35,7 @@ bb1: { StorageDead(_2); + PlaceMention(_1); StorageLive(_4); _4 = move _1; goto -> bb2; @@ -52,6 +53,7 @@ bb3: { StorageDead(_8); + PlaceMention(_7); _10 = discriminant(_7); switchInt(move _10) -> [0: bb6, 1: bb4, otherwise: bb5]; } diff --git a/tests/mir-opt/derefer_complex_case.main.Derefer.panic-unwind.diff b/tests/mir-opt/derefer_complex_case.main.Derefer.panic-unwind.diff index da4cc188cfa..ae5656f02a5 100644 --- a/tests/mir-opt/derefer_complex_case.main.Derefer.panic-unwind.diff +++ b/tests/mir-opt/derefer_complex_case.main.Derefer.panic-unwind.diff @@ -35,6 +35,7 @@ bb1: { StorageDead(_2); + PlaceMention(_1); StorageLive(_4); _4 = move _1; goto -> bb2; @@ -52,6 +53,7 @@ bb3: { StorageDead(_8); + PlaceMention(_7); _10 = discriminant(_7); switchInt(move _10) -> [0: bb6, 1: bb4, otherwise: bb5]; } diff --git a/tests/mir-opt/derefer_terminator_test.main.Derefer.panic-abort.diff b/tests/mir-opt/derefer_terminator_test.main.Derefer.panic-abort.diff index 895dcf5798e..f4c034517f7 100644 --- a/tests/mir-opt/derefer_terminator_test.main.Derefer.panic-abort.diff +++ b/tests/mir-opt/derefer_terminator_test.main.Derefer.panic-abort.diff @@ -12,6 +12,9 @@ + let mut _10: &&&bool; + let mut _11: &&bool; + let mut _12: &bool; ++ let mut _13: &&&bool; ++ let mut _14: &&bool; ++ let mut _15: &bool; scope 1 { debug b => _1; let _2: bool; @@ -48,11 +51,16 @@ _6 = &_7; _5 = &_6; _4 = &_5; +- PlaceMention((*(*(*(*_4))))); - switchInt((*(*(*(*_4))))) -> [0: bb3, otherwise: bb4]; + _10 = deref_copy (*_4); + _11 = deref_copy (*_10); + _12 = deref_copy (*_11); -+ switchInt((*_12)) -> [0: bb3, otherwise: bb4]; ++ PlaceMention((*_12)); ++ _13 = deref_copy (*_4); ++ _14 = deref_copy (*_13); ++ _15 = deref_copy (*_14); ++ switchInt((*_15)) -> [0: bb3, otherwise: bb4]; } bb3: { diff --git a/tests/mir-opt/derefer_terminator_test.main.Derefer.panic-unwind.diff b/tests/mir-opt/derefer_terminator_test.main.Derefer.panic-unwind.diff index 19b26c901cb..e3c0c6b7dd2 100644 --- a/tests/mir-opt/derefer_terminator_test.main.Derefer.panic-unwind.diff +++ b/tests/mir-opt/derefer_terminator_test.main.Derefer.panic-unwind.diff @@ -12,6 +12,9 @@ + let mut _10: &&&bool; + let mut _11: &&bool; + let mut _12: &bool; ++ let mut _13: &&&bool; ++ let mut _14: &&bool; ++ let mut _15: &bool; scope 1 { debug b => _1; let _2: bool; @@ -48,11 +51,16 @@ _6 = &_7; _5 = &_6; _4 = &_5; +- PlaceMention((*(*(*(*_4))))); - switchInt((*(*(*(*_4))))) -> [0: bb3, otherwise: bb4]; + _10 = deref_copy (*_4); + _11 = deref_copy (*_10); + _12 = deref_copy (*_11); -+ switchInt((*_12)) -> [0: bb3, otherwise: bb4]; ++ PlaceMention((*_12)); ++ _13 = deref_copy (*_4); ++ _14 = deref_copy (*_13); ++ _15 = deref_copy (*_14); ++ switchInt((*_15)) -> [0: bb3, otherwise: bb4]; } bb3: { diff --git a/tests/mir-opt/exponential_or.match_tuple.SimplifyCfg-initial.after.mir b/tests/mir-opt/exponential_or.match_tuple.SimplifyCfg-initial.after.mir index fba616d0474..b04e09e88b8 100644 --- a/tests/mir-opt/exponential_or.match_tuple.SimplifyCfg-initial.after.mir +++ b/tests/mir-opt/exponential_or.match_tuple.SimplifyCfg-initial.after.mir @@ -18,7 +18,7 @@ fn match_tuple(_1: (u32, bool, Option, u32)) -> u32 { } bb0: { - FakeRead(ForMatchedPlace(None), _1); + PlaceMention(_1); switchInt((_1.0: u32)) -> [1: bb2, 4: bb2, otherwise: bb1]; } diff --git a/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-abort.diff b/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-abort.diff index ae18ddc8366..55d2629a551 100644 --- a/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-abort.diff +++ b/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-abort.diff @@ -60,6 +60,7 @@ bb5: { StorageDead(_3); + PlaceMention(_1); _5 = discriminant(_1); switchInt(move _5) -> [0: bb6, otherwise: bb7]; } diff --git a/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-unwind.diff b/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-unwind.diff index d08113c0ba5..c731b5646f6 100644 --- a/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-unwind.diff +++ b/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-unwind.diff @@ -60,6 +60,7 @@ bb5: { StorageDead(_3); + PlaceMention(_1); _5 = discriminant(_1); switchInt(move _5) -> [0: bb6, otherwise: bb7]; } diff --git a/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-abort.mir b/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-abort.mir index 73462967850..fadfdfc87be 100644 --- a/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-abort.mir +++ b/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-abort.mir @@ -45,6 +45,7 @@ fn test() -> Option> { bb2: { StorageDead(_7); + PlaceMention(_6); _8 = discriminant(_6); switchInt(move _8) -> [0: bb3, 1: bb5, otherwise: bb4]; } diff --git a/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-unwind.mir b/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-unwind.mir index 8264e2cabbc..8f94165a108 100644 --- a/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-unwind.mir +++ b/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-unwind.mir @@ -45,6 +45,7 @@ fn test() -> Option> { bb2: { StorageDead(_7); + PlaceMention(_6); _8 = discriminant(_6); switchInt(move _8) -> [0: bb3, 1: bb5, otherwise: bb4]; } diff --git a/tests/mir-opt/issue_72181_1.f.built.after.mir b/tests/mir-opt/issue_72181_1.f.built.after.mir index 16f34e4a449..89da9a80113 100644 --- a/tests/mir-opt/issue_72181_1.f.built.after.mir +++ b/tests/mir-opt/issue_72181_1.f.built.after.mir @@ -5,6 +5,7 @@ fn f(_1: Void) -> ! { let mut _0: !; bb0: { + PlaceMention(_1); FakeRead(ForMatchedPlace(None), _1); unreachable; } diff --git a/tests/mir-opt/issue_99325.main.built.after.32bit.mir b/tests/mir-opt/issue_99325.main.built.after.32bit.mir index 188b53d28d7..ffb1aedd2ea 100644 --- a/tests/mir-opt/issue_99325.main.built.after.32bit.mir +++ b/tests/mir-opt/issue_99325.main.built.after.32bit.mir @@ -81,7 +81,7 @@ fn main() -> () { _2 = (move _3, move _5); StorageDead(_5); StorageDead(_3); - FakeRead(ForMatchedPlace(None), _2); + PlaceMention(_2); StorageLive(_8); _8 = (_2.0: &&[u8]); StorageLive(_9); @@ -180,7 +180,7 @@ fn main() -> () { _23 = (move _24, move _26); StorageDead(_26); StorageDead(_24); - FakeRead(ForMatchedPlace(None), _23); + PlaceMention(_23); StorageLive(_28); _28 = (_23.0: &&[u8]); StorageLive(_29); diff --git a/tests/mir-opt/issue_99325.main.built.after.64bit.mir b/tests/mir-opt/issue_99325.main.built.after.64bit.mir index 188b53d28d7..ffb1aedd2ea 100644 --- a/tests/mir-opt/issue_99325.main.built.after.64bit.mir +++ b/tests/mir-opt/issue_99325.main.built.after.64bit.mir @@ -81,7 +81,7 @@ fn main() -> () { _2 = (move _3, move _5); StorageDead(_5); StorageDead(_3); - FakeRead(ForMatchedPlace(None), _2); + PlaceMention(_2); StorageLive(_8); _8 = (_2.0: &&[u8]); StorageLive(_9); @@ -180,7 +180,7 @@ fn main() -> () { _23 = (move _24, move _26); StorageDead(_26); StorageDead(_24); - FakeRead(ForMatchedPlace(None), _23); + PlaceMention(_23); StorageLive(_28); _28 = (_23.0: &&[u8]); StorageLive(_29); diff --git a/tests/mir-opt/lower_intrinsics.transmute_to_box_uninhabited.LowerIntrinsics.panic-abort.diff b/tests/mir-opt/lower_intrinsics.transmute_to_box_uninhabited.LowerIntrinsics.panic-abort.diff index 49cc8b1afe3..c4a3358ffa3 100644 --- a/tests/mir-opt/lower_intrinsics.transmute_to_box_uninhabited.LowerIntrinsics.panic-abort.diff +++ b/tests/mir-opt/lower_intrinsics.transmute_to_box_uninhabited.LowerIntrinsics.panic-abort.diff @@ -4,6 +4,7 @@ fn transmute_to_box_uninhabited() -> ! { let mut _0: !; let _1: std::boxed::Box; + let mut _2: *const Never; scope 1 { debug x => _1; } @@ -16,6 +17,8 @@ } bb1: { + _2 = (((_1.0: std::ptr::Unique).0: std::ptr::NonNull).0: *const Never); + PlaceMention((*_2)); unreachable; } } diff --git a/tests/mir-opt/lower_intrinsics.transmute_to_box_uninhabited.LowerIntrinsics.panic-unwind.diff b/tests/mir-opt/lower_intrinsics.transmute_to_box_uninhabited.LowerIntrinsics.panic-unwind.diff index 49cc8b1afe3..c4a3358ffa3 100644 --- a/tests/mir-opt/lower_intrinsics.transmute_to_box_uninhabited.LowerIntrinsics.panic-unwind.diff +++ b/tests/mir-opt/lower_intrinsics.transmute_to_box_uninhabited.LowerIntrinsics.panic-unwind.diff @@ -4,6 +4,7 @@ fn transmute_to_box_uninhabited() -> ! { let mut _0: !; let _1: std::boxed::Box; + let mut _2: *const Never; scope 1 { debug x => _1; } @@ -16,6 +17,8 @@ } bb1: { + _2 = (((_1.0: std::ptr::Unique).0: std::ptr::NonNull).0: *const Never); + PlaceMention((*_2)); unreachable; } } diff --git a/tests/mir-opt/lower_intrinsics.transmute_to_mut_uninhabited.LowerIntrinsics.panic-abort.diff b/tests/mir-opt/lower_intrinsics.transmute_to_mut_uninhabited.LowerIntrinsics.panic-abort.diff index 94c7ebe1520..c2c4ec0003c 100644 --- a/tests/mir-opt/lower_intrinsics.transmute_to_mut_uninhabited.LowerIntrinsics.panic-abort.diff +++ b/tests/mir-opt/lower_intrinsics.transmute_to_mut_uninhabited.LowerIntrinsics.panic-abort.diff @@ -16,6 +16,7 @@ } bb1: { + PlaceMention((*_1)); unreachable; } } diff --git a/tests/mir-opt/lower_intrinsics.transmute_to_mut_uninhabited.LowerIntrinsics.panic-unwind.diff b/tests/mir-opt/lower_intrinsics.transmute_to_mut_uninhabited.LowerIntrinsics.panic-unwind.diff index 94c7ebe1520..c2c4ec0003c 100644 --- a/tests/mir-opt/lower_intrinsics.transmute_to_mut_uninhabited.LowerIntrinsics.panic-unwind.diff +++ b/tests/mir-opt/lower_intrinsics.transmute_to_mut_uninhabited.LowerIntrinsics.panic-unwind.diff @@ -16,6 +16,7 @@ } bb1: { + PlaceMention((*_1)); unreachable; } } diff --git a/tests/mir-opt/lower_intrinsics.transmute_to_ref_uninhabited.LowerIntrinsics.panic-abort.diff b/tests/mir-opt/lower_intrinsics.transmute_to_ref_uninhabited.LowerIntrinsics.panic-abort.diff index 6576616e0ca..1b516a1f53b 100644 --- a/tests/mir-opt/lower_intrinsics.transmute_to_ref_uninhabited.LowerIntrinsics.panic-abort.diff +++ b/tests/mir-opt/lower_intrinsics.transmute_to_ref_uninhabited.LowerIntrinsics.panic-abort.diff @@ -16,6 +16,7 @@ } bb1: { + PlaceMention((*_1)); unreachable; } } diff --git a/tests/mir-opt/lower_intrinsics.transmute_to_ref_uninhabited.LowerIntrinsics.panic-unwind.diff b/tests/mir-opt/lower_intrinsics.transmute_to_ref_uninhabited.LowerIntrinsics.panic-unwind.diff index 6576616e0ca..1b516a1f53b 100644 --- a/tests/mir-opt/lower_intrinsics.transmute_to_ref_uninhabited.LowerIntrinsics.panic-unwind.diff +++ b/tests/mir-opt/lower_intrinsics.transmute_to_ref_uninhabited.LowerIntrinsics.panic-unwind.diff @@ -16,6 +16,7 @@ } bb1: { + PlaceMention((*_1)); unreachable; } } diff --git a/tests/mir-opt/match_arm_scopes.complicated_match.panic-abort.SimplifyCfg-initial.after-ElaborateDrops.after.diff b/tests/mir-opt/match_arm_scopes.complicated_match.panic-abort.SimplifyCfg-initial.after-ElaborateDrops.after.diff index 3e817ff433b..2989582d038 100644 --- a/tests/mir-opt/match_arm_scopes.complicated_match.panic-abort.SimplifyCfg-initial.after-ElaborateDrops.after.diff +++ b/tests/mir-opt/match_arm_scopes.complicated_match.panic-abort.SimplifyCfg-initial.after-ElaborateDrops.after.diff @@ -31,7 +31,7 @@ } bb0: { -- FakeRead(ForMatchedPlace(None), _2); + PlaceMention(_2); - switchInt((_2.0: bool)) -> [0: bb1, otherwise: bb2]; + switchInt((_2.0: bool)) -> [0: bb5, otherwise: bb1]; } diff --git a/tests/mir-opt/match_arm_scopes.complicated_match.panic-unwind.SimplifyCfg-initial.after-ElaborateDrops.after.diff b/tests/mir-opt/match_arm_scopes.complicated_match.panic-unwind.SimplifyCfg-initial.after-ElaborateDrops.after.diff index 3e817ff433b..2989582d038 100644 --- a/tests/mir-opt/match_arm_scopes.complicated_match.panic-unwind.SimplifyCfg-initial.after-ElaborateDrops.after.diff +++ b/tests/mir-opt/match_arm_scopes.complicated_match.panic-unwind.SimplifyCfg-initial.after-ElaborateDrops.after.diff @@ -31,7 +31,7 @@ } bb0: { -- FakeRead(ForMatchedPlace(None), _2); + PlaceMention(_2); - switchInt((_2.0: bool)) -> [0: bb1, otherwise: bb2]; + switchInt((_2.0: bool)) -> [0: bb5, otherwise: bb1]; } diff --git a/tests/mir-opt/match_test.main.SimplifyCfg-initial.after.mir b/tests/mir-opt/match_test.main.SimplifyCfg-initial.after.mir index 7f8eb82c772..90ec3ab49ad 100644 --- a/tests/mir-opt/match_test.main.SimplifyCfg-initial.after.mir +++ b/tests/mir-opt/match_test.main.SimplifyCfg-initial.after.mir @@ -26,7 +26,7 @@ fn main() -> () { _2 = const true; FakeRead(ForLet(None), _2); StorageLive(_3); - FakeRead(ForMatchedPlace(None), _1); + PlaceMention(_1); _6 = Le(const 0_i32, _1); switchInt(move _6) -> [0: bb4, otherwise: bb1]; } diff --git a/tests/mir-opt/remove_fake_borrows.match_guard.CleanupPostBorrowck.panic-abort.diff b/tests/mir-opt/remove_fake_borrows.match_guard.CleanupPostBorrowck.panic-abort.diff index 33322c41b01..61329bb75d1 100644 --- a/tests/mir-opt/remove_fake_borrows.match_guard.CleanupPostBorrowck.panic-abort.diff +++ b/tests/mir-opt/remove_fake_borrows.match_guard.CleanupPostBorrowck.panic-abort.diff @@ -13,8 +13,7 @@ let mut _8: bool; bb0: { -- FakeRead(ForMatchedPlace(None), _1); -+ nop; + PlaceMention(_1); _3 = discriminant(_1); switchInt(move _3) -> [1: bb2, otherwise: bb1]; } diff --git a/tests/mir-opt/remove_fake_borrows.match_guard.CleanupPostBorrowck.panic-unwind.diff b/tests/mir-opt/remove_fake_borrows.match_guard.CleanupPostBorrowck.panic-unwind.diff index 33322c41b01..61329bb75d1 100644 --- a/tests/mir-opt/remove_fake_borrows.match_guard.CleanupPostBorrowck.panic-unwind.diff +++ b/tests/mir-opt/remove_fake_borrows.match_guard.CleanupPostBorrowck.panic-unwind.diff @@ -13,8 +13,7 @@ let mut _8: bool; bb0: { -- FakeRead(ForMatchedPlace(None), _1); -+ nop; + PlaceMention(_1); _3 = discriminant(_1); switchInt(move _3) -> [1: bb2, otherwise: bb1]; } diff --git a/tests/ui/binding/issue-53114-borrow-checks.rs b/tests/ui/binding/issue-53114-borrow-checks.rs index 7646472f45f..8b4ebe7265a 100644 --- a/tests/ui/binding/issue-53114-borrow-checks.rs +++ b/tests/ui/binding/issue-53114-borrow-checks.rs @@ -1,8 +1,9 @@ +// check-pass // Issue #53114: NLL's borrow check had some deviations from the old borrow // checker, and both had some deviations from our ideal state. This test // captures the behavior of how `_` bindings are handled with respect to how we // flag expressions that are meant to request unsafe blocks. -#![allow(irrefutable_let_patterns)] +#![allow(irrefutable_let_patterns, dropping_references)] struct M; fn let_wild_gets_moved_expr() { @@ -20,28 +21,22 @@ fn match_moved_expr_to_wild() { let m = M; drop(m); match m { _ => { } } // #53114: should eventually be accepted too - //~^ ERROR [E0382] let mm = (M, M); // variation on above with `_` in substructure match mm { (_x, _) => { } } match mm { (_, _y) => { } } - //~^ ERROR [E0382] match mm { (_, _) => { } } - //~^ ERROR [E0382] } fn if_let_moved_expr_to_wild() { let m = M; drop(m); if let _ = m { } // #53114: should eventually be accepted too - //~^ ERROR [E0382] let mm = (M, M); // variation on above with `_` in substructure if let (_x, _) = mm { } if let (_, _y) = mm { } - //~^ ERROR [E0382] if let (_, _) = mm { } - //~^ ERROR [E0382] } fn let_wild_gets_borrowed_expr() { diff --git a/tests/ui/binding/issue-53114-borrow-checks.stderr b/tests/ui/binding/issue-53114-borrow-checks.stderr deleted file mode 100644 index 0ec2ae8839e..00000000000 --- a/tests/ui/binding/issue-53114-borrow-checks.stderr +++ /dev/null @@ -1,81 +0,0 @@ -error[E0382]: use of moved value: `m` - --> $DIR/issue-53114-borrow-checks.rs:22:11 - | -LL | let m = M; - | - move occurs because `m` has type `M`, which does not implement the `Copy` trait -LL | drop(m); - | - value moved here -LL | match m { _ => { } } // #53114: should eventually be accepted too - | ^ value used here after move - -error[E0382]: use of partially moved value: `mm` - --> $DIR/issue-53114-borrow-checks.rs:27:11 - | -LL | match mm { (_x, _) => { } } - | -- value partially moved here -LL | match mm { (_, _y) => { } } - | ^^ value used here after partial move - | - = note: partial move occurs because `mm.0` has type `M`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | match mm { (ref _x, _) => { } } - | +++ - -error[E0382]: use of partially moved value: `mm` - --> $DIR/issue-53114-borrow-checks.rs:29:11 - | -LL | match mm { (_, _y) => { } } - | -- value partially moved here -LL | -LL | match mm { (_, _) => { } } - | ^^ value used here after partial move - | - = note: partial move occurs because `mm.1` has type `M`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | match mm { (_, ref _y) => { } } - | +++ - -error[E0382]: use of moved value: `m` - --> $DIR/issue-53114-borrow-checks.rs:36:16 - | -LL | let m = M; - | - move occurs because `m` has type `M`, which does not implement the `Copy` trait -LL | drop(m); - | - value moved here -LL | if let _ = m { } // #53114: should eventually be accepted too - | ^ value used here after move - -error[E0382]: use of partially moved value: `mm` - --> $DIR/issue-53114-borrow-checks.rs:41:22 - | -LL | if let (_x, _) = mm { } - | -- value partially moved here -LL | if let (_, _y) = mm { } - | ^^ value used here after partial move - | - = note: partial move occurs because `mm.0` has type `M`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | if let (ref _x, _) = mm { } - | +++ - -error[E0382]: use of partially moved value: `mm` - --> $DIR/issue-53114-borrow-checks.rs:43:21 - | -LL | if let (_, _y) = mm { } - | -- value partially moved here -LL | -LL | if let (_, _) = mm { } - | ^^ value used here after partial move - | - = note: partial move occurs because `mm.1` has type `M`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | if let (_, ref _y) = mm { } - | +++ - -error: aborting due to 6 previous errors - -For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/borrowck/borrowck-move-out-from-array-match.rs b/tests/ui/borrowck/borrowck-move-out-from-array-match.rs index ced4d002b38..d2a5da66de9 100644 --- a/tests/ui/borrowck/borrowck-move-out-from-array-match.rs +++ b/tests/ui/borrowck/borrowck-move-out-from-array-match.rs @@ -42,8 +42,8 @@ fn move_out_by_const_index_and_subslice() { [_x, _, _] => {} } match a { - //~^ ERROR use of partially moved value [_y @ .., _, _] => {} + //~^ ERROR use of partially moved value } } @@ -53,8 +53,8 @@ fn move_out_by_const_index_end_and_subslice() { [.., _x] => {} } match a { - //~^ ERROR use of partially moved value [_, _, _y @ ..] => {} + //~^ ERROR use of partially moved value } } @@ -64,8 +64,8 @@ fn move_out_by_const_index_field_and_subslice() { [(_x, _), _, _] => {} } match a { - //~^ ERROR use of partially moved value [_y @ .., _, _] => {} + //~^ ERROR use of partially moved value } } @@ -75,8 +75,8 @@ fn move_out_by_const_index_end_field_and_subslice() { [.., (_x, _)] => {} } match a { - //~^ ERROR use of partially moved value [_, _, _y @ ..] => {} + //~^ ERROR use of partially moved value } } @@ -108,8 +108,8 @@ fn move_out_by_subslice_and_subslice() { [x @ .., _] => {} } match a { - //~^ ERROR use of partially moved value [_, _y @ ..] => {} + //~^ ERROR use of partially moved value } } diff --git a/tests/ui/borrowck/borrowck-move-out-from-array-match.stderr b/tests/ui/borrowck/borrowck-move-out-from-array-match.stderr index 67b00c1dd90..d827776845e 100644 --- a/tests/ui/borrowck/borrowck-move-out-from-array-match.stderr +++ b/tests/ui/borrowck/borrowck-move-out-from-array-match.stderr @@ -44,13 +44,13 @@ LL | [_, _, (ref _x, _)] => {} | +++ error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-match.rs:44:11 + --> $DIR/borrowck-move-out-from-array-match.rs:45:10 | LL | [_x, _, _] => {} | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move +... +LL | [_y @ .., _, _] => {} + | ^^ value used here after partial move | = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait help: borrow this binding in the pattern to avoid moving the value @@ -59,13 +59,13 @@ LL | [ref _x, _, _] => {} | +++ error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-match.rs:55:11 + --> $DIR/borrowck-move-out-from-array-match.rs:56:16 | LL | [.., _x] => {} | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move +... +LL | [_, _, _y @ ..] => {} + | ^^ value used here after partial move | = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait help: borrow this binding in the pattern to avoid moving the value @@ -74,13 +74,13 @@ LL | [.., ref _x] => {} | +++ error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-match.rs:66:11 + --> $DIR/borrowck-move-out-from-array-match.rs:67:10 | LL | [(_x, _), _, _] => {} | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move +... +LL | [_y @ .., _, _] => {} + | ^^ value used here after partial move | = note: partial move occurs because `a[..].0` has type `String`, which does not implement the `Copy` trait help: borrow this binding in the pattern to avoid moving the value @@ -89,13 +89,13 @@ LL | [(ref _x, _), _, _] => {} | +++ error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-match.rs:77:11 + --> $DIR/borrowck-move-out-from-array-match.rs:78:16 | LL | [.., (_x, _)] => {} | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move +... +LL | [_, _, _y @ ..] => {} + | ^^ value used here after partial move | = note: partial move occurs because `a[..].0` has type `String`, which does not implement the `Copy` trait help: borrow this binding in the pattern to avoid moving the value @@ -134,13 +134,13 @@ LL | [_, _, ref _y @ ..] => {} | +++ error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-match.rs:110:11 + --> $DIR/borrowck-move-out-from-array-match.rs:111:13 | LL | [x @ .., _] => {} | - value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move +... +LL | [_, _y @ ..] => {} + | ^^ value used here after partial move | = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait help: borrow this binding in the pattern to avoid moving the value diff --git a/tests/ui/borrowck/borrowck-move-out-from-array-no-overlap-match.rs b/tests/ui/borrowck/borrowck-move-out-from-array-no-overlap-match.rs index 97db70f34cc..1e401b7e92e 100644 --- a/tests/ui/borrowck/borrowck-move-out-from-array-no-overlap-match.rs +++ b/tests/ui/borrowck/borrowck-move-out-from-array-no-overlap-match.rs @@ -1,3 +1,4 @@ +// check-pass // Due to #53114, which causes a "read" of the `_` patterns, // the borrow-checker refuses this code, while it should probably be allowed. // Once the bug is fixed, the test, which is derived from a @@ -15,7 +16,6 @@ fn move_out_from_begin_and_one_from_end() { [_, _, _x] => {} } match a { - //~^ ERROR use of partially moved value [.., _y, _] => {} } } @@ -26,7 +26,6 @@ fn move_out_from_begin_field_and_end_field() { [_, _, (_x, _)] => {} } match a { - //~^ ERROR use of partially moved value [.., (_, _y)] => {} } } @@ -39,7 +38,6 @@ fn move_out_by_const_index_and_subslice() { [_x, _, _] => {} } match a { - //~^ ERROR use of partially moved value [_, _y @ ..] => {} } } @@ -50,7 +48,6 @@ fn move_out_by_const_index_end_and_subslice() { [.., _x] => {} } match a { - //~^ ERROR use of partially moved value [_y @ .., _] => {} } } @@ -61,7 +58,6 @@ fn move_out_by_const_index_field_and_subslice() { [(_x, _), _, _] => {} } match a { - //~^ ERROR use of partially moved value [_, _y @ ..] => {} } } @@ -72,7 +68,6 @@ fn move_out_by_const_index_end_field_and_subslice() { [.., (_x, _)] => {} } match a { - //~^ ERROR use of partially moved value [_y @ .., _] => {} } } @@ -83,7 +78,6 @@ fn move_out_by_const_subslice_and_index_field() { [_, _y @ ..] => {} } match a { - //~^ ERROR use of partially moved value [(_x, _), _, _] => {} } } @@ -94,7 +88,6 @@ fn move_out_by_const_subslice_and_end_index_field() { [_y @ .., _] => {} } match a { - //~^ ERROR use of partially moved value [.., (_x, _)] => {} } } @@ -107,7 +100,6 @@ fn move_out_by_subslice_and_subslice() { [x @ .., _, _] => {} } match a { - //~^ ERROR use of partially moved value [_, _y @ ..] => {} } } diff --git a/tests/ui/borrowck/borrowck-move-out-from-array-no-overlap-match.stderr b/tests/ui/borrowck/borrowck-move-out-from-array-no-overlap-match.stderr deleted file mode 100644 index 47429ea3eeb..00000000000 --- a/tests/ui/borrowck/borrowck-move-out-from-array-no-overlap-match.stderr +++ /dev/null @@ -1,138 +0,0 @@ -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:17:11 - | -LL | [_, _, _x] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [_, _, ref _x] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:28:11 - | -LL | [_, _, (_x, _)] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..].0` has type `String`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [_, _, (ref _x, _)] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:41:11 - | -LL | [_x, _, _] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [ref _x, _, _] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:52:11 - | -LL | [.., _x] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [.., ref _x] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:63:11 - | -LL | [(_x, _), _, _] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..].0` has type `String`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [(ref _x, _), _, _] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:74:11 - | -LL | [.., (_x, _)] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..].0` has type `String`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [.., (ref _x, _)] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:85:11 - | -LL | [_, _y @ ..] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [_, ref _y @ ..] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:96:11 - | -LL | [_y @ .., _] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [ref _y @ .., _] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:109:11 - | -LL | [x @ .., _, _] => {} - | - value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [ref x @ .., _, _] => {} - | +++ - -error: aborting due to 9 previous errors - -For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/borrowck/borrowck-move-out-from-array-use-match.rs b/tests/ui/borrowck/borrowck-move-out-from-array-use-match.rs index 604a25cdcc1..fbcf126f3ea 100644 --- a/tests/ui/borrowck/borrowck-move-out-from-array-use-match.rs +++ b/tests/ui/borrowck/borrowck-move-out-from-array-use-match.rs @@ -42,8 +42,8 @@ fn move_out_by_const_index_and_subslice() { [_x, _, _] => {} } match a { - //~^ ERROR [E0382] [ref _y @ .., _, _] => {} + //~^ ERROR [E0382] } } @@ -53,8 +53,8 @@ fn move_out_by_const_index_end_and_subslice() { [.., _x] => {} } match a { - //~^ ERROR [E0382] [_, _, ref _y @ ..] => {} + //~^ ERROR [E0382] } } @@ -64,8 +64,8 @@ fn move_out_by_const_index_field_and_subslice() { [(_x, _), _, _] => {} } match a { - //~^ ERROR [E0382] [ref _y @ .., _, _] => {} + //~^ ERROR [E0382] } } @@ -75,8 +75,8 @@ fn move_out_by_const_index_end_field_and_subslice() { [.., (_x, _)] => {} } match a { - //~^ ERROR [E0382] [_, _, ref _y @ ..] => {} + //~^ ERROR [E0382] } } @@ -108,8 +108,8 @@ fn move_out_by_subslice_and_subslice() { [x @ .., _] => {} } match a { - //~^ ERROR [E0382] [_, ref _y @ ..] => {} + //~^ ERROR [E0382] } } diff --git a/tests/ui/borrowck/borrowck-move-out-from-array-use-match.stderr b/tests/ui/borrowck/borrowck-move-out-from-array-use-match.stderr index bfab13d42d2..da76b5c4a65 100644 --- a/tests/ui/borrowck/borrowck-move-out-from-array-use-match.stderr +++ b/tests/ui/borrowck/borrowck-move-out-from-array-use-match.stderr @@ -43,14 +43,14 @@ help: borrow this binding in the pattern to avoid moving the value LL | [_, _, (ref _x, _)] => {} | +++ -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-use-match.rs:44:11 +error[E0382]: borrow of partially moved value: `a` + --> $DIR/borrowck-move-out-from-array-use-match.rs:45:10 | LL | [_x, _, _] => {} | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move +... +LL | [ref _y @ .., _, _] => {} + | ^^^^^^ value borrowed here after partial move | = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait help: borrow this binding in the pattern to avoid moving the value @@ -58,14 +58,14 @@ help: borrow this binding in the pattern to avoid moving the value LL | [ref _x, _, _] => {} | +++ -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-use-match.rs:55:11 +error[E0382]: borrow of partially moved value: `a` + --> $DIR/borrowck-move-out-from-array-use-match.rs:56:16 | LL | [.., _x] => {} | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move +... +LL | [_, _, ref _y @ ..] => {} + | ^^^^^^ value borrowed here after partial move | = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait help: borrow this binding in the pattern to avoid moving the value @@ -73,14 +73,14 @@ help: borrow this binding in the pattern to avoid moving the value LL | [.., ref _x] => {} | +++ -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-use-match.rs:66:11 +error[E0382]: borrow of partially moved value: `a` + --> $DIR/borrowck-move-out-from-array-use-match.rs:67:10 | LL | [(_x, _), _, _] => {} | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move +... +LL | [ref _y @ .., _, _] => {} + | ^^^^^^ value borrowed here after partial move | = note: partial move occurs because `a[..].0` has type `String`, which does not implement the `Copy` trait help: borrow this binding in the pattern to avoid moving the value @@ -88,14 +88,14 @@ help: borrow this binding in the pattern to avoid moving the value LL | [(ref _x, _), _, _] => {} | +++ -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-use-match.rs:77:11 +error[E0382]: borrow of partially moved value: `a` + --> $DIR/borrowck-move-out-from-array-use-match.rs:78:16 | LL | [.., (_x, _)] => {} | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move +... +LL | [_, _, ref _y @ ..] => {} + | ^^^^^^ value borrowed here after partial move | = note: partial move occurs because `a[..].0` has type `String`, which does not implement the `Copy` trait help: borrow this binding in the pattern to avoid moving the value @@ -133,14 +133,14 @@ help: borrow this binding in the pattern to avoid moving the value LL | [_, _, ref _y @ ..] => {} | +++ -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-use-match.rs:110:11 +error[E0382]: borrow of partially moved value: `a` + --> $DIR/borrowck-move-out-from-array-use-match.rs:111:13 | LL | [x @ .., _] => {} | - value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move +... +LL | [_, ref _y @ ..] => {} + | ^^^^^^ value borrowed here after partial move | = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait help: borrow this binding in the pattern to avoid moving the value diff --git a/tests/ui/borrowck/borrowck-move-out-from-array-use-no-overlap-match.rs b/tests/ui/borrowck/borrowck-move-out-from-array-use-no-overlap-match.rs index 017ca90b81a..2f6ce430b35 100644 --- a/tests/ui/borrowck/borrowck-move-out-from-array-use-no-overlap-match.rs +++ b/tests/ui/borrowck/borrowck-move-out-from-array-use-no-overlap-match.rs @@ -1,3 +1,4 @@ +// check-pass // Due to #53114, which causes a "read" of the `_` patterns, // the borrow-checker refuses this code, while it should probably be allowed. // Once the bug is fixed, the test, which is derived from a @@ -15,7 +16,6 @@ fn move_out_from_begin_and_one_from_end() { [_, _, _x] => {} } match a { - //~^ ERROR use of partially moved value [.., ref _y, _] => {} } } @@ -26,7 +26,6 @@ fn move_out_from_begin_field_and_end_field() { [_, _, (_x, _)] => {} } match a { - //~^ ERROR use of partially moved value [.., (_, ref _y)] => {} } } @@ -39,7 +38,6 @@ fn move_out_by_const_index_and_subslice() { [_x, _, _] => {} } match a { - //~^ ERROR use of partially moved value [_, ref _y @ ..] => {} } } @@ -50,7 +48,6 @@ fn move_out_by_const_index_end_and_subslice() { [.., _x] => {} } match a { - //~^ ERROR use of partially moved value [ref _y @ .., _] => {} } } @@ -61,7 +58,6 @@ fn move_out_by_const_index_field_and_subslice() { [(_x, _), _, _] => {} } match a { - //~^ ERROR use of partially moved value [_, ref _y @ ..] => {} } } @@ -72,7 +68,6 @@ fn move_out_by_const_index_end_field_and_subslice() { [.., (_x, _)] => {} } match a { - //~^ ERROR use of partially moved value [ref _y @ .., _] => {} } } @@ -83,7 +78,6 @@ fn move_out_by_const_subslice_and_index_field() { [_, _y @ ..] => {} } match a { - //~^ ERROR use of partially moved value [(ref _x, _), _, _] => {} } } @@ -94,7 +88,6 @@ fn move_out_by_const_subslice_and_end_index_field() { [_y @ .., _] => {} } match a { - //~^ ERROR use of partially moved value [.., (ref _x, _)] => {} } } @@ -107,7 +100,6 @@ fn move_out_by_subslice_and_subslice() { [x @ .., _, _] => {} } match a { - //~^ ERROR use of partially moved value [_, ref _y @ ..] => {} } } diff --git a/tests/ui/borrowck/borrowck-move-out-from-array-use-no-overlap-match.stderr b/tests/ui/borrowck/borrowck-move-out-from-array-use-no-overlap-match.stderr deleted file mode 100644 index 8412c24fe61..00000000000 --- a/tests/ui/borrowck/borrowck-move-out-from-array-use-no-overlap-match.stderr +++ /dev/null @@ -1,138 +0,0 @@ -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:17:11 - | -LL | [_, _, _x] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [_, _, ref _x] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:28:11 - | -LL | [_, _, (_x, _)] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..].0` has type `String`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [_, _, (ref _x, _)] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:41:11 - | -LL | [_x, _, _] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [ref _x, _, _] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:52:11 - | -LL | [.., _x] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [.., ref _x] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:63:11 - | -LL | [(_x, _), _, _] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..].0` has type `String`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [(ref _x, _), _, _] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:74:11 - | -LL | [.., (_x, _)] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..].0` has type `String`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [.., (ref _x, _)] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:85:11 - | -LL | [_, _y @ ..] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [_, ref _y @ ..] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:96:11 - | -LL | [_y @ .., _] => {} - | -- value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [ref _y @ .., _] => {} - | +++ - -error[E0382]: use of partially moved value: `a` - --> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:109:11 - | -LL | [x @ .., _, _] => {} - | - value partially moved here -LL | } -LL | match a { - | ^ value used here after partial move - | - = note: partial move occurs because `a[..]` has type `(String, String)`, which does not implement the `Copy` trait -help: borrow this binding in the pattern to avoid moving the value - | -LL | [ref x @ .., _, _] => {} - | +++ - -error: aborting due to 9 previous errors - -For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/borrowck/issue-62107-match-arm-scopes.rs b/tests/ui/borrowck/issue-62107-match-arm-scopes.rs index 93ce34d2fe5..7dbcad9d37f 100644 --- a/tests/ui/borrowck/issue-62107-match-arm-scopes.rs +++ b/tests/ui/borrowck/issue-62107-match-arm-scopes.rs @@ -1,8 +1,8 @@ fn main() { let e: i32; match e { - //~^ ERROR E0381 ref u if true => {} + //~^ ERROR E0381 ref v if true => { let tx = 0; &tx; diff --git a/tests/ui/borrowck/issue-62107-match-arm-scopes.stderr b/tests/ui/borrowck/issue-62107-match-arm-scopes.stderr index 9683da919aa..8fe8fa71064 100644 --- a/tests/ui/borrowck/issue-62107-match-arm-scopes.stderr +++ b/tests/ui/borrowck/issue-62107-match-arm-scopes.stderr @@ -1,10 +1,11 @@ error[E0381]: used binding `e` isn't initialized - --> $DIR/issue-62107-match-arm-scopes.rs:3:11 + --> $DIR/issue-62107-match-arm-scopes.rs:4:9 | LL | let e: i32; | - binding declared here but left uninitialized LL | match e { - | ^ `e` used here but it isn't initialized +LL | ref u if true => {} + | ^^^^^ `e` used here but it isn't initialized | help: consider assigning a value | diff --git a/tests/ui/borrowck/let_underscore_temporary.rs b/tests/ui/borrowck/let_underscore_temporary.rs index 835cd20798f..a5ea3b3a7ab 100644 --- a/tests/ui/borrowck/let_underscore_temporary.rs +++ b/tests/ui/borrowck/let_underscore_temporary.rs @@ -52,4 +52,42 @@ fn let_ascribe(string: &Option<&str>, mut num: Option) { }; } +fn matched(string: &Option<&str>, mut num: Option) { + match if let Some(s) = *string { s.len() } else { 0 } { + _ => {} + }; + match if let Some(s) = &num { s } else { &0 } { + _ => {} + }; + match if let Some(s) = &mut num { + *s += 1; + s + } else { + &mut 0 + //~^ ERROR temporary value dropped while borrowed + } { + _ => {} + }; + match if let Some(ref s) = num { s } else { &0 } { + _ => {} + }; + match if let Some(mut s) = num { + s += 1; + s + } else { + 0 + } { + _ => {} + }; + match if let Some(ref mut s) = num { + *s += 1; + s + } else { + &mut 0 + //~^ ERROR temporary value dropped while borrowed + } { + _ => {} + }; +} + fn main() {} diff --git a/tests/ui/borrowck/let_underscore_temporary.stderr b/tests/ui/borrowck/let_underscore_temporary.stderr index 74f3598c4d0..6bccf329181 100644 --- a/tests/ui/borrowck/let_underscore_temporary.stderr +++ b/tests/ui/borrowck/let_underscore_temporary.stderr @@ -74,6 +74,44 @@ LL | | }; | = note: consider using a `let` binding to create a longer lived value -error: aborting due to 4 previous errors +error[E0716]: temporary value dropped while borrowed + --> $DIR/let_underscore_temporary.rs:66:14 + | +LL | match if let Some(s) = &mut num { + | ___________- +LL | | *s += 1; +LL | | s +LL | | } else { +LL | | &mut 0 + | | ^ creates a temporary value which is freed while still in use +LL | | +LL | | } { + | | - + | | | + | |_____temporary value is freed at the end of this statement + | borrow later used here + | + = note: consider using a `let` binding to create a longer lived value + +error[E0716]: temporary value dropped while borrowed + --> $DIR/let_underscore_temporary.rs:86:14 + | +LL | match if let Some(ref mut s) = num { + | ___________- +LL | | *s += 1; +LL | | s +LL | | } else { +LL | | &mut 0 + | | ^ creates a temporary value which is freed while still in use +LL | | +LL | | } { + | | - + | | | + | |_____temporary value is freed at the end of this statement + | borrow later used here + | + = note: consider using a `let` binding to create a longer lived value + +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0716`. diff --git a/tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.32bit.stderr b/tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.32bit.stderr index de59d743b17..492d8718a13 100644 --- a/tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.32bit.stderr +++ b/tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.32bit.stderr @@ -108,6 +108,11 @@ help: skipping check that does not even have a feature gate | LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +help: skipping check that does not even have a feature gate + --> $DIR/const_refers_to_static_cross_crate.rs:27:20 + | +LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 8 previous errors; 1 warning emitted diff --git a/tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr b/tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr index e62520ef6ad..f6d82d6c0ba 100644 --- a/tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr +++ b/tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr @@ -108,6 +108,11 @@ help: skipping check that does not even have a feature gate | LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +help: skipping check that does not even have a feature gate + --> $DIR/const_refers_to_static_cross_crate.rs:27:20 + | +LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 8 previous errors; 1 warning emitted diff --git a/tests/ui/error-codes/E0396.rs b/tests/ui/error-codes/E0396.rs index 4415b70e75e..383eda3d636 100644 --- a/tests/ui/error-codes/E0396.rs +++ b/tests/ui/error-codes/E0396.rs @@ -9,9 +9,11 @@ const unsafe fn unreachable() -> ! { const INFALLIBLE: *mut Infallible = &[] as *const [Infallible] as *const _ as _; match *INFALLIBLE {} //~^ ERROR dereferencing raw mutable pointers in constant functions is unstable + //~| ERROR dereferencing raw mutable pointers in constant functions is unstable const BAD: () = unsafe { match *INFALLIBLE {} }; //~^ ERROR dereferencing raw mutable pointers in constants is unstable + //~| ERROR dereferencing raw mutable pointers in constants is unstable } fn main() { diff --git a/tests/ui/error-codes/E0396.stderr b/tests/ui/error-codes/E0396.stderr index 8c87f40674f..a84a1216e0a 100644 --- a/tests/ui/error-codes/E0396.stderr +++ b/tests/ui/error-codes/E0396.stderr @@ -16,8 +16,18 @@ LL | match *INFALLIBLE {} = note: see issue #57349 for more information = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable +error[E0658]: dereferencing raw mutable pointers in constant functions is unstable + --> $DIR/E0396.rs:10:11 + | +LL | match *INFALLIBLE {} + | ^^^^^^^^^^^ + | + = note: see issue #57349 for more information + = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + error[E0658]: dereferencing raw mutable pointers in constants is unstable - --> $DIR/E0396.rs:13:36 + --> $DIR/E0396.rs:14:36 | LL | const BAD: () = unsafe { match *INFALLIBLE {} }; | ^^^^^^^^^^^ @@ -25,6 +35,16 @@ LL | const BAD: () = unsafe { match *INFALLIBLE {} }; = note: see issue #57349 for more information = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable -error: aborting due to 3 previous errors +error[E0658]: dereferencing raw mutable pointers in constants is unstable + --> $DIR/E0396.rs:14:36 + | +LL | const BAD: () = unsafe { match *INFALLIBLE {} }; + | ^^^^^^^^^^^ + | + = note: see issue #57349 for more information + = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/rfcs/rfc-2294-if-let-guard/move-guard-if-let-chain.stderr b/tests/ui/rfcs/rfc-2294-if-let-guard/move-guard-if-let-chain.stderr index d27fde58244..087e54244b3 100644 --- a/tests/ui/rfcs/rfc-2294-if-let-guard/move-guard-if-let-chain.stderr +++ b/tests/ui/rfcs/rfc-2294-if-let-guard/move-guard-if-let-chain.stderr @@ -1,5 +1,5 @@ error[E0382]: use of moved value: `x` - --> $DIR/move-guard-if-let-chain.rs:12:27 + --> $DIR/move-guard-if-let-chain.rs:12:23 | LL | let x: Box<_> = Box::new(1); | - move occurs because `x` has type `Box`, which does not implement the `Copy` trait @@ -7,7 +7,7 @@ LL | let x: Box<_> = Box::new(1); LL | (1, 2) if let y = x && c => (), | - value moved here LL | (1, 2) if let z = x => (), - | ^ value used here after move + | ^ value used here after move | help: borrow this binding in the pattern to avoid moving the value | @@ -15,7 +15,7 @@ LL | (1, 2) if let ref y = x && c => (), | +++ error[E0382]: use of moved value: `x` - --> $DIR/move-guard-if-let-chain.rs:36:27 + --> $DIR/move-guard-if-let-chain.rs:36:23 | LL | let x: Box<_> = Box::new(1); | - move occurs because `x` has type `Box`, which does not implement the `Copy` trait @@ -23,7 +23,7 @@ LL | let x: Box<_> = Box::new(1); LL | (1, _) if let y = x && c => (), | - value moved here LL | (_, 2) if let z = x => (), - | ^ value used here after move + | ^ value used here after move | help: borrow this binding in the pattern to avoid moving the value | @@ -31,15 +31,13 @@ LL | (1, _) if let ref y = x && c => (), | +++ error[E0382]: use of moved value: `x` - --> $DIR/move-guard-if-let-chain.rs:59:36 + --> $DIR/move-guard-if-let-chain.rs:59:32 | LL | let x: Box<_> = Box::new(1); | - move occurs because `x` has type `Box`, which does not implement the `Copy` trait ... LL | (1, _) | (_, 2) if let y = x && c => (), - | - ^ value used here after move - | | - | value moved here + | ^ value used here after move | help: borrow this binding in the pattern to avoid moving the value | diff --git a/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-move-semantics.stderr b/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-move-semantics.stderr index e97fdcce1c1..9dc339abc06 100644 --- a/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-move-semantics.stderr +++ b/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-move-semantics.stderr @@ -1,13 +1,14 @@ error[E0382]: use of moved value: `a` - --> $DIR/dbg-macro-move-semantics.rs:9:18 + --> $DIR/dbg-macro-move-semantics.rs:9:13 | LL | let a = NoCopy(0); | - move occurs because `a` has type `NoCopy`, which does not implement the `Copy` trait LL | let _ = dbg!(a); | ------- value moved here LL | let _ = dbg!(a); - | ^ value used here after move + | ^^^^^^^ value used here after move | + = note: this error originates in the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error