From 701ccd3eadcf507a4e035668b45856c6f875fa83 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 16 Sep 2024 09:11:30 +1000 Subject: [PATCH] Remove `HirCollector::sess`. It's redundant w.r.t. `HirCollector::tcx`. This removes the unnecessary `'a` lifetime. --- src/librustdoc/doctest.rs | 1 - src/librustdoc/doctest/rust.rs | 17 +++++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 3ee6b24ac92cb..9ef203b4f1258 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( - &compiler.sess, tcx.hir(), ErrorCodes::from(compiler.sess.opts.unstable_features.is_nightly_build()), enable_per_target_ignores, diff --git a/src/librustdoc/doctest/rust.rs b/src/librustdoc/doctest/rust.rs index cc85a73430b37..7739790c310a7 100644 --- a/src/librustdoc/doctest/rust.rs +++ b/src/librustdoc/doctest/rust.rs @@ -10,7 +10,6 @@ use rustc_middle::hir::map::Map; use rustc_middle::hir::nested_filter; use rustc_middle::ty::TyCtxt; use rustc_resolve::rustdoc::span_of_fragments; -use rustc_session::Session; use rustc_span::source_map::SourceMap; use rustc_span::{BytePos, DUMMY_SP, FileName, Pos, Span}; @@ -63,8 +62,7 @@ impl DocTestVisitor for RustCollector { fn visit_header(&mut self, _name: &str, _level: u32) {} } -pub(super) struct HirCollector<'a, 'tcx> { - sess: &'a Session, +pub(super) struct HirCollector<'tcx> { map: Map<'tcx>, codes: ErrorCodes, tcx: TyCtxt<'tcx>, @@ -72,21 +70,20 @@ pub(super) struct HirCollector<'a, 'tcx> { collector: RustCollector, } -impl<'a, 'tcx> HirCollector<'a, 'tcx> { +impl<'tcx> HirCollector<'tcx> { pub fn new( - sess: &'a Session, map: Map<'tcx>, codes: ErrorCodes, enable_per_target_ignores: bool, tcx: TyCtxt<'tcx>, ) -> Self { let collector = RustCollector { - source_map: sess.psess.clone_source_map(), + source_map: tcx.sess.psess.clone_source_map(), cur_path: vec![], position: DUMMY_SP, tests: vec![], }; - Self { sess, map, codes, enable_per_target_ignores, tcx, collector } + Self { map, codes, enable_per_target_ignores, tcx, collector } } pub fn collect_crate(mut self) -> Vec { @@ -98,7 +95,7 @@ impl<'a, 'tcx> HirCollector<'a, 'tcx> { } } -impl<'a, 'tcx> HirCollector<'a, 'tcx> { +impl<'tcx> HirCollector<'tcx> { fn visit_testable( &mut self, name: String, @@ -108,7 +105,7 @@ impl<'a, 'tcx> HirCollector<'a, 'tcx> { ) { let ast_attrs = self.tcx.hir().attrs(self.tcx.local_def_id_to_hir_id(def_id)); if let Some(ref cfg) = ast_attrs.cfg(self.tcx, &FxHashSet::default()) { - if !cfg.matches(&self.sess.psess, Some(self.tcx.features())) { + if !cfg.matches(&self.tcx.sess.psess, Some(self.tcx.features())) { return; } } @@ -141,7 +138,7 @@ impl<'a, 'tcx> HirCollector<'a, 'tcx> { } } -impl<'a, 'tcx> intravisit::Visitor<'tcx> for HirCollector<'a, 'tcx> { +impl<'tcx> intravisit::Visitor<'tcx> for HirCollector<'tcx> { type NestedFilter = nested_filter::All; fn nested_visit_map(&mut self) -> Self::Map {