From 711c91da7fa5882020c8d9f7a6edfa6d0b9c062f Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 16 Sep 2024 09:24:22 +1000 Subject: [PATCH] Remove `HirCollector::map`. Because `rustc_middle::hir::map::Map` is a trivial wrapper around `TyCtxt`, and `HirCollector` has a `TyCtxt` field. --- src/librustdoc/doctest.rs | 1 - src/librustdoc/doctest/rust.rs | 15 ++++----------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 9ef203b4f1258..48272a41c938c 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -186,7 +186,6 @@ pub(crate) fn run( let mut collector = CreateRunnableDocTests::new(options, opts); let hir_collector = HirCollector::new( - tcx.hir(), ErrorCodes::from(compiler.sess.opts.unstable_features.is_nightly_build()), enable_per_target_ignores, tcx, diff --git a/src/librustdoc/doctest/rust.rs b/src/librustdoc/doctest/rust.rs index 7739790c310a7..a9ab02e29cd95 100644 --- a/src/librustdoc/doctest/rust.rs +++ b/src/librustdoc/doctest/rust.rs @@ -6,7 +6,6 @@ use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::Lrc; use rustc_hir::def_id::{CRATE_DEF_ID, LocalDefId}; use rustc_hir::{self as hir, CRATE_HIR_ID, intravisit}; -use rustc_middle::hir::map::Map; use rustc_middle::hir::nested_filter; use rustc_middle::ty::TyCtxt; use rustc_resolve::rustdoc::span_of_fragments; @@ -63,7 +62,6 @@ impl DocTestVisitor for RustCollector { } pub(super) struct HirCollector<'tcx> { - map: Map<'tcx>, codes: ErrorCodes, tcx: TyCtxt<'tcx>, enable_per_target_ignores: bool, @@ -71,19 +69,14 @@ pub(super) struct HirCollector<'tcx> { } impl<'tcx> HirCollector<'tcx> { - pub fn new( - map: Map<'tcx>, - codes: ErrorCodes, - enable_per_target_ignores: bool, - tcx: TyCtxt<'tcx>, - ) -> Self { + pub fn new(codes: ErrorCodes, enable_per_target_ignores: bool, tcx: TyCtxt<'tcx>) -> Self { let collector = RustCollector { source_map: tcx.sess.psess.clone_source_map(), cur_path: vec![], position: DUMMY_SP, tests: vec![], }; - Self { map, codes, enable_per_target_ignores, tcx, collector } + Self { codes, enable_per_target_ignores, tcx, collector } } pub fn collect_crate(mut self) -> Vec { @@ -142,13 +135,13 @@ impl<'tcx> intravisit::Visitor<'tcx> for HirCollector<'tcx> { type NestedFilter = nested_filter::All; fn nested_visit_map(&mut self) -> Self::Map { - self.map + self.tcx.hir() } fn visit_item(&mut self, item: &'tcx hir::Item<'_>) { let name = match &item.kind { hir::ItemKind::Impl(impl_) => { - rustc_hir_pretty::id_to_string(&self.map, impl_.self_ty.hir_id) + rustc_hir_pretty::id_to_string(&self.tcx.hir(), impl_.self_ty.hir_id) } _ => item.ident.to_string(), };