Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions compiler/rustc_ast_lowering/src/delegation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,13 +815,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
}

struct SelfResolver<'a> {
resolver: &'a mut ResolverAstLowering,
struct SelfResolver<'a, 'tcx> {
resolver: &'a mut ResolverAstLowering<'tcx>,
path_id: NodeId,
self_param_id: NodeId,
}

impl<'a> SelfResolver<'a> {
impl SelfResolver<'_, '_> {
fn try_replace_id(&mut self, id: NodeId) {
if let Some(res) = self.resolver.partial_res_map.get(&id)
&& let Some(Res::Local(sig_id)) = res.full_res()
Expand All @@ -833,7 +833,7 @@ impl<'a> SelfResolver<'a> {
}
}

impl<'ast, 'a> Visitor<'ast> for SelfResolver<'a> {
impl<'ast, 'a> Visitor<'ast> for SelfResolver<'a, '_> {
fn visit_id(&mut self, id: NodeId) {
self.try_replace_id(id);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use super::{

pub(super) struct ItemLowerer<'a, 'hir> {
pub(super) tcx: TyCtxt<'hir>,
pub(super) resolver: &'a mut ResolverAstLowering,
pub(super) resolver: &'a mut ResolverAstLowering<'hir>,
pub(super) ast_index: &'a IndexSlice<LocalDefId, AstOwner<'a>>,
pub(super) owners: &'a mut IndexVec<LocalDefId, hir::MaybeOwner<'hir>>,
}
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct LoweringContext<'a, 'hir> {
// will be in AST index.
ast_index: &'a IndexSlice<LocalDefId, AstOwner<'a>>,

resolver: &'a mut ResolverAstLowering,
resolver: &'a mut ResolverAstLowering<'hir>,
disambiguator: DisambiguatorState,

/// Used to allocate HIR nodes.
Expand Down Expand Up @@ -133,7 +133,7 @@ struct LoweringContext<'a, 'hir> {

current_hir_id_owner: hir::OwnerId,
item_local_id_counter: hir::ItemLocalId,
trait_map: ItemLocalMap<Box<[TraitCandidate]>>,
trait_map: ItemLocalMap<&'hir [TraitCandidate<'hir>]>,

impl_trait_defs: Vec<hir::GenericParam<'hir>>,
impl_trait_bounds: Vec<hir::WherePredicate<'hir>>,
Expand Down Expand Up @@ -162,7 +162,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn new(
tcx: TyCtxt<'hir>,
ast_index: &'a IndexSlice<LocalDefId, AstOwner<'a>>,
resolver: &'a mut ResolverAstLowering,
resolver: &'a mut ResolverAstLowering<'hir>,
) -> Self {
let registered_tools = tcx.registered_tools(()).iter().map(|x| x.name).collect();
Self {
Expand Down Expand Up @@ -248,7 +248,7 @@ impl SpanLowerer {
}

#[extension(trait ResolverAstLoweringExt)]
impl ResolverAstLowering {
impl ResolverAstLowering<'_> {
fn legacy_const_generic_args(&self, expr: &Expr, tcx: TyCtxt<'_>) -> Option<Vec<usize>> {
let ExprKind::Path(None, path) = &expr.kind else {
return None;
Expand Down Expand Up @@ -748,8 +748,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.children.push((def_id, hir::MaybeOwner::NonOwner(hir_id)));
}

if let Some(traits) = self.resolver.trait_map.remove(&ast_node_id) {
self.trait_map.insert(hir_id.local_id, traits.into_boxed_slice());
if let Some(&traits) = self.resolver.trait_map.get(&ast_node_id) {
self.trait_map.insert(hir_id.local_id, traits);
}

// Check whether the same `NodeId` is lowered more than once.
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1633,7 +1633,7 @@ pub struct OwnerInfo<'hir> {
pub attrs: AttributeMap<'hir>,
/// Map indicating what traits are in scope for places where this
/// is relevant; generated by resolve.
pub trait_map: ItemLocalMap<Box<[TraitCandidate]>>,
pub trait_map: ItemLocalMap<&'hir [TraitCandidate<'hir>]>,

/// Lints delayed during ast lowering to be emitted
/// after hir has completely built
Expand Down Expand Up @@ -4683,10 +4683,10 @@ pub struct Upvar {
// The TraitCandidate's import_ids is empty if the trait is defined in the same module, and
// has length > 0 if the trait is found through an chain of imports, starting with the
// import/use statement in the scope where the trait is used.
#[derive(Debug, Clone, HashStable_Generic)]
pub struct TraitCandidate {
#[derive(Debug, Clone, Copy, HashStable_Generic)]
pub struct TraitCandidate<'hir> {
pub def_id: DefId,
pub import_ids: SmallVec<[LocalDefId; 1]>,
pub import_ids: &'hir [LocalDefId],
// Indicates whether this trait candidate is ambiguously glob imported
// in it's scope. Related to the AMBIGUOUS_GLOB_IMPORTED_TRAITS lint.
// If this is set to true and the trait is used as a result of method lookup, this
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
);
let container_id = pick.item.container_id(self.tcx);
let container = with_no_trimmed_paths!(self.tcx.def_path_str(container_id));
for def_id in pick.import_ids {
for &def_id in pick.import_ids {
let hir_id = self.tcx.local_def_id_to_hir_id(def_id);
path_span
.push_span_label(self.tcx.hir_span(hir_id), format!("`{container}` imported here"));
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/method/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// NOTE: on the failure path, we also record the possibly-used trait methods
// since an unused import warning is kinda distracting from the method error.
for &import_id in &pick.import_ids {
for &import_id in pick.import_ids {
debug!("used_trait_import: {:?}", import_id);
self.typeck_results.borrow_mut().used_trait_imports.insert(import_id);
}
Expand Down Expand Up @@ -554,7 +554,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
debug!(?pick);
{
let mut typeck_results = self.typeck_results.borrow_mut();
for import_id in pick.import_ids {
for &import_id in pick.import_ids {
debug!(used_trait_import=?import_id);
typeck_results.used_trait_imports.insert(import_id);
}
Expand Down
40 changes: 14 additions & 26 deletions compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use rustc_trait_selection::traits::query::method_autoderef::{
CandidateStep, MethodAutoderefBadTy, MethodAutoderefStepsResult,
};
use rustc_trait_selection::traits::{self, ObligationCause, ObligationCtxt};
use smallvec::{SmallVec, smallvec};
use smallvec::SmallVec;
use tracing::{debug, instrument};

use self::CandidateKind::*;
Expand Down Expand Up @@ -99,7 +99,7 @@ impl<'a, 'tcx> Deref for ProbeContext<'a, 'tcx> {
pub(crate) struct Candidate<'tcx> {
pub(crate) item: ty::AssocItem,
pub(crate) kind: CandidateKind<'tcx>,
pub(crate) import_ids: SmallVec<[LocalDefId; 1]>,
pub(crate) import_ids: &'tcx [LocalDefId],
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -206,7 +206,7 @@ impl PickConstraintsForShadowed {
pub(crate) struct Pick<'tcx> {
pub item: ty::AssocItem,
pub kind: PickKind<'tcx>,
pub import_ids: SmallVec<[LocalDefId; 1]>,
pub import_ids: &'tcx [LocalDefId],

/// Indicates that the source expression should be autoderef'd N times
/// ```ignore (not-rust)
Expand Down Expand Up @@ -574,7 +574,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ty::Binder::dummy(trait_ref),
false,
),
import_ids: smallvec![],
import_ids: &[],
},
false,
);
Expand Down Expand Up @@ -946,7 +946,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
Candidate {
item,
kind: InherentImplCandidate { impl_def_id, receiver_steps },
import_ids: smallvec![],
import_ids: &[],
},
true,
);
Expand Down Expand Up @@ -979,11 +979,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
traits::supertraits(self.tcx, trait_ref),
|this, new_trait_ref, item| {
this.push_candidate(
Candidate {
item,
kind: ObjectCandidate(new_trait_ref),
import_ids: smallvec![],
},
Candidate { item, kind: ObjectCandidate(new_trait_ref), import_ids: &[] },
true,
);
},
Expand Down Expand Up @@ -1018,11 +1014,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {

self.assemble_candidates_for_bounds(bounds, |this, poly_trait_ref, item| {
this.push_candidate(
Candidate {
item,
kind: WhereClauseCandidate(poly_trait_ref),
import_ids: smallvec![],
},
Candidate { item, kind: WhereClauseCandidate(poly_trait_ref), import_ids: &[] },
true,
);
});
Expand Down Expand Up @@ -1072,11 +1064,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
let mut duplicates = FxHashSet::default();
for trait_info in suggest::all_traits(self.tcx) {
if duplicates.insert(trait_info.def_id) {
self.assemble_extension_candidates_for_trait(
&smallvec![],
trait_info.def_id,
false,
);
self.assemble_extension_candidates_for_trait(&[], trait_info.def_id, false);
}
}
}
Expand All @@ -1100,7 +1088,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
#[instrument(level = "debug", skip(self))]
fn assemble_extension_candidates_for_trait(
&mut self,
import_ids: &SmallVec<[LocalDefId; 1]>,
import_ids: &'tcx [LocalDefId],
trait_def_id: DefId,
lint_ambiguous: bool,
) {
Expand All @@ -1123,7 +1111,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
self.push_candidate(
Candidate {
item,
import_ids: import_ids.clone(),
import_ids,
kind: TraitCandidate(bound_trait_ref, lint_ambiguous),
},
false,
Expand All @@ -1146,7 +1134,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
self.push_candidate(
Candidate {
item,
import_ids: import_ids.clone(),
import_ids,
kind: TraitCandidate(ty::Binder::dummy(trait_ref), lint_ambiguous),
},
false,
Expand Down Expand Up @@ -2353,7 +2341,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
Some(Pick {
item: probes[0].0.item,
kind: TraitPick(lint_ambiguous),
import_ids: probes[0].0.import_ids.clone(),
import_ids: probes[0].0.import_ids,
autoderefs: 0,
autoref_or_ptr_adjustment: None,
self_ty,
Expand Down Expand Up @@ -2430,7 +2418,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
Some(Pick {
item: child_candidate.item,
kind: TraitPick(lint_ambiguous),
import_ids: child_candidate.import_ids.clone(),
import_ids: child_candidate.import_ids,
autoderefs: 0,
autoref_or_ptr_adjustment: None,
self_ty,
Expand Down Expand Up @@ -2707,7 +2695,7 @@ impl<'tcx> Candidate<'tcx> {
WhereClausePick(trait_ref)
}
},
import_ids: self.import_ids.clone(),
import_ids: self.import_ids,
autoderefs: 0,
autoref_or_ptr_adjustment: None,
self_ty,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// NOTE: Reporting a method error should also suppress any unused trait errors,
// since the method error is very possibly the reason why the trait wasn't used.
for &import_id in
self.tcx.in_scope_traits(call_id).into_iter().flatten().flat_map(|c| &c.import_ids)
self.tcx.in_scope_traits(call_id).into_iter().flatten().flat_map(|c| c.import_ids)
{
self.typeck_results.borrow_mut().used_trait_imports.insert(import_id);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P
fn resolver_for_lowering_raw<'tcx>(
tcx: TyCtxt<'tcx>,
(): (),
) -> (&'tcx Steal<(ty::ResolverAstLowering, Arc<ast::Crate>)>, &'tcx ty::ResolverGlobalCtxt) {
) -> (&'tcx Steal<(ty::ResolverAstLowering<'tcx>, Arc<ast::Crate>)>, &'tcx ty::ResolverGlobalCtxt) {
let arenas = Resolver::arenas();
let _ = tcx.registered_tools(()); // Uses `crate_for_resolver`.
let (krate, pre_configured_attrs) = tcx.crate_for_resolver(()).steal();
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ macro_rules! arena_types {
rustc_middle::ty::DefinitionSiteHiddenType<'tcx>,
>,
[] resolver: rustc_data_structures::steal::Steal<(
rustc_middle::ty::ResolverAstLowering,
rustc_middle::ty::ResolverAstLowering<'tcx>,
std::sync::Arc<rustc_ast::Crate>,
)>,
[] crate_for_resolver: rustc_data_structures::steal::Steal<(rustc_ast::Crate, rustc_ast::AttrVec)>,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ rustc_queries! {
desc { "getting the resolver outputs" }
}

query resolver_for_lowering_raw(_: ()) -> (&'tcx Steal<(ty::ResolverAstLowering, Arc<ast::Crate>)>, &'tcx ty::ResolverGlobalCtxt) {
query resolver_for_lowering_raw(_: ()) -> (&'tcx Steal<(ty::ResolverAstLowering<'tcx>, Arc<ast::Crate>)>, &'tcx ty::ResolverGlobalCtxt) {
eval_always
no_hash
desc { "getting the resolver for lowering" }
Expand Down Expand Up @@ -1910,7 +1910,7 @@ rustc_queries! {
desc { "computing whether impls specialize one another" }
}
query in_scope_traits_map(_: hir::OwnerId)
-> Option<&'tcx ItemLocalMap<Box<[TraitCandidate]>>> {
-> Option<&'tcx ItemLocalMap<&'tcx [TraitCandidate<'tcx>]>> {
desc { "getting traits in scope at a block" }
}

Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2614,7 +2614,7 @@ impl<'tcx> TyCtxt<'tcx> {
lint_level(self.sess, lint, level, None, decorate);
}

pub fn in_scope_traits(self, id: HirId) -> Option<&'tcx [TraitCandidate]> {
pub fn in_scope_traits(self, id: HirId) -> Option<&'tcx [TraitCandidate<'tcx>]> {
let map = self.in_scope_traits_map(id.owner)?;
let candidates = map.get(&id.local_id)?;
Some(candidates)
Expand Down Expand Up @@ -2777,7 +2777,9 @@ impl<'tcx> TyCtxt<'tcx> {
self.resolutions(()).extern_crate_map.get(&def_id).copied()
}

pub fn resolver_for_lowering(self) -> &'tcx Steal<(ty::ResolverAstLowering, Arc<ast::Crate>)> {
pub fn resolver_for_lowering(
self,
) -> &'tcx Steal<(ty::ResolverAstLowering<'tcx>, Arc<ast::Crate>)> {
self.resolver_for_lowering_raw(()).0
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ pub struct ResolverGlobalCtxt {
/// Resolutions that should only be used for lowering.
/// This struct is meant to be consumed by lowering.
#[derive(Debug)]
pub struct ResolverAstLowering {
pub struct ResolverAstLowering<'tcx> {
/// Resolutions for nodes that have a single resolution.
pub partial_res_map: NodeMap<hir::def::PartialRes>,
/// Resolutions for import nodes, which have multiple resolutions in different namespaces.
Expand All @@ -214,7 +214,7 @@ pub struct ResolverAstLowering {

pub node_id_to_def_id: NodeMap<LocalDefId>,

pub trait_map: NodeMap<Vec<hir::TraitCandidate>>,
pub trait_map: NodeMap<&'tcx [hir::TraitCandidate<'tcx>]>,
/// List functions and methods for which lifetime elision was successful.
pub lifetime_elision_allowed: FxHashSet<ast::NodeId>,

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_passes/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub(crate) enum Duplicate {
struct LanguageItemCollector<'ast, 'tcx> {
items: LanguageItems,
tcx: TyCtxt<'tcx>,
resolver: &'ast ResolverAstLowering,
resolver: &'ast ResolverAstLowering<'tcx>,
// FIXME(#118552): We should probably feed def_span eagerly on def-id creation
// so we can avoid constructing this map for local def-ids.
item_spans: FxHashMap<DefId, Span>,
Expand All @@ -42,7 +42,7 @@ struct LanguageItemCollector<'ast, 'tcx> {
impl<'ast, 'tcx> LanguageItemCollector<'ast, 'tcx> {
fn new(
tcx: TyCtxt<'tcx>,
resolver: &'ast ResolverAstLowering,
resolver: &'ast ResolverAstLowering<'tcx>,
) -> LanguageItemCollector<'ast, 'tcx> {
LanguageItemCollector {
tcx,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5258,7 +5258,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
}
}

fn traits_in_scope(&mut self, ident: Ident, ns: Namespace) -> Vec<TraitCandidate> {
fn traits_in_scope(&mut self, ident: Ident, ns: Namespace) -> &'tcx [TraitCandidate<'tcx>] {
self.r.traits_in_scope(
self.current_trait_ref.as_ref().map(|(module, _)| *module),
&self.parent_scope,
Expand Down
Loading
Loading