]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_mir/borrow_check/mod.rs
Auto merge of #69227 - Marwes:buffer_stderr, r=varkor
[rust.git] / src / librustc_mir / borrow_check / mod.rs
index 941534e68fcad75c5a4cf4decdf36e27004f149b..aa49ab1b722d106b505e84d5df51cc546bb4e68a 100644 (file)
@@ -1,6 +1,5 @@
 //! This query borrow-checks the MIR to (further) ensure it is not broken.
 
-use rustc::infer::InferCtxt;
 use rustc::lint::builtin::MUTABLE_BORROW_RESERVATION_CONFLICT;
 use rustc::lint::builtin::UNUSED_MUT;
 use rustc::mir::{
@@ -20,6 +19,7 @@
 use rustc_hir::{def_id::DefId, HirId, Node};
 use rustc_index::bit_set::BitSet;
 use rustc_index::vec::IndexVec;
+use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
 
 use either::Either;
 use smallvec::SmallVec;
@@ -90,7 +90,7 @@ pub fn provide(providers: &mut Providers<'_>) {
     *providers = Providers { mir_borrowck, ..*providers };
 }
 
-fn mir_borrowck(tcx: TyCtxt<'_>, def_id: DefId) -> BorrowCheckResult<'_> {
+fn mir_borrowck(tcx: TyCtxt<'_>, def_id: DefId) -> &BorrowCheckResult<'_> {
     let (input_body, promoted) = tcx.mir_validated(def_id);
     debug!("run query mir_borrowck: {}", tcx.def_path_str(def_id));
 
@@ -101,7 +101,7 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def_id: DefId) -> BorrowCheckResult<'_> {
     });
     debug!("mir_borrowck done");
 
-    opt_closure_req
+    tcx.arena.alloc(opt_closure_req)
 }
 
 fn do_mir_borrowck<'a, 'tcx>(
@@ -136,6 +136,9 @@ fn do_mir_borrowck<'a, 'tcx>(
 
     // Gather the upvars of a closure, if any.
     let tables = tcx.typeck_tables_of(def_id);
+    if tables.tainted_by_errors {
+        infcx.set_tainted_by_errors();
+    }
     let upvars: Vec<_> = tables
         .upvar_list
         .get(&def_id)
@@ -195,27 +198,40 @@ fn do_mir_borrowck<'a, 'tcx>(
         Rc::new(BorrowSet::build(tcx, body, locals_are_invalidated_at_exit, &mdpe.move_data));
 
     // Compute non-lexical lifetimes.
-    let nll::NllOutput { regioncx, polonius_output, opt_closure_req, nll_errors } =
-        nll::compute_regions(
-            infcx,
-            def_id,
-            free_regions,
-            body,
-            &promoted,
-            location_table,
-            param_env,
-            &mut flow_inits,
-            &mdpe.move_data,
-            &borrow_set,
-        );
+    let nll::NllOutput {
+        regioncx,
+        opaque_type_values,
+        polonius_output,
+        opt_closure_req,
+        nll_errors,
+    } = nll::compute_regions(
+        infcx,
+        def_id,
+        free_regions,
+        body,
+        &promoted,
+        location_table,
+        param_env,
+        &mut flow_inits,
+        &mdpe.move_data,
+        &borrow_set,
+    );
 
     // Dump MIR results into a file, if that is enabled. This let us
     // write unit-tests, as well as helping with debugging.
     nll::dump_mir_results(infcx, MirSource::item(def_id), &body, &regioncx, &opt_closure_req);
 
-    // We also have a `#[rustc_nll]` annotation that causes us to dump
+    // We also have a `#[rustc_regions]` annotation that causes us to dump
     // information.
-    nll::dump_annotation(infcx, &body, def_id, &regioncx, &opt_closure_req, &mut errors_buffer);
+    nll::dump_annotation(
+        infcx,
+        &body,
+        def_id,
+        &regioncx,
+        &opt_closure_req,
+        &opaque_type_values,
+        &mut errors_buffer,
+    );
 
     // The various `flow_*` structures can be large. We drop `flow_inits` here
     // so it doesn't overlap with the others below. This reduces peak memory
@@ -349,7 +365,7 @@ fn do_mir_borrowck<'a, 'tcx>(
         // Skip over locals that begin with an underscore or have no name
         match mbcx.local_names[local] {
             Some(name) => {
-                if name.as_str().starts_with("_") {
+                if name.as_str().starts_with('_') {
                     continue;
                 }
             }
@@ -389,6 +405,7 @@ fn do_mir_borrowck<'a, 'tcx>(
     }
 
     let result = BorrowCheckResult {
+        concrete_opaque_types: opaque_type_values,
         closure_requirements: opt_closure_req,
         used_mut_upvars: mbcx.used_mut_upvars,
     };
@@ -1582,9 +1599,9 @@ fn check_if_subslice_element_is_moved(
     ) {
         if let Some(mpi) = self.move_path_for_place(place_span.0) {
             let move_paths = &self.move_data.move_paths;
-            let mut child = move_paths[mpi].first_child;
-            while let Some(child_mpi) = child {
-                let child_move_path = &move_paths[child_mpi];
+
+            let root_path = &move_paths[mpi];
+            for (child_mpi, child_move_path) in root_path.children(move_paths) {
                 let last_proj = child_move_path.place.projection.last().unwrap();
                 if let ProjectionElem::ConstantIndex { offset, from_end, .. } = last_proj {
                     debug_assert!(!from_end, "Array constant indexing shouldn't be `from_end`.");
@@ -1606,7 +1623,6 @@ fn check_if_subslice_element_is_moved(
                         }
                     }
                 }
-                child = child_move_path.next_sibling;
             }
         }
     }