1
Fork 0

Remove HirCollector::map.

Because `rustc_middle::hir::map::Map` is a trivial wrapper around
`TyCtxt`, and `HirCollector` has a `TyCtxt` field.
This commit is contained in:
Nicholas Nethercote 2024-09-16 09:24:22 +10:00
parent 701ccd3ead
commit 711c91da7f
2 changed files with 4 additions and 12 deletions

View file

@ -186,7 +186,6 @@ pub(crate) fn run(
let mut collector = CreateRunnableDocTests::new(options, opts); let mut collector = CreateRunnableDocTests::new(options, opts);
let hir_collector = HirCollector::new( let hir_collector = HirCollector::new(
tcx.hir(),
ErrorCodes::from(compiler.sess.opts.unstable_features.is_nightly_build()), ErrorCodes::from(compiler.sess.opts.unstable_features.is_nightly_build()),
enable_per_target_ignores, enable_per_target_ignores,
tcx, tcx,

View file

@ -6,7 +6,6 @@ use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
use rustc_hir::def_id::{CRATE_DEF_ID, LocalDefId}; use rustc_hir::def_id::{CRATE_DEF_ID, LocalDefId};
use rustc_hir::{self as hir, CRATE_HIR_ID, intravisit}; 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::hir::nested_filter;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
use rustc_resolve::rustdoc::span_of_fragments; use rustc_resolve::rustdoc::span_of_fragments;
@ -63,7 +62,6 @@ impl DocTestVisitor for RustCollector {
} }
pub(super) struct HirCollector<'tcx> { pub(super) struct HirCollector<'tcx> {
map: Map<'tcx>,
codes: ErrorCodes, codes: ErrorCodes,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
enable_per_target_ignores: bool, enable_per_target_ignores: bool,
@ -71,19 +69,14 @@ pub(super) struct HirCollector<'tcx> {
} }
impl<'tcx> HirCollector<'tcx> { impl<'tcx> HirCollector<'tcx> {
pub fn new( pub fn new(codes: ErrorCodes, enable_per_target_ignores: bool, tcx: TyCtxt<'tcx>) -> Self {
map: Map<'tcx>,
codes: ErrorCodes,
enable_per_target_ignores: bool,
tcx: TyCtxt<'tcx>,
) -> Self {
let collector = RustCollector { let collector = RustCollector {
source_map: tcx.sess.psess.clone_source_map(), source_map: tcx.sess.psess.clone_source_map(),
cur_path: vec![], cur_path: vec![],
position: DUMMY_SP, position: DUMMY_SP,
tests: vec![], 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<ScrapedDocTest> { pub fn collect_crate(mut self) -> Vec<ScrapedDocTest> {
@ -142,13 +135,13 @@ impl<'tcx> intravisit::Visitor<'tcx> for HirCollector<'tcx> {
type NestedFilter = nested_filter::All; type NestedFilter = nested_filter::All;
fn nested_visit_map(&mut self) -> Self::Map { fn nested_visit_map(&mut self) -> Self::Map {
self.map self.tcx.hir()
} }
fn visit_item(&mut self, item: &'tcx hir::Item<'_>) { fn visit_item(&mut self, item: &'tcx hir::Item<'_>) {
let name = match &item.kind { let name = match &item.kind {
hir::ItemKind::Impl(impl_) => { 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(), _ => item.ident.to_string(),
}; };