]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_mir/borrow_check/nll.rs
Rollup merge of #70038 - DutchGhost:const-forget-tests, r=RalfJung
[rust.git] / src / librustc_mir / borrow_check / nll.rs
index 2201abe4b92f998159064c68802982e2589ea261..077ed49ed2cacc8fc248a8e1f5c3ed561b36536f 100644 (file)
@@ -86,15 +86,18 @@ fn populate_polonius_move_facts(
     body: &Body<'_>,
 ) {
     all_facts
-        .path_belongs_to_var
+        .path_is_var
         .extend(move_data.rev_lookup.iter_locals_enumerated().map(|(v, &m)| (m, v)));
 
     for (child, move_path) in move_data.move_paths.iter_enumerated() {
-        all_facts
-            .child
-            .extend(move_path.parents(&move_data.move_paths).map(|(parent, _)| (child, parent)));
+        if let Some(parent) = move_path.parent {
+            all_facts.child_path.push((child, parent));
+        }
     }
 
+    let fn_entry_start = location_table
+        .start_index(Location { block: BasicBlock::from_u32(0u32), statement_index: 0 });
+
     // initialized_at
     for init in move_data.inits.iter() {
         match init.location {
@@ -115,28 +118,37 @@ fn populate_polonius_move_facts(
                         // the successors, but not in the unwind block.
                         let first_statement = Location { block: successor, statement_index: 0 };
                         all_facts
-                            .initialized_at
+                            .path_assigned_at_base
                             .push((init.path, location_table.start_index(first_statement)));
                     }
                 } else {
                     // In all other cases, the initialization just happens at the
                     // midpoint, like any other effect.
-                    all_facts.initialized_at.push((init.path, location_table.mid_index(location)));
+                    all_facts
+                        .path_assigned_at_base
+                        .push((init.path, location_table.mid_index(location)));
                 }
             }
             // Arguments are initialized on function entry
             InitLocation::Argument(local) => {
                 assert!(body.local_kind(local) == LocalKind::Arg);
-                let fn_entry = Location { block: BasicBlock::from_u32(0u32), statement_index: 0 };
-                all_facts.initialized_at.push((init.path, location_table.start_index(fn_entry)));
+                all_facts.path_assigned_at_base.push((init.path, fn_entry_start));
             }
         }
     }
 
+    for (local, &path) in move_data.rev_lookup.iter_locals_enumerated() {
+        if body.local_kind(local) != LocalKind::Arg {
+            // Non-arguments start out deinitialised; we simulate this with an
+            // initial move:
+            all_facts.path_moved_at_base.push((path, fn_entry_start));
+        }
+    }
+
     // moved_out_at
     // deinitialisation is assumed to always happen!
     all_facts
-        .moved_out_at
+        .path_moved_at_base
         .extend(move_data.moves.iter().map(|mo| (mo.path, location_table.mid_index(mo.source))));
 }
 
@@ -260,7 +272,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
     // Dump facts if requested.
     let polonius_output = all_facts.and_then(|all_facts| {
         if infcx.tcx.sess.opts.debugging_opts.nll_facts {
-            let def_path = infcx.tcx.hir().def_path(def_id);
+            let def_path = infcx.tcx.def_path(def_id);
             let dir_path =
                 PathBuf::from("nll-facts").join(def_path.to_filename_friendly_no_crate());
             all_facts.write_to_dir(dir_path, location_table).unwrap();