]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_mir/borrow_check/mod.rs
Auto merge of #64739 - guanqun:remove-as-str, r=estebank
[rust.git] / src / librustc_mir / borrow_check / mod.rs
index 5f18d4d774dc09316310b008d460b7a0d66d0c41..75d4b56fdb7c20480890b3e62c44380ef7ac0651 100644 (file)
 use rustc::ty::{self, TyCtxt};
 
 use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder};
-use rustc_data_structures::bit_set::BitSet;
+use rustc_index::bit_set::BitSet;
 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
 use rustc_data_structures::graph::dominators::Dominators;
-use rustc_data_structures::indexed_vec::IndexVec;
+use rustc_index::vec::IndexVec;
 use smallvec::SmallVec;
 
 use std::collections::BTreeMap;
@@ -235,7 +235,7 @@ fn do_mir_borrowck<'a, 'tcx>(
 
     let movable_generator = match tcx.hir().get(id) {
         Node::Expr(&hir::Expr {
-            node: hir::ExprKind::Closure(.., Some(hir::GeneratorMovability::Static)),
+            kind: hir::ExprKind::Closure(.., Some(hir::GeneratorMovability::Static)),
             ..
         }) => false,
         _ => true,
@@ -621,7 +621,7 @@ fn visit_terminator_entry(
                 target: _,
                 unwind: _,
             } => {
-                let gcx = self.infcx.tcx.global_tcx();
+                let tcx = self.infcx.tcx;
 
                 // Compute the type with accurate region information.
                 let drop_place_ty = drop_place.ty(self.body, self.infcx.tcx);
@@ -629,10 +629,10 @@ fn visit_terminator_entry(
                 // Erase the regions.
                 let drop_place_ty = self.infcx.tcx.erase_regions(&drop_place_ty).ty;
 
-                // "Lift" into the gcx -- once regions are erased, this type should be in the
+                // "Lift" into the tcx -- once regions are erased, this type should be in the
                 // global arenas; this "lift" operation basically just asserts that is true, but
                 // that is useful later.
-                gcx.lift_to_global(&drop_place_ty).unwrap();
+                tcx.lift(&drop_place_ty).unwrap();
 
                 debug!("visit_terminator_drop \
                         loc: {:?} term: {:?} drop_place: {:?} drop_place_ty: {:?} span: {:?}",
@@ -1932,48 +1932,28 @@ fn check_access_permissions(
                 }
             }
 
-            Reservation(wk @ WriteKind::Move)
-            | Write(wk @ WriteKind::Move)
-            | Reservation(wk @ WriteKind::StorageDeadOrDrop)
-            | Reservation(wk @ WriteKind::MutableBorrow(BorrowKind::Shared))
-            | Reservation(wk @ WriteKind::MutableBorrow(BorrowKind::Shallow))
-            | Write(wk @ WriteKind::StorageDeadOrDrop)
-            | Write(wk @ WriteKind::MutableBorrow(BorrowKind::Shared))
-            | Write(wk @ WriteKind::MutableBorrow(BorrowKind::Shallow)) => {
-                if let (Err(place_err), true) = (
+            Reservation(WriteKind::Move)
+            | Write(WriteKind::Move)
+            | Reservation(WriteKind::StorageDeadOrDrop)
+            | Reservation(WriteKind::MutableBorrow(BorrowKind::Shared))
+            | Reservation(WriteKind::MutableBorrow(BorrowKind::Shallow))
+            | Write(WriteKind::StorageDeadOrDrop)
+            | Write(WriteKind::MutableBorrow(BorrowKind::Shared))
+            | Write(WriteKind::MutableBorrow(BorrowKind::Shallow)) => {
+                if let (Err(_), true) = (
                     self.is_mutable(place.as_ref(), is_local_mutation_allowed),
                     self.errors_buffer.is_empty()
                 ) {
-                    if self.infcx.tcx.migrate_borrowck() {
-                        // rust-lang/rust#46908: In pure NLL mode this
-                        // code path should be unreachable (and thus
-                        // we signal an ICE in the else branch
-                        // here). But we can legitimately get here
-                        // under borrowck=migrate mode, so instead of
-                        // ICE'ing we instead report a legitimate
-                        // error (which will then be downgraded to a
-                        // warning by the migrate machinery).
-                        error_access = match wk {
-                            WriteKind::MutableBorrow(_) => AccessKind::MutableBorrow,
-                            WriteKind::Move => AccessKind::Move,
-                            WriteKind::StorageDeadOrDrop |
-                            WriteKind::Mutate => AccessKind::Mutate,
-                        };
-                        self.report_mutability_error(
-                            place,
-                            span,
-                            place_err,
-                            error_access,
-                            location,
-                        );
-                    } else {
-                        span_bug!(
-                            span,
-                            "Accessing `{:?}` with the kind `{:?}` shouldn't be possible",
-                            place,
-                            kind,
-                        );
-                    }
+                    // rust-lang/rust#46908: In pure NLL mode this code path should be
+                    // unreachable, but we use `delay_span_bug` because we can hit this when
+                    // dereferencing a non-Copy raw pointer *and* have `-Ztreat-err-as-bug`
+                    // enabled. We don't want to ICE for that case, as other errors will have
+                    // been emitted (#52262).
+                    self.infcx.tcx.sess.delay_span_bug(span, &format!(
+                        "Accessing `{:?}` with the kind `{:?}` shouldn't be possible",
+                        place,
+                        kind,
+                    ));
                 }
                 return false;
             }