Skip to content

Commit 9d35587

Browse files
committed
work around weird match arm lifetimes
1 parent 66c032c commit 9d35587

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/librustc_mir/dataflow/impls/mod.rs

+23-3
Original file line numberDiff line numberDiff line change
@@ -585,9 +585,29 @@ impl<'a, 'gcx, 'tcx> BitDenotation for EverInitializedLvals<'a, 'gcx, 'tcx> {
585585
sets.gen_all(&init_loc_map[location]);
586586

587587
match stmt.kind {
588-
mir::StatementKind::StorageDead(local) => {
589-
// End inits for StorageDead, so that an immutable variable can
590-
// be reinitialized on the next iteration of the loop.
588+
mir::StatementKind::StorageDead(local) |
589+
mir::StatementKind::StorageLive(local) => {
590+
// End inits for StorageDead and StorageLive, so that an immutable
591+
// variable can be reinitialized on the next iteration of the loop.
592+
//
593+
// FIXME(#46525): We *need* to do this for StorageLive as well as
594+
// StorageDead, because lifetimes of match bindings with guards are
595+
// weird - i.e. this code
596+
//
597+
// ```
598+
// fn main() {
599+
// match 0 {
600+
// a | a
601+
// if { println!("a={}", a); false } => {}
602+
// _ => {}
603+
// }
604+
// }
605+
// ```
606+
//
607+
// runs the guard twice, using the same binding for `a`, and only
608+
// storagedeads after everything ends, so if we don't regard the
609+
// storagelive as killing storage, we would have a multiple assignment
610+
// to immutable data error.
591611
if let LookupResult::Exact(mpi) = rev_lookup.find(&mir::Place::Local(local)) {
592612
debug!("stmt {:?} at loc {:?} clears the ever initialized status of {:?}",
593613
stmt, location, &init_path_map[mpi]);

src/test/run-pass/match-pipe-binding.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// compile-flags: -Z borrowck=compare
1112

1213
fn test1() {
1314
// from issue 6338

0 commit comments

Comments
 (0)