Skip to content

Commit

Permalink
Rollup merge of rust-lang#106813 - oli-obk:sess_cleanup, r=GuillaumeG…
Browse files Browse the repository at this point in the history
…omez,petrochenkov

Remove redundant session field

There was already a session available in the resolver, so we access that session.
  • Loading branch information
matthiaskrgr authored Jan 13, 2023
2 parents 41c0c4b + 4aca7be commit 213b4cf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
6 changes: 5 additions & 1 deletion compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,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> {
self.node_id_to_def_id.get(&node).copied()
}
Expand Down Expand Up @@ -1194,6 +1194,10 @@ impl Resolver<'_> {
self.cstore().item_generics_num_lifetimes(def_id, self.session)
}
}

pub fn sess(&self) -> &'a Session {
self.session
}
}

impl<'a> Resolver<'a> {
Expand Down
3 changes: 0 additions & 3 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,6 @@ fn main_args(at_args: &[String]) -> MainResult {
let crate_version = options.crate_version.clone();

let output_format = options.output_format;
let externs = options.externs.clone();
let scrape_examples_options = options.scrape_examples_options.clone();
let bin_crate = options.bin_crate;

Expand Down Expand Up @@ -805,9 +804,7 @@ fn main_args(at_args: &[String]) -> MainResult {
let resolver_caches = resolver.borrow_mut().access(|resolver| {
collect_intra_doc_links::early_resolve_intra_doc_links(
resolver,
sess,
krate,
externs,
render_options.document_private,
)
});
Expand Down
22 changes: 11 additions & 11 deletions src/librustdoc/passes/collect_intra_doc_links/early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ use rustc_hir::def_id::{DefId, DefIdMap, DefIdSet, CRATE_DEF_ID};
use rustc_hir::TraitCandidate;
use rustc_middle::ty::{DefIdTree, Visibility};
use rustc_resolve::{ParentScope, Resolver};
use rustc_session::config::Externs;
use rustc_session::Session;
use rustc_span::symbol::sym;
use rustc_span::{Symbol, SyntaxContext};

Expand All @@ -22,16 +20,13 @@ use std::mem;

pub(crate) fn early_resolve_intra_doc_links(
resolver: &mut Resolver<'_>,
sess: &Session,
krate: &ast::Crate,
externs: Externs,
document_private_items: bool,
) -> ResolverCaches {
let parent_scope =
ParentScope::module(resolver.expect_module(CRATE_DEF_ID.to_def_id()), resolver);
let mut link_resolver = EarlyDocLinkResolver {
resolver,
sess,
parent_scope,
visited_mods: Default::default(),
markdown_links: Default::default(),
Expand All @@ -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.
// DO NOT REMOVE THIS without first testing on the reproducer in
// 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);
}

Expand All @@ -73,7 +70,6 @@ fn doc_attrs<'a>(attrs: impl Iterator<Item = &'a ast::Attribute>) -> Attributes

struct EarlyDocLinkResolver<'r, 'ra> {
resolver: &'r mut Resolver<'ra>,
sess: &'r Session,
parent_scope: ParentScope<'ra>,
visited_mods: DefIdSet,
markdown_links: FxHashMap<String, Vec<PreprocessedMarkdownLink>>,
Expand Down Expand Up @@ -166,7 +162,7 @@ impl<'ra> EarlyDocLinkResolver<'_, 'ra> {
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);
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 {
if !is_inherent || self.resolver.cstore().visibility_untracked(assoc_def_id).is_public()
Expand All @@ -191,7 +187,9 @@ impl<'ra> EarlyDocLinkResolver<'_, 'ra> {
if !self.resolver.cstore().may_have_doc_links_untracked(def_id) {
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.get_nearest_non_block_module(
self.resolver.opt_parent(scope_id).unwrap_or(scope_id),
Expand All @@ -205,7 +203,9 @@ impl<'ra> EarlyDocLinkResolver<'_, 'ra> {
if !self.resolver.cstore().may_have_doc_links_untracked(def_id) {
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);
self.resolve_doc_links(doc_attrs(attrs.iter()), parent_scope);
}
Expand Down Expand Up @@ -321,7 +321,7 @@ impl<'ra> EarlyDocLinkResolver<'_, 'ra> {
let field_def_ids = Vec::from_iter(
self.resolver
.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 {
self.resolve_doc_links_extern_outer(field_def_id, scope_id);
Expand Down

0 comments on commit 213b4cf

Please sign in to comment.