Skip to content

Commit

Permalink
Remove HirCollector::map.
Browse files Browse the repository at this point in the history
Because `rustc_middle::hir::map::Map` is a trivial wrapper around
`TyCtxt`, and `HirCollector` has a `TyCtxt` field.
  • Loading branch information
nnethercote committed Sep 25, 2024
1 parent 701ccd3 commit 711c91d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
1 change: 0 additions & 1 deletion src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 4 additions & 11 deletions src/librustdoc/doctest/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,27 +62,21 @@ impl DocTestVisitor for RustCollector {
}

pub(super) struct HirCollector<'tcx> {
map: Map<'tcx>,
codes: ErrorCodes,
tcx: TyCtxt<'tcx>,
enable_per_target_ignores: bool,
collector: RustCollector,
}

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<ScrapedDocTest> {
Expand Down Expand Up @@ -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(),
};
Expand Down

0 comments on commit 711c91d

Please sign in to comment.