Skip to content

Commit ff56b27

Browse files
committed
Auto merge of #153494 - aerooneqq:boxed-trait-candidates-to-hir-arena, r=<try>
Replace Box<[TraitCandidate]> with &'hir [TraitCandidate<'hir>]
2 parents f824853 + dc31c15 commit ff56b27

File tree

16 files changed

+58
-67
lines changed

16 files changed

+58
-67
lines changed

compiler/rustc_ast_lowering/src/delegation.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -815,13 +815,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
815815
}
816816
}
817817

818-
struct SelfResolver<'a> {
819-
resolver: &'a mut ResolverAstLowering,
818+
struct SelfResolver<'a, 'tcx> {
819+
resolver: &'a mut ResolverAstLowering<'tcx>,
820820
path_id: NodeId,
821821
self_param_id: NodeId,
822822
}
823823

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

836-
impl<'ast, 'a> Visitor<'ast> for SelfResolver<'a> {
836+
impl<'ast, 'a> Visitor<'ast> for SelfResolver<'a, '_> {
837837
fn visit_id(&mut self, id: NodeId) {
838838
self.try_replace_id(id);
839839
}

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use super::{
2727

2828
pub(super) struct ItemLowerer<'a, 'hir> {
2929
pub(super) tcx: TyCtxt<'hir>,
30-
pub(super) resolver: &'a mut ResolverAstLowering,
30+
pub(super) resolver: &'a mut ResolverAstLowering<'hir>,
3131
pub(super) ast_index: &'a IndexSlice<LocalDefId, AstOwner<'a>>,
3232
pub(super) owners: &'a mut IndexVec<LocalDefId, hir::MaybeOwner<'hir>>,
3333
}

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ struct LoweringContext<'a, 'hir> {
9999
// will be in AST index.
100100
ast_index: &'a IndexSlice<LocalDefId, AstOwner<'a>>,
101101

102-
resolver: &'a mut ResolverAstLowering,
102+
resolver: &'a mut ResolverAstLowering<'hir>,
103103
disambiguator: DisambiguatorState,
104104

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

134134
current_hir_id_owner: hir::OwnerId,
135135
item_local_id_counter: hir::ItemLocalId,
136-
trait_map: ItemLocalMap<Box<[TraitCandidate]>>,
136+
trait_map: ItemLocalMap<&'hir [TraitCandidate<'hir>]>,
137137

138138
impl_trait_defs: Vec<hir::GenericParam<'hir>>,
139139
impl_trait_bounds: Vec<hir::WherePredicate<'hir>>,
@@ -162,7 +162,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
162162
fn new(
163163
tcx: TyCtxt<'hir>,
164164
ast_index: &'a IndexSlice<LocalDefId, AstOwner<'a>>,
165-
resolver: &'a mut ResolverAstLowering,
165+
resolver: &'a mut ResolverAstLowering<'hir>,
166166
) -> Self {
167167
let registered_tools = tcx.registered_tools(()).iter().map(|x| x.name).collect();
168168
Self {
@@ -248,7 +248,7 @@ impl SpanLowerer {
248248
}
249249

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

751-
if let Some(traits) = self.resolver.trait_map.remove(&ast_node_id) {
752-
self.trait_map.insert(hir_id.local_id, traits.into_boxed_slice());
751+
if let Some(&traits) = self.resolver.trait_map.get(&ast_node_id) {
752+
self.trait_map.insert(hir_id.local_id, traits);
753753
}
754754

755755
// Check whether the same `NodeId` is lowered more than once.

compiler/rustc_hir/src/hir.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,7 @@ pub struct OwnerInfo<'hir> {
16331633
pub attrs: AttributeMap<'hir>,
16341634
/// Map indicating what traits are in scope for places where this
16351635
/// is relevant; generated by resolve.
1636-
pub trait_map: ItemLocalMap<Box<[TraitCandidate]>>,
1636+
pub trait_map: ItemLocalMap<&'hir [TraitCandidate<'hir>]>,
16371637

16381638
/// Lints delayed during ast lowering to be emitted
16391639
/// after hir has completely built
@@ -4683,10 +4683,10 @@ pub struct Upvar {
46834683
// The TraitCandidate's import_ids is empty if the trait is defined in the same module, and
46844684
// has length > 0 if the trait is found through an chain of imports, starting with the
46854685
// import/use statement in the scope where the trait is used.
4686-
#[derive(Debug, Clone, HashStable_Generic)]
4687-
pub struct TraitCandidate {
4686+
#[derive(Debug, Clone, Copy, HashStable_Generic)]
4687+
pub struct TraitCandidate<'hir> {
46884688
pub def_id: DefId,
4689-
pub import_ids: SmallVec<[LocalDefId; 1]>,
4689+
pub import_ids: &'hir [LocalDefId],
46904690
// Indicates whether this trait candidate is ambiguously glob imported
46914691
// in it's scope. Related to the AMBIGUOUS_GLOB_IMPORTED_TRAITS lint.
46924692
// If this is set to true and the trait is used as a result of method lookup, this

compiler/rustc_hir_typeck/src/demand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10081008
);
10091009
let container_id = pick.item.container_id(self.tcx);
10101010
let container = with_no_trimmed_paths!(self.tcx.def_path_str(container_id));
1011-
for def_id in pick.import_ids {
1011+
for &def_id in pick.import_ids {
10121012
let hir_id = self.tcx.local_def_id_to_hir_id(def_id);
10131013
path_span
10141014
.push_span_label(self.tcx.hir_span(hir_id), format!("`{container}` imported here"));

compiler/rustc_hir_typeck/src/method/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
196196

197197
// NOTE: on the failure path, we also record the possibly-used trait methods
198198
// since an unused import warning is kinda distracting from the method error.
199-
for &import_id in &pick.import_ids {
199+
for &import_id in pick.import_ids {
200200
debug!("used_trait_import: {:?}", import_id);
201201
self.typeck_results.borrow_mut().used_trait_imports.insert(import_id);
202202
}
@@ -554,7 +554,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
554554
debug!(?pick);
555555
{
556556
let mut typeck_results = self.typeck_results.borrow_mut();
557-
for import_id in pick.import_ids {
557+
for &import_id in pick.import_ids {
558558
debug!(used_trait_import=?import_id);
559559
typeck_results.used_trait_imports.insert(import_id);
560560
}

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use rustc_trait_selection::traits::query::method_autoderef::{
3535
CandidateStep, MethodAutoderefBadTy, MethodAutoderefStepsResult,
3636
};
3737
use rustc_trait_selection::traits::{self, ObligationCause, ObligationCtxt};
38-
use smallvec::{SmallVec, smallvec};
38+
use smallvec::SmallVec;
3939
use tracing::{debug, instrument};
4040

4141
use self::CandidateKind::*;
@@ -98,7 +98,7 @@ impl<'a, 'tcx> Deref for ProbeContext<'a, 'tcx> {
9898
pub(crate) struct Candidate<'tcx> {
9999
pub(crate) item: ty::AssocItem,
100100
pub(crate) kind: CandidateKind<'tcx>,
101-
pub(crate) import_ids: SmallVec<[LocalDefId; 1]>,
101+
pub(crate) import_ids: &'tcx [LocalDefId],
102102
}
103103

104104
#[derive(Debug, Clone)]
@@ -205,7 +205,7 @@ impl PickConstraintsForShadowed {
205205
pub(crate) struct Pick<'tcx> {
206206
pub item: ty::AssocItem,
207207
pub kind: PickKind<'tcx>,
208-
pub import_ids: SmallVec<[LocalDefId; 1]>,
208+
pub import_ids: &'tcx [LocalDefId],
209209

210210
/// Indicates that the source expression should be autoderef'd N times
211211
/// ```ignore (not-rust)
@@ -571,7 +571,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
571571
ty::Binder::dummy(trait_ref),
572572
false,
573573
),
574-
import_ids: smallvec![],
574+
import_ids: &[],
575575
},
576576
false,
577577
);
@@ -943,7 +943,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
943943
Candidate {
944944
item,
945945
kind: InherentImplCandidate { impl_def_id, receiver_steps },
946-
import_ids: smallvec![],
946+
import_ids: &[],
947947
},
948948
true,
949949
);
@@ -976,11 +976,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
976976
traits::supertraits(self.tcx, trait_ref),
977977
|this, new_trait_ref, item| {
978978
this.push_candidate(
979-
Candidate {
980-
item,
981-
kind: ObjectCandidate(new_trait_ref),
982-
import_ids: smallvec![],
983-
},
979+
Candidate { item, kind: ObjectCandidate(new_trait_ref), import_ids: &[] },
984980
true,
985981
);
986982
},
@@ -1015,11 +1011,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
10151011

10161012
self.assemble_candidates_for_bounds(bounds, |this, poly_trait_ref, item| {
10171013
this.push_candidate(
1018-
Candidate {
1019-
item,
1020-
kind: WhereClauseCandidate(poly_trait_ref),
1021-
import_ids: smallvec![],
1022-
},
1014+
Candidate { item, kind: WhereClauseCandidate(poly_trait_ref), import_ids: &[] },
10231015
true,
10241016
);
10251017
});
@@ -1069,11 +1061,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
10691061
let mut duplicates = FxHashSet::default();
10701062
for trait_info in suggest::all_traits(self.tcx) {
10711063
if duplicates.insert(trait_info.def_id) {
1072-
self.assemble_extension_candidates_for_trait(
1073-
&smallvec![],
1074-
trait_info.def_id,
1075-
false,
1076-
);
1064+
self.assemble_extension_candidates_for_trait(&[], trait_info.def_id, false);
10771065
}
10781066
}
10791067
}
@@ -1097,7 +1085,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
10971085
#[instrument(level = "debug", skip(self))]
10981086
fn assemble_extension_candidates_for_trait(
10991087
&mut self,
1100-
import_ids: &SmallVec<[LocalDefId; 1]>,
1088+
import_ids: &'tcx [LocalDefId],
11011089
trait_def_id: DefId,
11021090
lint_ambiguous: bool,
11031091
) {
@@ -1120,7 +1108,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
11201108
self.push_candidate(
11211109
Candidate {
11221110
item,
1123-
import_ids: import_ids.clone(),
1111+
import_ids,
11241112
kind: TraitCandidate(bound_trait_ref, lint_ambiguous),
11251113
},
11261114
false,
@@ -1143,7 +1131,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
11431131
self.push_candidate(
11441132
Candidate {
11451133
item,
1146-
import_ids: import_ids.clone(),
1134+
import_ids,
11471135
kind: TraitCandidate(ty::Binder::dummy(trait_ref), lint_ambiguous),
11481136
},
11491137
false,
@@ -2329,7 +2317,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
23292317
Some(Pick {
23302318
item: probes[0].0.item,
23312319
kind: TraitPick(lint_ambiguous),
2332-
import_ids: probes[0].0.import_ids.clone(),
2320+
import_ids: probes[0].0.import_ids,
23332321
autoderefs: 0,
23342322
autoref_or_ptr_adjustment: None,
23352323
self_ty,
@@ -2406,7 +2394,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
24062394
Some(Pick {
24072395
item: child_candidate.item,
24082396
kind: TraitPick(lint_ambiguous),
2409-
import_ids: child_candidate.import_ids.clone(),
2397+
import_ids: child_candidate.import_ids,
24102398
autoderefs: 0,
24112399
autoref_or_ptr_adjustment: None,
24122400
self_ty,
@@ -2683,7 +2671,7 @@ impl<'tcx> Candidate<'tcx> {
26832671
WhereClausePick(trait_ref)
26842672
}
26852673
},
2686-
import_ids: self.import_ids.clone(),
2674+
import_ids: self.import_ids,
26872675
autoderefs: 0,
26882676
autoref_or_ptr_adjustment: None,
26892677
self_ty,

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
199199
// NOTE: Reporting a method error should also suppress any unused trait errors,
200200
// since the method error is very possibly the reason why the trait wasn't used.
201201
for &import_id in
202-
self.tcx.in_scope_traits(call_id).into_iter().flatten().flat_map(|c| &c.import_ids)
202+
self.tcx.in_scope_traits(call_id).into_iter().flatten().flat_map(|c| c.import_ids)
203203
{
204204
self.typeck_results.borrow_mut().used_trait_imports.insert(import_id);
205205
}

compiler/rustc_interface/src/passes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P
781781
fn resolver_for_lowering_raw<'tcx>(
782782
tcx: TyCtxt<'tcx>,
783783
(): (),
784-
) -> (&'tcx Steal<(ty::ResolverAstLowering, Arc<ast::Crate>)>, &'tcx ty::ResolverGlobalCtxt) {
784+
) -> (&'tcx Steal<(ty::ResolverAstLowering<'tcx>, Arc<ast::Crate>)>, &'tcx ty::ResolverGlobalCtxt) {
785785
let arenas = Resolver::arenas();
786786
let _ = tcx.registered_tools(()); // Uses `crate_for_resolver`.
787787
let (krate, pre_configured_attrs) = tcx.crate_for_resolver(()).steal();

compiler/rustc_middle/src/arena.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ macro_rules! arena_types {
3232
rustc_middle::ty::DefinitionSiteHiddenType<'tcx>,
3333
>,
3434
[] resolver: rustc_data_structures::steal::Steal<(
35-
rustc_middle::ty::ResolverAstLowering,
35+
rustc_middle::ty::ResolverAstLowering<'tcx>,
3636
std::sync::Arc<rustc_ast::Crate>,
3737
)>,
3838
[] crate_for_resolver: rustc_data_structures::steal::Steal<(rustc_ast::Crate, rustc_ast::AttrVec)>,

0 commit comments

Comments
 (0)