Skip to content

Commit 763d373

Browse files
committed
Use tcx as the only context for visitor
Previously two different parts of the context had to be passed separately; there were two sources of truth.
1 parent 2f29e69 commit 763d373

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/librustdoc/core.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
392392
let hir = tcx.hir();
393393
let body = hir.body(hir.body_owned_by(hir.as_local_hir_id(def_id)));
394394
debug!("visiting body for {:?}", def_id);
395-
EmitIgnoredResolutionErrors::new(&tcx.sess, hir).visit_body(body);
395+
EmitIgnoredResolutionErrors::new(&tcx).visit_body(body);
396396
DEFAULT_TYPECK.with(|typeck| typeck(tcx, def_id))
397397
};
398398
}),
@@ -602,27 +602,26 @@ thread_local!(static DEFAULT_TYPECK: for<'tcx> fn(TyCtxt<'tcx>, LocalDefId) -> &
602602
/// the name resolution pass may find errors that are never emitted.
603603
/// If typeck is called after this happens, then we'll get an ICE:
604604
/// 'Res::Error found but not reported'. To avoid this, emit the errors now.
605-
struct EmitIgnoredResolutionErrors<'a, 'hir> {
606-
session: &'a Session,
607-
hir_map: Map<'hir>,
605+
struct EmitIgnoredResolutionErrors<'a, 'tcx> {
606+
tcx: &'a TyCtxt<'tcx>,
608607
}
609608

610-
impl<'a, 'hir> EmitIgnoredResolutionErrors<'a, 'hir> {
611-
fn new(session: &'a Session, hir_map: Map<'hir>) -> Self {
612-
Self { session, hir_map }
609+
impl<'a, 'tcx> EmitIgnoredResolutionErrors<'a, 'tcx> {
610+
fn new(tcx: &'a TyCtxt<'tcx>) -> Self {
611+
Self { tcx }
613612
}
614613
}
615614

616-
impl<'hir> Visitor<'hir> for EmitIgnoredResolutionErrors<'_, 'hir> {
617-
type Map = Map<'hir>;
615+
impl<'tcx> Visitor<'tcx> for EmitIgnoredResolutionErrors<'_, 'tcx> {
616+
type Map = Map<'tcx>;
618617

619618
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
620619
// We need to recurse into nested closures,
621620
// since those will fallback to the parent for type checking.
622-
NestedVisitorMap::OnlyBodies(self.hir_map)
621+
NestedVisitorMap::OnlyBodies(self.tcx.hir())
623622
}
624623

625-
fn visit_path(&mut self, path: &'hir Path<'_>, _id: HirId) {
624+
fn visit_path(&mut self, path: &'tcx Path<'_>, _id: HirId) {
626625
debug!("visiting path {:?}", path);
627626
if path.res == Res::Err {
628627
// We have less context here than in rustc_resolve,
@@ -637,7 +636,7 @@ impl<'hir> Visitor<'hir> for EmitIgnoredResolutionErrors<'_, 'hir> {
637636
.join("::")
638637
);
639638
let mut err = rustc_errors::struct_span_err!(
640-
self.session,
639+
self.tcx.sess,
641640
path.span,
642641
E0433,
643642
"failed to resolve: {}",

0 commit comments

Comments
 (0)