Skip to content

Commit a32d392

Browse files
committed
Copy ty::AssocItem all other the place
1 parent 236ddf3 commit a32d392

File tree

17 files changed

+89
-96
lines changed

17 files changed

+89
-96
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![];
@@ -480,7 +480,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RemapLateBound<'_, 'tcx> {
480480

481481
fn emit_implied_wf_lint<'tcx>(
482482
tcx: TyCtxt<'tcx>,
483-
impl_m: &ty::AssocItem,
483+
impl_m: ty::AssocItem,
484484
hir_id: hir::HirId,
485485
bad_args: Vec<(Span, Option<String>)>,
486486
) {
@@ -527,8 +527,8 @@ enum CheckImpliedWfMode {
527527

528528
fn compare_asyncness<'tcx>(
529529
tcx: TyCtxt<'tcx>,
530-
impl_m: &ty::AssocItem,
531-
trait_m: &ty::AssocItem,
530+
impl_m: ty::AssocItem,
531+
trait_m: ty::AssocItem,
532532
) -> Result<(), ErrorGuaranteed> {
533533
if tcx.asyncness(trait_m.def_id) == hir::IsAsync::Async {
534534
match tcx.fn_sig(impl_m.def_id).skip_binder().skip_binder().output().kind() {
@@ -873,8 +873,8 @@ fn report_trait_method_mismatch<'tcx>(
873873
infcx: &InferCtxt<'tcx>,
874874
mut cause: ObligationCause<'tcx>,
875875
terr: TypeError<'tcx>,
876-
(trait_m, trait_sig): (&ty::AssocItem, ty::FnSig<'tcx>),
877-
(impl_m, impl_sig): (&ty::AssocItem, ty::FnSig<'tcx>),
876+
(trait_m, trait_sig): (ty::AssocItem, ty::FnSig<'tcx>),
877+
(impl_m, impl_sig): (ty::AssocItem, ty::FnSig<'tcx>),
878878
impl_trait_ref: ty::TraitRef<'tcx>,
879879
) -> ErrorGuaranteed {
880880
let tcx = infcx.tcx;
@@ -967,8 +967,8 @@ fn report_trait_method_mismatch<'tcx>(
967967

968968
fn check_region_bounds_on_impl_item<'tcx>(
969969
tcx: TyCtxt<'tcx>,
970-
impl_m: &ty::AssocItem,
971-
trait_m: &ty::AssocItem,
970+
impl_m: ty::AssocItem,
971+
trait_m: ty::AssocItem,
972972
delay: bool,
973973
) -> Result<(), ErrorGuaranteed> {
974974
let impl_generics = tcx.generics_of(impl_m.def_id);
@@ -1042,7 +1042,7 @@ fn check_region_bounds_on_impl_item<'tcx>(
10421042
.sess
10431043
.create_err(LifetimesOrBoundsMismatchOnTrait {
10441044
span,
1045-
item_kind: assoc_item_kind_str(impl_m),
1045+
item_kind: assoc_item_kind_str(&impl_m),
10461046
ident: impl_m.ident(tcx),
10471047
generics_span,
10481048
bounds_span,
@@ -1060,8 +1060,8 @@ fn extract_spans_for_error_reporting<'tcx>(
10601060
infcx: &infer::InferCtxt<'tcx>,
10611061
terr: TypeError<'_>,
10621062
cause: &ObligationCause<'tcx>,
1063-
impl_m: &ty::AssocItem,
1064-
trait_m: &ty::AssocItem,
1063+
impl_m: ty::AssocItem,
1064+
trait_m: ty::AssocItem,
10651065
) -> (Span, Option<Span>) {
10661066
let tcx = infcx.tcx;
10671067
let mut impl_args = {
@@ -1084,8 +1084,8 @@ fn extract_spans_for_error_reporting<'tcx>(
10841084

10851085
fn compare_self_type<'tcx>(
10861086
tcx: TyCtxt<'tcx>,
1087-
impl_m: &ty::AssocItem,
1088-
trait_m: &ty::AssocItem,
1087+
impl_m: ty::AssocItem,
1088+
trait_m: ty::AssocItem,
10891089
impl_trait_ref: ty::TraitRef<'tcx>,
10901090
) -> Result<(), ErrorGuaranteed> {
10911091
// Try to give more informative error messages about self typing
@@ -1096,7 +1096,7 @@ fn compare_self_type<'tcx>(
10961096
// inscrutable, particularly for cases where one method has no
10971097
// self.
10981098

1099-
let self_string = |method: &ty::AssocItem| {
1099+
let self_string = |method: ty::AssocItem| {
11001100
let untransformed_self_ty = match method.container {
11011101
ty::ImplContainer => impl_trait_ref.self_ty(),
11021102
ty::TraitContainer => tcx.types.self_param,
@@ -1186,8 +1186,8 @@ fn compare_self_type<'tcx>(
11861186
/// [`compare_generic_param_kinds`]. This function also does not handle lifetime parameters
11871187
fn compare_number_of_generics<'tcx>(
11881188
tcx: TyCtxt<'tcx>,
1189-
impl_: &ty::AssocItem,
1190-
trait_: &ty::AssocItem,
1189+
impl_: ty::AssocItem,
1190+
trait_: ty::AssocItem,
11911191
delay: bool,
11921192
) -> Result<(), ErrorGuaranteed> {
11931193
let trait_own_counts = tcx.generics_of(trait_.def_id).own_counts();
@@ -1207,7 +1207,7 @@ fn compare_number_of_generics<'tcx>(
12071207
("const", trait_own_counts.consts, impl_own_counts.consts),
12081208
];
12091209

1210-
let item_kind = assoc_item_kind_str(impl_);
1210+
let item_kind = assoc_item_kind_str(&impl_);
12111211

12121212
let mut err_occurred = None;
12131213
for (kind, trait_count, impl_count) in matchings {
@@ -1329,8 +1329,8 @@ fn compare_number_of_generics<'tcx>(
13291329

13301330
fn compare_number_of_method_arguments<'tcx>(
13311331
tcx: TyCtxt<'tcx>,
1332-
impl_m: &ty::AssocItem,
1333-
trait_m: &ty::AssocItem,
1332+
impl_m: ty::AssocItem,
1333+
trait_m: ty::AssocItem,
13341334
) -> Result<(), ErrorGuaranteed> {
13351335
let impl_m_fty = tcx.fn_sig(impl_m.def_id);
13361336
let trait_m_fty = tcx.fn_sig(trait_m.def_id);
@@ -1409,8 +1409,8 @@ fn compare_number_of_method_arguments<'tcx>(
14091409

14101410
fn compare_synthetic_generics<'tcx>(
14111411
tcx: TyCtxt<'tcx>,
1412-
impl_m: &ty::AssocItem,
1413-
trait_m: &ty::AssocItem,
1412+
impl_m: ty::AssocItem,
1413+
trait_m: ty::AssocItem,
14141414
) -> Result<(), ErrorGuaranteed> {
14151415
// FIXME(chrisvittal) Clean up this function, list of FIXME items:
14161416
// 1. Better messages for the span labels
@@ -1563,8 +1563,8 @@ fn compare_synthetic_generics<'tcx>(
15631563
/// This function does not handle lifetime parameters
15641564
fn compare_generic_param_kinds<'tcx>(
15651565
tcx: TyCtxt<'tcx>,
1566-
impl_item: &ty::AssocItem,
1567-
trait_item: &ty::AssocItem,
1566+
impl_item: ty::AssocItem,
1567+
trait_item: ty::AssocItem,
15681568
delay: bool,
15691569
) -> Result<(), ErrorGuaranteed> {
15701570
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
@@ -1183,7 +1183,7 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) {
11831183
///
11841184
/// Assuming the defaults are used, check that all predicates (bounds on the
11851185
/// assoc type and where clauses on the trait) hold.
1186-
fn check_associated_type_bounds(wfcx: &WfCheckingCtxt<'_, '_>, item: &ty::AssocItem, span: Span) {
1186+
fn check_associated_type_bounds(wfcx: &WfCheckingCtxt<'_, '_>, item: ty::AssocItem, span: Span) {
11871187
let bounds = wfcx.tcx().explicit_item_bounds(item.def_id);
11881188

11891189
debug!("check_associated_type_bounds: bounds={:?}", bounds);
@@ -1633,7 +1633,7 @@ const HELP_FOR_SELF_TYPE: &str = "consider changing to `self`, `&self`, `&mut se
16331633
fn check_method_receiver<'tcx>(
16341634
wfcx: &WfCheckingCtxt<'_, 'tcx>,
16351635
fn_sig: &hir::FnSig<'_>,
1636-
method: &ty::AssocItem,
1636+
method: ty::AssocItem,
16371637
self_ty: Ty<'tcx>,
16381638
) {
16391639
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)