Skip to content

Commit 9aa5c24

Browse files
committed
Auto merge of #108075 - WaffleLapkin:de-arena-allocates-you-OwO, r=Nilstrieb
Remove `arena_cache` modifier from `associated_item` query & copy `ty::AssocItem` instead of passing by ref r? `@ghost`
2 parents f722b24 + dce666b commit 9aa5c24

File tree

18 files changed

+93
-101
lines changed

18 files changed

+93
-101
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
537537
let assoc_items = tcx.associated_items(id.owner_id);
538538
check_on_unimplemented(tcx, id);
539539

540-
for assoc_item in assoc_items.in_definition_order() {
540+
for &assoc_item in assoc_items.in_definition_order() {
541541
match assoc_item.kind {
542542
ty::AssocKind::Fn => {
543543
let abi = tcx.fn_sig(assoc_item.def_id).skip_binder().abi();
@@ -670,7 +670,7 @@ pub(super) fn check_on_unimplemented(tcx: TyCtxt<'_>, item: hir::ItemId) {
670670
pub(super) fn check_specialization_validity<'tcx>(
671671
tcx: TyCtxt<'tcx>,
672672
trait_def: &ty::TraitDef,
673-
trait_item: &ty::AssocItem,
673+
trait_item: ty::AssocItem,
674674
impl_id: DefId,
675675
impl_item: DefId,
676676
) {
@@ -767,17 +767,17 @@ fn check_impl_items_against_trait<'tcx>(
767767
));
768768
}
769769
ty::AssocKind::Fn => {
770-
compare_impl_method(tcx, &ty_impl_item, &ty_trait_item, impl_trait_ref);
770+
compare_impl_method(tcx, ty_impl_item, ty_trait_item, impl_trait_ref);
771771
}
772772
ty::AssocKind::Type => {
773-
compare_impl_ty(tcx, &ty_impl_item, &ty_trait_item, impl_trait_ref);
773+
compare_impl_ty(tcx, ty_impl_item, ty_trait_item, impl_trait_ref);
774774
}
775775
}
776776

777777
check_specialization_validity(
778778
tcx,
779779
trait_def,
780-
&ty_trait_item,
780+
ty_trait_item,
781781
impl_id.to_def_id(),
782782
impl_item,
783783
);

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+34-34
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ use std::iter;
3737
/// - `impl_trait_ref`: the TraitRef corresponding to the trait implementation
3838
pub(super) fn compare_impl_method<'tcx>(
3939
tcx: TyCtxt<'tcx>,
40-
impl_m: &ty::AssocItem,
41-
trait_m: &ty::AssocItem,
40+
impl_m: ty::AssocItem,
41+
trait_m: ty::AssocItem,
4242
impl_trait_ref: ty::TraitRef<'tcx>,
4343
) {
4444
debug!("compare_impl_method(impl_trait_ref={:?})", impl_trait_ref);
@@ -129,8 +129,8 @@ pub(super) fn compare_impl_method<'tcx>(
129129
#[instrument(level = "debug", skip(tcx, impl_trait_ref))]
130130
fn compare_method_predicate_entailment<'tcx>(
131131
tcx: TyCtxt<'tcx>,
132-
impl_m: &ty::AssocItem,
133-
trait_m: &ty::AssocItem,
132+
impl_m: ty::AssocItem,
133+
trait_m: ty::AssocItem,
134134
impl_trait_ref: ty::TraitRef<'tcx>,
135135
check_implied_wf: CheckImpliedWfMode,
136136
) -> Result<(), ErrorGuaranteed> {
@@ -381,8 +381,8 @@ fn compare_method_predicate_entailment<'tcx>(
381381
fn extract_bad_args_for_implies_lint<'tcx>(
382382
tcx: TyCtxt<'tcx>,
383383
errors: &[infer::RegionResolutionError<'tcx>],
384-
(trait_m, trait_sig): (&ty::AssocItem, ty::FnSig<'tcx>),
385-
(impl_m, impl_sig): (&ty::AssocItem, ty::FnSig<'tcx>),
384+
(trait_m, trait_sig): (ty::AssocItem, ty::FnSig<'tcx>),
385+
(impl_m, impl_sig): (ty::AssocItem, ty::FnSig<'tcx>),
386386
hir_id: hir::HirId,
387387
) -> Vec<(Span, Option<String>)> {
388388
let mut blame_generics = vec![];
@@ -476,7 +476,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RemapLateBound<'_, 'tcx> {
476476

477477
fn emit_implied_wf_lint<'tcx>(
478478
tcx: TyCtxt<'tcx>,
479-
impl_m: &ty::AssocItem,
479+
impl_m: ty::AssocItem,
480480
hir_id: hir::HirId,
481481
bad_args: Vec<(Span, Option<String>)>,
482482
) {
@@ -523,8 +523,8 @@ enum CheckImpliedWfMode {
523523

524524
fn compare_asyncness<'tcx>(
525525
tcx: TyCtxt<'tcx>,
526-
impl_m: &ty::AssocItem,
527-
trait_m: &ty::AssocItem,
526+
impl_m: ty::AssocItem,
527+
trait_m: ty::AssocItem,
528528
) -> Result<(), ErrorGuaranteed> {
529529
if tcx.asyncness(trait_m.def_id) == hir::IsAsync::Async {
530530
match tcx.fn_sig(impl_m.def_id).skip_binder().skip_binder().output().kind() {
@@ -869,8 +869,8 @@ fn report_trait_method_mismatch<'tcx>(
869869
infcx: &InferCtxt<'tcx>,
870870
mut cause: ObligationCause<'tcx>,
871871
terr: TypeError<'tcx>,
872-
(trait_m, trait_sig): (&ty::AssocItem, ty::FnSig<'tcx>),
873-
(impl_m, impl_sig): (&ty::AssocItem, ty::FnSig<'tcx>),
872+
(trait_m, trait_sig): (ty::AssocItem, ty::FnSig<'tcx>),
873+
(impl_m, impl_sig): (ty::AssocItem, ty::FnSig<'tcx>),
874874
impl_trait_ref: ty::TraitRef<'tcx>,
875875
) -> ErrorGuaranteed {
876876
let tcx = infcx.tcx;
@@ -963,8 +963,8 @@ fn report_trait_method_mismatch<'tcx>(
963963

964964
fn check_region_bounds_on_impl_item<'tcx>(
965965
tcx: TyCtxt<'tcx>,
966-
impl_m: &ty::AssocItem,
967-
trait_m: &ty::AssocItem,
966+
impl_m: ty::AssocItem,
967+
trait_m: ty::AssocItem,
968968
delay: bool,
969969
) -> Result<(), ErrorGuaranteed> {
970970
let impl_generics = tcx.generics_of(impl_m.def_id);
@@ -1038,7 +1038,7 @@ fn check_region_bounds_on_impl_item<'tcx>(
10381038
.sess
10391039
.create_err(LifetimesOrBoundsMismatchOnTrait {
10401040
span,
1041-
item_kind: assoc_item_kind_str(impl_m),
1041+
item_kind: assoc_item_kind_str(&impl_m),
10421042
ident: impl_m.ident(tcx),
10431043
generics_span,
10441044
bounds_span,
@@ -1056,8 +1056,8 @@ fn extract_spans_for_error_reporting<'tcx>(
10561056
infcx: &infer::InferCtxt<'tcx>,
10571057
terr: TypeError<'_>,
10581058
cause: &ObligationCause<'tcx>,
1059-
impl_m: &ty::AssocItem,
1060-
trait_m: &ty::AssocItem,
1059+
impl_m: ty::AssocItem,
1060+
trait_m: ty::AssocItem,
10611061
) -> (Span, Option<Span>) {
10621062
let tcx = infcx.tcx;
10631063
let mut impl_args = {
@@ -1080,8 +1080,8 @@ fn extract_spans_for_error_reporting<'tcx>(
10801080

10811081
fn compare_self_type<'tcx>(
10821082
tcx: TyCtxt<'tcx>,
1083-
impl_m: &ty::AssocItem,
1084-
trait_m: &ty::AssocItem,
1083+
impl_m: ty::AssocItem,
1084+
trait_m: ty::AssocItem,
10851085
impl_trait_ref: ty::TraitRef<'tcx>,
10861086
) -> Result<(), ErrorGuaranteed> {
10871087
// Try to give more informative error messages about self typing
@@ -1092,7 +1092,7 @@ fn compare_self_type<'tcx>(
10921092
// inscrutable, particularly for cases where one method has no
10931093
// self.
10941094

1095-
let self_string = |method: &ty::AssocItem| {
1095+
let self_string = |method: ty::AssocItem| {
10961096
let untransformed_self_ty = match method.container {
10971097
ty::ImplContainer => impl_trait_ref.self_ty(),
10981098
ty::TraitContainer => tcx.types.self_param,
@@ -1182,8 +1182,8 @@ fn compare_self_type<'tcx>(
11821182
/// [`compare_generic_param_kinds`]. This function also does not handle lifetime parameters
11831183
fn compare_number_of_generics<'tcx>(
11841184
tcx: TyCtxt<'tcx>,
1185-
impl_: &ty::AssocItem,
1186-
trait_: &ty::AssocItem,
1185+
impl_: ty::AssocItem,
1186+
trait_: ty::AssocItem,
11871187
delay: bool,
11881188
) -> Result<(), ErrorGuaranteed> {
11891189
let trait_own_counts = tcx.generics_of(trait_.def_id).own_counts();
@@ -1203,7 +1203,7 @@ fn compare_number_of_generics<'tcx>(
12031203
("const", trait_own_counts.consts, impl_own_counts.consts),
12041204
];
12051205

1206-
let item_kind = assoc_item_kind_str(impl_);
1206+
let item_kind = assoc_item_kind_str(&impl_);
12071207

12081208
let mut err_occurred = None;
12091209
for (kind, trait_count, impl_count) in matchings {
@@ -1325,8 +1325,8 @@ fn compare_number_of_generics<'tcx>(
13251325

13261326
fn compare_number_of_method_arguments<'tcx>(
13271327
tcx: TyCtxt<'tcx>,
1328-
impl_m: &ty::AssocItem,
1329-
trait_m: &ty::AssocItem,
1328+
impl_m: ty::AssocItem,
1329+
trait_m: ty::AssocItem,
13301330
) -> Result<(), ErrorGuaranteed> {
13311331
let impl_m_fty = tcx.fn_sig(impl_m.def_id);
13321332
let trait_m_fty = tcx.fn_sig(trait_m.def_id);
@@ -1405,8 +1405,8 @@ fn compare_number_of_method_arguments<'tcx>(
14051405

14061406
fn compare_synthetic_generics<'tcx>(
14071407
tcx: TyCtxt<'tcx>,
1408-
impl_m: &ty::AssocItem,
1409-
trait_m: &ty::AssocItem,
1408+
impl_m: ty::AssocItem,
1409+
trait_m: ty::AssocItem,
14101410
) -> Result<(), ErrorGuaranteed> {
14111411
// FIXME(chrisvittal) Clean up this function, list of FIXME items:
14121412
// 1. Better messages for the span labels
@@ -1559,8 +1559,8 @@ fn compare_synthetic_generics<'tcx>(
15591559
/// This function does not handle lifetime parameters
15601560
fn compare_generic_param_kinds<'tcx>(
15611561
tcx: TyCtxt<'tcx>,
1562-
impl_item: &ty::AssocItem,
1563-
trait_item: &ty::AssocItem,
1562+
impl_item: ty::AssocItem,
1563+
trait_item: ty::AssocItem,
15641564
delay: bool,
15651565
) -> Result<(), ErrorGuaranteed> {
15661566
assert_eq!(impl_item.kind, trait_item.kind);
@@ -1736,8 +1736,8 @@ pub(super) fn compare_impl_const_raw(
17361736

17371737
pub(super) fn compare_impl_ty<'tcx>(
17381738
tcx: TyCtxt<'tcx>,
1739-
impl_ty: &ty::AssocItem,
1740-
trait_ty: &ty::AssocItem,
1739+
impl_ty: ty::AssocItem,
1740+
trait_ty: ty::AssocItem,
17411741
impl_trait_ref: ty::TraitRef<'tcx>,
17421742
) {
17431743
debug!("compare_impl_type(impl_trait_ref={:?})", impl_trait_ref);
@@ -1754,8 +1754,8 @@ pub(super) fn compare_impl_ty<'tcx>(
17541754
/// instead of associated functions.
17551755
fn compare_type_predicate_entailment<'tcx>(
17561756
tcx: TyCtxt<'tcx>,
1757-
impl_ty: &ty::AssocItem,
1758-
trait_ty: &ty::AssocItem,
1757+
impl_ty: ty::AssocItem,
1758+
trait_ty: ty::AssocItem,
17591759
impl_trait_ref: ty::TraitRef<'tcx>,
17601760
) -> Result<(), ErrorGuaranteed> {
17611761
let impl_substs = InternalSubsts::identity_for_item(tcx, impl_ty.def_id);
@@ -1855,8 +1855,8 @@ fn compare_type_predicate_entailment<'tcx>(
18551855
#[instrument(level = "debug", skip(tcx))]
18561856
pub(super) fn check_type_bounds<'tcx>(
18571857
tcx: TyCtxt<'tcx>,
1858-
trait_ty: &ty::AssocItem,
1859-
impl_ty: &ty::AssocItem,
1858+
trait_ty: ty::AssocItem,
1859+
impl_ty: ty::AssocItem,
18601860
impl_trait_ref: ty::TraitRef<'tcx>,
18611861
) -> Result<(), ErrorGuaranteed> {
18621862
// Given

compiler/rustc_hir_analysis/src/check/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ fn report_forbidden_specialization(tcx: TyCtxt<'_>, impl_item: DefId, parent_imp
199199
fn missing_items_err(
200200
tcx: TyCtxt<'_>,
201201
impl_span: Span,
202-
missing_items: &[&ty::AssocItem],
202+
missing_items: &[ty::AssocItem],
203203
full_impl_span: Span,
204204
) {
205205
let missing_items_msg = missing_items
@@ -225,7 +225,7 @@ fn missing_items_err(
225225
let padding =
226226
tcx.sess.source_map().indentation_before(sugg_sp).unwrap_or_else(|| String::new());
227227

228-
for trait_item in missing_items {
228+
for &trait_item in missing_items {
229229
let snippet = suggestion_signature(trait_item, tcx);
230230
let code = format!("{}{}\n{}", padding, snippet, padding);
231231
let msg = format!("implement the missing item: `{snippet}`");
@@ -272,7 +272,7 @@ fn default_body_is_unstable(
272272
reason: Option<Symbol>,
273273
issue: Option<NonZeroU32>,
274274
) {
275-
let missing_item_name = &tcx.associated_item(item_did).name;
275+
let missing_item_name = tcx.associated_item(item_did).name;
276276
let use_of_unstable_library_feature_note = match reason {
277277
Some(r) => format!("use of unstable library feature '{feature}': {r}"),
278278
None => format!("use of unstable library feature '{feature}'"),
@@ -365,7 +365,7 @@ fn fn_sig_suggestion<'tcx>(
365365
sig: ty::FnSig<'tcx>,
366366
ident: Ident,
367367
predicates: ty::GenericPredicates<'tcx>,
368-
assoc: &ty::AssocItem,
368+
assoc: ty::AssocItem,
369369
) -> String {
370370
let args = sig
371371
.inputs()
@@ -433,7 +433,7 @@ pub fn ty_kind_suggestion(ty: Ty<'_>) -> Option<&'static str> {
433433
/// Return placeholder code for the given associated item.
434434
/// Similar to `ty::AssocItem::suggestion`, but appropriate for use as the code snippet of a
435435
/// structured suggestion.
436-
fn suggestion_signature(assoc: &ty::AssocItem, tcx: TyCtxt<'_>) -> String {
436+
fn suggestion_signature(assoc: ty::AssocItem, tcx: TyCtxt<'_>) -> String {
437437
match assoc.kind {
438438
ty::AssocKind::Fn => {
439439
// We skip the binder here because the binder would deanonymize all

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,7 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) {
11801180
///
11811181
/// Assuming the defaults are used, check that all predicates (bounds on the
11821182
/// assoc type and where clauses on the trait) hold.
1183-
fn check_associated_type_bounds(wfcx: &WfCheckingCtxt<'_, '_>, item: &ty::AssocItem, span: Span) {
1183+
fn check_associated_type_bounds(wfcx: &WfCheckingCtxt<'_, '_>, item: ty::AssocItem, span: Span) {
11841184
let bounds = wfcx.tcx().explicit_item_bounds(item.def_id);
11851185

11861186
debug!("check_associated_type_bounds: bounds={:?}", bounds);
@@ -1630,7 +1630,7 @@ const HELP_FOR_SELF_TYPE: &str = "consider changing to `self`, `&self`, `&mut se
16301630
fn check_method_receiver<'tcx>(
16311631
wfcx: &WfCheckingCtxt<'_, 'tcx>,
16321632
fn_sig: &hir::FnSig<'_>,
1633-
method: &ty::AssocItem,
1633+
method: ty::AssocItem,
16341634
self_ty: Ty<'tcx>,
16351635
) {
16361636
let tcx = wfcx.tcx();

compiler/rustc_hir_analysis/src/coherence/inherent_impls_overlap.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
2727
/// namespace.
2828
fn impls_have_common_items(
2929
&self,
30-
impl_items1: &ty::AssocItems<'_>,
31-
impl_items2: &ty::AssocItems<'_>,
30+
impl_items1: &ty::AssocItems,
31+
impl_items2: &ty::AssocItems,
3232
) -> bool {
3333
let mut impl_items1 = &impl_items1;
3434
let mut impl_items2 = &impl_items2;
@@ -38,10 +38,10 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
3838
std::mem::swap(&mut impl_items1, &mut impl_items2);
3939
}
4040

41-
for item1 in impl_items1.in_definition_order() {
41+
for &item1 in impl_items1.in_definition_order() {
4242
let collision = impl_items2
4343
.filter_by_name_unhygienic(item1.name)
44-
.any(|item2| self.compare_hygienically(item1, item2));
44+
.any(|&item2| self.compare_hygienically(item1, item2));
4545

4646
if collision {
4747
return true;
@@ -51,7 +51,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
5151
false
5252
}
5353

54-
fn compare_hygienically(&self, item1: &ty::AssocItem, item2: &ty::AssocItem) -> bool {
54+
fn compare_hygienically(&self, item1: ty::AssocItem, item2: ty::AssocItem) -> bool {
5555
// Symbols and namespace match, compare hygienically.
5656
item1.kind.namespace() == item2.kind.namespace()
5757
&& item1.ident(self.tcx).normalize_to_macros_2_0()
@@ -98,10 +98,10 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
9898
let impl_items1 = self.tcx.associated_items(impl1);
9999
let impl_items2 = self.tcx.associated_items(impl2);
100100

101-
for item1 in impl_items1.in_definition_order() {
101+
for &item1 in impl_items1.in_definition_order() {
102102
let collision = impl_items2
103103
.filter_by_name_unhygienic(item1.name)
104-
.find(|item2| self.compare_hygienically(item1, item2));
104+
.find(|&&item2| self.compare_hygienically(item1, item2));
105105

106106
if let Some(item2) = collision {
107107
let name = item1.ident(self.tcx).normalize_to_macros_2_0();

compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
423423

424424
fn get_unbound_associated_types(&self) -> Vec<String> {
425425
if self.tcx.is_trait(self.def_id) {
426-
let items: &AssocItems<'_> = self.tcx.associated_items(self.def_id);
426+
let items: &AssocItems = self.tcx.associated_items(self.def_id);
427427
items
428428
.in_definition_order()
429429
.filter(|item| item.kind == AssocKind::Type)

0 commit comments

Comments
 (0)