]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #69612 - Dylan-DPC:rollup-f180gcc, r=Dylan-DPC
authorbors <bors@rust-lang.org>
Sun, 1 Mar 2020 17:39:05 +0000 (17:39 +0000)
committerbors <bors@rust-lang.org>
Sun, 1 Mar 2020 17:39:05 +0000 (17:39 +0000)
Rollup of 7 pull requests

Successful merges:

 - #69504 (Use assert_ne in hash tests)
 - #69554 (Cleanup e0374)
 - #69568 (Clarify explanation of Vec<T> 'fn resize')
 - #69569 (simplify boolean expressions)
 - #69577 (Clean up E0375 explanation)
 - #69598 (rustdoc: HTML escape crate version)
 - #69607 (Clean up E0376 explanation)

Failed merges:

r? @ghost

src/librustc/hir/map/mod.rs
src/librustc/hir/mod.rs
src/librustc/query/mod.rs
src/librustc/ty/mod.rs
src/librustc_lint/unused.rs
src/librustc_mir_build/hair/pattern/check_match.rs
src/librustc_passes/liveness.rs
src/librustc_privacy/lib.rs
src/librustc_typeck/check/method/suggest.rs
src/librustdoc/passes/collect_intra_doc_links.rs

index b208826560512dfc6dddec82357138e2c3b82f78..4f7c4153ea173e773f6787188497e4830a441eac 100644 (file)
@@ -746,15 +746,9 @@ pub fn get_parent_item(&self, hir_id: HirId) -> HirId {
         hir_id
     }
 
-    /// Returns the `DefId` of `id`'s nearest module parent, or `id` itself if no
-    /// module parent is in this map.
-    pub fn get_module_parent(&self, id: HirId) -> DefId {
-        self.local_def_id(self.get_module_parent_node(id))
-    }
-
     /// Returns the `HirId` of `id`'s nearest module parent, or `id` itself if no
     /// module parent is in this map.
-    pub fn get_module_parent_node(&self, hir_id: HirId) -> HirId {
+    pub(super) fn get_module_parent_node(&self, hir_id: HirId) -> HirId {
         for (hir_id, node) in self.parent_iter(hir_id) {
             if let Node::Item(&Item { kind: ItemKind::Mod(_), .. }) = node {
                 return hir_id;
index 7d48280661a64232a6487687ab4dfc9b10c09eeb..1aa3b27bd1a5dfb418bdb590ce8dc1098fd70b13 100644 (file)
@@ -7,9 +7,10 @@
 
 use crate::ty::query::Providers;
 use crate::ty::TyCtxt;
-use rustc_hir::def_id::LOCAL_CRATE;
+use rustc_hir::def_id::{DefId, LOCAL_CRATE};
 use rustc_hir::print;
 use rustc_hir::Crate;
+use rustc_hir::HirId;
 use std::ops::Deref;
 
 /// A wrapper type which allows you to access HIR.
@@ -45,9 +46,17 @@ impl<'tcx> TyCtxt<'tcx> {
     pub fn hir(self) -> Hir<'tcx> {
         Hir { tcx: self, map: &self.hir_map }
     }
+
+    pub fn parent_module(self, id: HirId) -> DefId {
+        self.parent_module_from_def_id(DefId::local(id.owner))
+    }
 }
 
 pub fn provide(providers: &mut Providers<'_>) {
+    providers.parent_module_from_def_id = |tcx, id| {
+        let hir = tcx.hir();
+        hir.local_def_id(hir.get_module_parent_node(hir.as_local_hir_id(id).unwrap()))
+    };
     providers.hir_crate = |tcx, _| tcx.hir_map.untracked_krate();
     map::provide(providers);
 }
index f3249f5014d5a4bfee2ea785f21b409c97726b7a..b3315cc3701daf1a3b52629b74244b1220892e37 100644 (file)
@@ -98,6 +98,10 @@ fn describe_as_module(def_id: DefId, tcx: TyCtxt<'_>) -> String {
             eval_always
             desc { "computing the lint levels for items in this crate" }
         }
+
+        query parent_module_from_def_id(_: DefId) -> DefId {
+            eval_always
+        }
     }
 
     Codegen {
index 89ff0b2a0ccbc1984d1480369d89f20049fc6368..c9e58b6c771c0883480e3b31c056c81451157108 100644 (file)
@@ -385,9 +385,7 @@ pub fn from_hir(visibility: &hir::Visibility<'_>, id: hir::HirId, tcx: TyCtxt<'_
                 Res::Err => Visibility::Public,
                 def => Visibility::Restricted(def.def_id()),
             },
-            hir::VisibilityKind::Inherited => {
-                Visibility::Restricted(tcx.hir().get_module_parent(id))
-            }
+            hir::VisibilityKind::Inherited => Visibility::Restricted(tcx.parent_module(id)),
         }
     }
 
@@ -3087,7 +3085,7 @@ pub fn adjust_ident_and_get_scope(
             Some(actual_expansion) => {
                 self.hir().definitions().parent_module_of_macro_def(actual_expansion)
             }
-            None => self.hir().get_module_parent(block),
+            None => self.parent_module(block),
         };
         (ident, scope)
     }
index 7b6741954d9c8b21d339a68c8a8ac2cc0f88011c..02f04b2345932cbe27cceebe415fa92cd9d6fcb0 100644 (file)
@@ -124,8 +124,7 @@ fn check_must_use_ty<'tcx>(
             descr_post: &str,
             plural_len: usize,
         ) -> bool {
-            if ty.is_unit()
-                || cx.tcx.is_ty_uninhabited_from(cx.tcx.hir().get_module_parent(expr.hir_id), ty)
+            if ty.is_unit() || cx.tcx.is_ty_uninhabited_from(cx.tcx.parent_module(expr.hir_id), ty)
             {
                 return true;
             }
index edd05ee0aa94ec75007d4a3436462f38aa969fe0..d0eefb2e4d14f0e4ecbab35bd3760cf93475dd64 100644 (file)
@@ -142,7 +142,7 @@ fn lower_pattern<'p>(
     }
 
     fn check_in_cx(&self, hir_id: HirId, f: impl FnOnce(MatchCheckCtxt<'_, 'tcx>)) {
-        let module = self.tcx.hir().get_module_parent(hir_id);
+        let module = self.tcx.parent_module(hir_id);
         MatchCheckCtxt::create_and_enter(self.tcx, self.param_env, module, |cx| f(cx));
     }
 
index 43b615dee9811f3f2783d82d5755050e6dafea59..5b6d0fc74e80f2966221980b663f38057893f294 100644 (file)
@@ -1125,7 +1125,7 @@ fn propagate_through_expr(&mut self, expr: &Expr<'_>, succ: LiveNode) -> LiveNod
             }
 
             hir::ExprKind::Call(ref f, ref args) => {
-                let m = self.ir.tcx.hir().get_module_parent(expr.hir_id);
+                let m = self.ir.tcx.parent_module(expr.hir_id);
                 let succ = if self.ir.tcx.is_ty_uninhabited_from(m, self.tables.expr_ty(expr)) {
                     self.s.exit_ln
                 } else {
@@ -1136,7 +1136,7 @@ fn propagate_through_expr(&mut self, expr: &Expr<'_>, succ: LiveNode) -> LiveNod
             }
 
             hir::ExprKind::MethodCall(.., ref args) => {
-                let m = self.ir.tcx.hir().get_module_parent(expr.hir_id);
+                let m = self.ir.tcx.parent_module(expr.hir_id);
                 let succ = if self.ir.tcx.is_ty_uninhabited_from(m, self.tables.expr_ty(expr)) {
                     self.s.exit_ln
                 } else {
index 0a27c323644a6fbd78f0320300fb918ca98ed25d..24696b203326f428df0519be4306c1c81dc7cf36 100644 (file)
@@ -327,7 +327,7 @@ fn def_id_visibility<'tcx>(
                 }
                 Node::Expr(expr) => {
                     return (
-                        ty::Visibility::Restricted(tcx.hir().get_module_parent(expr.hir_id)),
+                        ty::Visibility::Restricted(tcx.parent_module(expr.hir_id)),
                         expr.span,
                         "private",
                     );
index cd96a3ad9f1270feddd1042959e749047206cca0..95faa353e9b65c0b12ea1cef72b7103746d62654 100644 (file)
@@ -427,7 +427,7 @@ pub fn report_method_error<'b>(
                         });
 
                     if let Some((field, field_ty)) = field_receiver {
-                        let scope = self.tcx.hir().get_module_parent(self.body_id);
+                        let scope = self.tcx.parent_module(self.body_id);
                         let is_accessible = field.vis.is_accessible_from(scope, self.tcx);
 
                         if is_accessible {
@@ -824,7 +824,7 @@ fn suggest_use_candidates(
         mut msg: String,
         candidates: Vec<DefId>,
     ) {
-        let module_did = self.tcx.hir().get_module_parent(self.body_id);
+        let module_did = self.tcx.parent_module(self.body_id);
         let module_id = self.tcx.hir().as_local_hir_id(module_did).unwrap();
         let krate = self.tcx.hir().krate();
         let (span, found_use) = UsePlacementFinder::check(self.tcx, krate, module_id);
index ad121a667daf5f49afa1a9ce3159b271b725d57d..7aa90d667813fb8ecb40f8fdf3baa725291e439c 100644 (file)
@@ -348,7 +348,7 @@ fn fold_item(&mut self, mut item: Item) -> Option<Item> {
         let parent_node = self.cx.as_local_hir_id(item.def_id).and_then(|hir_id| {
             // FIXME: this fails hard for impls in non-module scope, but is necessary for the
             // current `resolve()` implementation.
-            match self.cx.tcx.hir().get_module_parent_node(hir_id) {
+            match self.cx.as_local_hir_id(self.cx.tcx.parent_module(hir_id)).unwrap() {
                 id if id != hir_id => Some(id),
                 _ => None,
             }