From f86f7ad5f2d3eb6631e5fab57630a4fee9a50d01 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 3 Feb 2025 10:45:49 +1100 Subject: Move some `Map` methods onto `TyCtxt`. The end goal is to eliminate `Map` altogether. I added a `hir_` prefix to all of them, that seemed simplest. The exceptions are `module_items` which became `hir_module_free_items` because there was already a `hir_module_items`, and `items` which became `hir_free_items` for consistency with `hir_module_free_items`. --- compiler/rustc_driver_impl/src/pretty.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'compiler/rustc_driver_impl/src') diff --git a/compiler/rustc_driver_impl/src/pretty.rs b/compiler/rustc_driver_impl/src/pretty.rs index 576b1c76823..ea17dd773c0 100644 --- a/compiler/rustc_driver_impl/src/pretty.rs +++ b/compiler/rustc_driver_impl/src/pretty.rs @@ -273,7 +273,7 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) { let attrs = |id| hir_map.attrs(id); pprust_hir::print_crate( sm, - hir_map.root_module(), + tcx.hir_root_module(), src_name, src, &attrs, @@ -294,7 +294,7 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) { } HirTree => { debug!("pretty printing HIR tree"); - format!("{:#?}", ex.tcx().hir().krate()) + format!("{:#?}", ex.tcx().hir_krate()) } Mir => { let mut out = Vec::new(); -- cgit 1.4.1-3-g733a5 From f666361caa963c3f41934d5b431af24d8894d159 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 17 Feb 2025 13:24:07 +1100 Subject: Remove `TyCtxt::hir_krate`. It's a trivial wrapper around the `hir_crate` query with a small number of uses. --- compiler/rustc_driver_impl/src/pretty.rs | 2 +- compiler/rustc_middle/src/hir/map.rs | 8 +------- src/librustdoc/core.rs | 2 +- 3 files changed, 3 insertions(+), 9 deletions(-) (limited to 'compiler/rustc_driver_impl/src') diff --git a/compiler/rustc_driver_impl/src/pretty.rs b/compiler/rustc_driver_impl/src/pretty.rs index ea17dd773c0..093ee659bb4 100644 --- a/compiler/rustc_driver_impl/src/pretty.rs +++ b/compiler/rustc_driver_impl/src/pretty.rs @@ -294,7 +294,7 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) { } HirTree => { debug!("pretty printing HIR tree"); - format!("{:#?}", ex.tcx().hir_krate()) + format!("{:#?}", ex.tcx().hir_crate(())) } Mir => { let mut out = Vec::new(); diff --git a/compiler/rustc_middle/src/hir/map.rs b/compiler/rustc_middle/src/hir/map.rs index 9bd35fdd6f0..b44f14315d7 100644 --- a/compiler/rustc_middle/src/hir/map.rs +++ b/compiler/rustc_middle/src/hir/map.rs @@ -165,12 +165,6 @@ impl<'tcx> TyCtxt<'tcx> { self.hir_node(self.parent_hir_id(hir_id)) } - /// Best avoided in favour of more targeted methods. See the comment on the `hir_crate` query. - #[inline] - pub fn hir_krate(self) -> &'tcx Crate<'tcx> { - self.hir_crate(()) - } - #[inline] pub fn hir_root_module(self) -> &'tcx Mod<'tcx> { match self.hir_owner_node(CRATE_OWNER_ID) { @@ -414,7 +408,7 @@ impl<'hir> Map<'hir> { where V: Visitor<'hir>, { - let krate = self.tcx.hir_krate(); + let krate = self.tcx.hir_crate(()); for info in krate.owners.iter() { if let MaybeOwner::Owner(info) = info { for attrs in info.attrs.map.values() { diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 09e71f65c14..1ead87fd69d 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -378,7 +378,7 @@ pub(crate) fn run_global_ctxt( ctxt.external_traits.insert(sized_trait_did, sized_trait); } - debug!("crate: {:?}", tcx.hir_krate()); + debug!("crate: {:?}", tcx.hir_crate(())); let mut krate = tcx.sess.time("clean_crate", || clean::krate(&mut ctxt)); -- cgit 1.4.1-3-g733a5