Remove redundant session field

This commit is contained in:
Oli Scherer 2022-12-08 09:39:48 +00:00
parent 222d1ff68d
commit 4aca7beab0
3 changed files with 16 additions and 15 deletions

View file

@ -1133,7 +1133,7 @@ impl<'a, 'b> DefIdTree for &'a Resolver<'b> {
} }
} }
impl Resolver<'_> { impl<'a> Resolver<'a> {
fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> { fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> {
self.node_id_to_def_id.get(&node).copied() self.node_id_to_def_id.get(&node).copied()
} }
@ -1190,6 +1190,10 @@ impl Resolver<'_> {
self.cstore().item_generics_num_lifetimes(def_id, self.session) self.cstore().item_generics_num_lifetimes(def_id, self.session)
} }
} }
pub fn sess(&self) -> &'a Session {
self.session
}
} }
impl<'a> Resolver<'a> { impl<'a> Resolver<'a> {

View file

@ -772,7 +772,6 @@ fn main_args(at_args: &[String]) -> MainResult {
let crate_version = options.crate_version.clone(); let crate_version = options.crate_version.clone();
let output_format = options.output_format; let output_format = options.output_format;
let externs = options.externs.clone();
let scrape_examples_options = options.scrape_examples_options.clone(); let scrape_examples_options = options.scrape_examples_options.clone();
let bin_crate = options.bin_crate; let bin_crate = options.bin_crate;
@ -805,9 +804,7 @@ fn main_args(at_args: &[String]) -> MainResult {
let resolver_caches = resolver.borrow_mut().access(|resolver| { let resolver_caches = resolver.borrow_mut().access(|resolver| {
collect_intra_doc_links::early_resolve_intra_doc_links( collect_intra_doc_links::early_resolve_intra_doc_links(
resolver, resolver,
sess,
krate, krate,
externs,
render_options.document_private, render_options.document_private,
) )
}); });

View file

@ -12,8 +12,6 @@ use rustc_hir::def_id::{DefId, DefIdMap, DefIdSet, CRATE_DEF_ID};
use rustc_hir::TraitCandidate; use rustc_hir::TraitCandidate;
use rustc_middle::ty::{DefIdTree, Visibility}; use rustc_middle::ty::{DefIdTree, Visibility};
use rustc_resolve::{ParentScope, Resolver}; use rustc_resolve::{ParentScope, Resolver};
use rustc_session::config::Externs;
use rustc_session::Session;
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
use rustc_span::{Symbol, SyntaxContext}; use rustc_span::{Symbol, SyntaxContext};
@ -22,16 +20,13 @@ use std::mem;
pub(crate) fn early_resolve_intra_doc_links( pub(crate) fn early_resolve_intra_doc_links(
resolver: &mut Resolver<'_>, resolver: &mut Resolver<'_>,
sess: &Session,
krate: &ast::Crate, krate: &ast::Crate,
externs: Externs,
document_private_items: bool, document_private_items: bool,
) -> ResolverCaches { ) -> ResolverCaches {
let parent_scope = let parent_scope =
ParentScope::module(resolver.expect_module(CRATE_DEF_ID.to_def_id()), resolver); ParentScope::module(resolver.expect_module(CRATE_DEF_ID.to_def_id()), resolver);
let mut link_resolver = EarlyDocLinkResolver { let mut link_resolver = EarlyDocLinkResolver {
resolver, resolver,
sess,
parent_scope, parent_scope,
visited_mods: Default::default(), visited_mods: Default::default(),
markdown_links: Default::default(), markdown_links: Default::default(),
@ -52,7 +47,9 @@ pub(crate) fn early_resolve_intra_doc_links(
// the known necessary crates. Load them all unconditionally until we find a way to fix this. // the known necessary crates. Load them all unconditionally until we find a way to fix this.
// DO NOT REMOVE THIS without first testing on the reproducer in // DO NOT REMOVE THIS without first testing on the reproducer in
// https://github.com/jyn514/objr/commit/edcee7b8124abf0e4c63873e8422ff81beb11ebb // https://github.com/jyn514/objr/commit/edcee7b8124abf0e4c63873e8422ff81beb11ebb
for (extern_name, _) in externs.iter().filter(|(_, entry)| entry.add_prelude) { for (extern_name, _) in
link_resolver.resolver.sess().opts.externs.iter().filter(|(_, entry)| entry.add_prelude)
{
link_resolver.resolver.resolve_rustdoc_path(extern_name, TypeNS, parent_scope); link_resolver.resolver.resolve_rustdoc_path(extern_name, TypeNS, parent_scope);
} }
@ -73,7 +70,6 @@ fn doc_attrs<'a>(attrs: impl Iterator<Item = &'a ast::Attribute>) -> Attributes
struct EarlyDocLinkResolver<'r, 'ra> { struct EarlyDocLinkResolver<'r, 'ra> {
resolver: &'r mut Resolver<'ra>, resolver: &'r mut Resolver<'ra>,
sess: &'r Session,
parent_scope: ParentScope<'ra>, parent_scope: ParentScope<'ra>,
visited_mods: DefIdSet, visited_mods: DefIdSet,
markdown_links: FxHashMap<String, Vec<PreprocessedMarkdownLink>>, markdown_links: FxHashMap<String, Vec<PreprocessedMarkdownLink>>,
@ -166,7 +162,7 @@ impl<'ra> EarlyDocLinkResolver<'_, 'ra> {
fn resolve_doc_links_extern_impl(&mut self, def_id: DefId, is_inherent: bool) { fn resolve_doc_links_extern_impl(&mut self, def_id: DefId, is_inherent: bool) {
self.resolve_doc_links_extern_outer_fixme(def_id, def_id); self.resolve_doc_links_extern_outer_fixme(def_id, def_id);
let assoc_item_def_ids = Vec::from_iter( let assoc_item_def_ids = Vec::from_iter(
self.resolver.cstore().associated_item_def_ids_untracked(def_id, self.sess), self.resolver.cstore().associated_item_def_ids_untracked(def_id, self.resolver.sess()),
); );
for assoc_def_id in assoc_item_def_ids { for assoc_def_id in assoc_item_def_ids {
if !is_inherent || self.resolver.cstore().visibility_untracked(assoc_def_id).is_public() if !is_inherent || self.resolver.cstore().visibility_untracked(assoc_def_id).is_public()
@ -191,7 +187,9 @@ impl<'ra> EarlyDocLinkResolver<'_, 'ra> {
if !self.resolver.cstore().may_have_doc_links_untracked(def_id) { if !self.resolver.cstore().may_have_doc_links_untracked(def_id) {
return; return;
} }
let attrs = Vec::from_iter(self.resolver.cstore().item_attrs_untracked(def_id, self.sess)); let attrs = Vec::from_iter(
self.resolver.cstore().item_attrs_untracked(def_id, self.resolver.sess()),
);
let parent_scope = ParentScope::module( let parent_scope = ParentScope::module(
self.resolver.get_nearest_non_block_module( self.resolver.get_nearest_non_block_module(
self.resolver.opt_parent(scope_id).unwrap_or(scope_id), self.resolver.opt_parent(scope_id).unwrap_or(scope_id),
@ -205,7 +203,9 @@ impl<'ra> EarlyDocLinkResolver<'_, 'ra> {
if !self.resolver.cstore().may_have_doc_links_untracked(def_id) { if !self.resolver.cstore().may_have_doc_links_untracked(def_id) {
return; return;
} }
let attrs = Vec::from_iter(self.resolver.cstore().item_attrs_untracked(def_id, self.sess)); let attrs = Vec::from_iter(
self.resolver.cstore().item_attrs_untracked(def_id, self.resolver.sess()),
);
let parent_scope = ParentScope::module(self.resolver.expect_module(def_id), self.resolver); let parent_scope = ParentScope::module(self.resolver.expect_module(def_id), self.resolver);
self.resolve_doc_links(doc_attrs(attrs.iter()), parent_scope); self.resolve_doc_links(doc_attrs(attrs.iter()), parent_scope);
} }
@ -321,7 +321,7 @@ impl<'ra> EarlyDocLinkResolver<'_, 'ra> {
let field_def_ids = Vec::from_iter( let field_def_ids = Vec::from_iter(
self.resolver self.resolver
.cstore() .cstore()
.associated_item_def_ids_untracked(def_id, self.sess), .associated_item_def_ids_untracked(def_id, self.resolver.sess()),
); );
for field_def_id in field_def_ids { for field_def_id in field_def_ids {
self.resolve_doc_links_extern_outer(field_def_id, scope_id); self.resolve_doc_links_extern_outer(field_def_id, scope_id);