From 236ddf36b37cba82cdbfbab7fe9991d113ececf8 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Fri, 3 Feb 2023 16:29:46 +0000 Subject: [PATCH 1/3] Remove `arena_cache` modifier from queries which return `Copy` types --- compiler/rustc_middle/src/query/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index f02e3a9aa29f6..420c32ce4770d 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -729,9 +729,8 @@ rustc_queries! { } /// Maps from a trait item to the trait item "descriptor". - query associated_item(key: DefId) -> &'tcx ty::AssocItem { + query associated_item(key: DefId) -> ty::AssocItem { desc { |tcx| "computing associated item data for `{}`", tcx.def_path_str(key) } - arena_cache cache_on_disk_if { key.is_local() } separate_provide_extern } From a32d39274113c30d8e367f729028e605ccbc6313 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 6 Feb 2023 08:57:34 +0000 Subject: [PATCH 2/3] Copy `ty::AssocItem` all other the place --- .../rustc_hir_analysis/src/check/check.rs | 10 +-- .../src/check/compare_impl_item.rs | 68 +++++++++---------- compiler/rustc_hir_analysis/src/check/mod.rs | 10 +-- .../rustc_hir_analysis/src/check/wfcheck.rs | 4 +- .../src/coherence/inherent_impls_overlap.rs | 14 ++-- .../wrong_number_of_generic_args.rs | 2 +- compiler/rustc_hir_typeck/src/method/probe.rs | 21 +++--- .../infer/error_reporting/note_and_explain.rs | 6 +- compiler/rustc_middle/src/query/mod.rs | 2 +- .../src/traits/specialization_graph.rs | 8 +-- compiler/rustc_middle/src/ty/assoc.rs | 12 ++-- compiler/rustc_middle/src/ty/mod.rs | 2 +- .../src/traits/object_safety.rs | 12 ++-- .../src/traits/project.rs | 6 +- .../traits/specialize/specialization_graph.rs | 2 +- .../src/traits/vtable.rs | 4 +- compiler/rustc_ty_utils/src/assoc.rs | 2 +- 17 files changed, 89 insertions(+), 96 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 49ad09800a5a0..0fcc3cce689ce 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -537,7 +537,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) { let assoc_items = tcx.associated_items(id.owner_id); check_on_unimplemented(tcx, id); - for assoc_item in assoc_items.in_definition_order() { + for &assoc_item in assoc_items.in_definition_order() { match assoc_item.kind { ty::AssocKind::Fn => { 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) { pub(super) fn check_specialization_validity<'tcx>( tcx: TyCtxt<'tcx>, trait_def: &ty::TraitDef, - trait_item: &ty::AssocItem, + trait_item: ty::AssocItem, impl_id: DefId, impl_item: DefId, ) { @@ -767,17 +767,17 @@ fn check_impl_items_against_trait<'tcx>( )); } ty::AssocKind::Fn => { - compare_impl_method(tcx, &ty_impl_item, &ty_trait_item, impl_trait_ref); + compare_impl_method(tcx, ty_impl_item, ty_trait_item, impl_trait_ref); } ty::AssocKind::Type => { - compare_impl_ty(tcx, &ty_impl_item, &ty_trait_item, impl_trait_ref); + compare_impl_ty(tcx, ty_impl_item, ty_trait_item, impl_trait_ref); } } check_specialization_validity( tcx, trait_def, - &ty_trait_item, + ty_trait_item, impl_id.to_def_id(), impl_item, ); diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs index 50f9bbc022e7c..7c3203b5422ed 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -37,8 +37,8 @@ use std::iter; /// - `impl_trait_ref`: the TraitRef corresponding to the trait implementation pub(super) fn compare_impl_method<'tcx>( tcx: TyCtxt<'tcx>, - impl_m: &ty::AssocItem, - trait_m: &ty::AssocItem, + impl_m: ty::AssocItem, + trait_m: ty::AssocItem, impl_trait_ref: ty::TraitRef<'tcx>, ) { debug!("compare_impl_method(impl_trait_ref={:?})", impl_trait_ref); @@ -129,8 +129,8 @@ pub(super) fn compare_impl_method<'tcx>( #[instrument(level = "debug", skip(tcx, impl_trait_ref))] fn compare_method_predicate_entailment<'tcx>( tcx: TyCtxt<'tcx>, - impl_m: &ty::AssocItem, - trait_m: &ty::AssocItem, + impl_m: ty::AssocItem, + trait_m: ty::AssocItem, impl_trait_ref: ty::TraitRef<'tcx>, check_implied_wf: CheckImpliedWfMode, ) -> Result<(), ErrorGuaranteed> { @@ -381,8 +381,8 @@ fn compare_method_predicate_entailment<'tcx>( fn extract_bad_args_for_implies_lint<'tcx>( tcx: TyCtxt<'tcx>, errors: &[infer::RegionResolutionError<'tcx>], - (trait_m, trait_sig): (&ty::AssocItem, ty::FnSig<'tcx>), - (impl_m, impl_sig): (&ty::AssocItem, ty::FnSig<'tcx>), + (trait_m, trait_sig): (ty::AssocItem, ty::FnSig<'tcx>), + (impl_m, impl_sig): (ty::AssocItem, ty::FnSig<'tcx>), hir_id: hir::HirId, ) -> Vec<(Span, Option)> { let mut blame_generics = vec![]; @@ -480,7 +480,7 @@ impl<'tcx> TypeFolder> for RemapLateBound<'_, 'tcx> { fn emit_implied_wf_lint<'tcx>( tcx: TyCtxt<'tcx>, - impl_m: &ty::AssocItem, + impl_m: ty::AssocItem, hir_id: hir::HirId, bad_args: Vec<(Span, Option)>, ) { @@ -527,8 +527,8 @@ enum CheckImpliedWfMode { fn compare_asyncness<'tcx>( tcx: TyCtxt<'tcx>, - impl_m: &ty::AssocItem, - trait_m: &ty::AssocItem, + impl_m: ty::AssocItem, + trait_m: ty::AssocItem, ) -> Result<(), ErrorGuaranteed> { if tcx.asyncness(trait_m.def_id) == hir::IsAsync::Async { match tcx.fn_sig(impl_m.def_id).skip_binder().skip_binder().output().kind() { @@ -873,8 +873,8 @@ fn report_trait_method_mismatch<'tcx>( infcx: &InferCtxt<'tcx>, mut cause: ObligationCause<'tcx>, terr: TypeError<'tcx>, - (trait_m, trait_sig): (&ty::AssocItem, ty::FnSig<'tcx>), - (impl_m, impl_sig): (&ty::AssocItem, ty::FnSig<'tcx>), + (trait_m, trait_sig): (ty::AssocItem, ty::FnSig<'tcx>), + (impl_m, impl_sig): (ty::AssocItem, ty::FnSig<'tcx>), impl_trait_ref: ty::TraitRef<'tcx>, ) -> ErrorGuaranteed { let tcx = infcx.tcx; @@ -967,8 +967,8 @@ fn report_trait_method_mismatch<'tcx>( fn check_region_bounds_on_impl_item<'tcx>( tcx: TyCtxt<'tcx>, - impl_m: &ty::AssocItem, - trait_m: &ty::AssocItem, + impl_m: ty::AssocItem, + trait_m: ty::AssocItem, delay: bool, ) -> Result<(), ErrorGuaranteed> { let impl_generics = tcx.generics_of(impl_m.def_id); @@ -1042,7 +1042,7 @@ fn check_region_bounds_on_impl_item<'tcx>( .sess .create_err(LifetimesOrBoundsMismatchOnTrait { span, - item_kind: assoc_item_kind_str(impl_m), + item_kind: assoc_item_kind_str(&impl_m), ident: impl_m.ident(tcx), generics_span, bounds_span, @@ -1060,8 +1060,8 @@ fn extract_spans_for_error_reporting<'tcx>( infcx: &infer::InferCtxt<'tcx>, terr: TypeError<'_>, cause: &ObligationCause<'tcx>, - impl_m: &ty::AssocItem, - trait_m: &ty::AssocItem, + impl_m: ty::AssocItem, + trait_m: ty::AssocItem, ) -> (Span, Option) { let tcx = infcx.tcx; let mut impl_args = { @@ -1084,8 +1084,8 @@ fn extract_spans_for_error_reporting<'tcx>( fn compare_self_type<'tcx>( tcx: TyCtxt<'tcx>, - impl_m: &ty::AssocItem, - trait_m: &ty::AssocItem, + impl_m: ty::AssocItem, + trait_m: ty::AssocItem, impl_trait_ref: ty::TraitRef<'tcx>, ) -> Result<(), ErrorGuaranteed> { // Try to give more informative error messages about self typing @@ -1096,7 +1096,7 @@ fn compare_self_type<'tcx>( // inscrutable, particularly for cases where one method has no // self. - let self_string = |method: &ty::AssocItem| { + let self_string = |method: ty::AssocItem| { let untransformed_self_ty = match method.container { ty::ImplContainer => impl_trait_ref.self_ty(), ty::TraitContainer => tcx.types.self_param, @@ -1186,8 +1186,8 @@ fn compare_self_type<'tcx>( /// [`compare_generic_param_kinds`]. This function also does not handle lifetime parameters fn compare_number_of_generics<'tcx>( tcx: TyCtxt<'tcx>, - impl_: &ty::AssocItem, - trait_: &ty::AssocItem, + impl_: ty::AssocItem, + trait_: ty::AssocItem, delay: bool, ) -> Result<(), ErrorGuaranteed> { let trait_own_counts = tcx.generics_of(trait_.def_id).own_counts(); @@ -1207,7 +1207,7 @@ fn compare_number_of_generics<'tcx>( ("const", trait_own_counts.consts, impl_own_counts.consts), ]; - let item_kind = assoc_item_kind_str(impl_); + let item_kind = assoc_item_kind_str(&impl_); let mut err_occurred = None; for (kind, trait_count, impl_count) in matchings { @@ -1329,8 +1329,8 @@ fn compare_number_of_generics<'tcx>( fn compare_number_of_method_arguments<'tcx>( tcx: TyCtxt<'tcx>, - impl_m: &ty::AssocItem, - trait_m: &ty::AssocItem, + impl_m: ty::AssocItem, + trait_m: ty::AssocItem, ) -> Result<(), ErrorGuaranteed> { let impl_m_fty = tcx.fn_sig(impl_m.def_id); let trait_m_fty = tcx.fn_sig(trait_m.def_id); @@ -1409,8 +1409,8 @@ fn compare_number_of_method_arguments<'tcx>( fn compare_synthetic_generics<'tcx>( tcx: TyCtxt<'tcx>, - impl_m: &ty::AssocItem, - trait_m: &ty::AssocItem, + impl_m: ty::AssocItem, + trait_m: ty::AssocItem, ) -> Result<(), ErrorGuaranteed> { // FIXME(chrisvittal) Clean up this function, list of FIXME items: // 1. Better messages for the span labels @@ -1563,8 +1563,8 @@ fn compare_synthetic_generics<'tcx>( /// This function does not handle lifetime parameters fn compare_generic_param_kinds<'tcx>( tcx: TyCtxt<'tcx>, - impl_item: &ty::AssocItem, - trait_item: &ty::AssocItem, + impl_item: ty::AssocItem, + trait_item: ty::AssocItem, delay: bool, ) -> Result<(), ErrorGuaranteed> { assert_eq!(impl_item.kind, trait_item.kind); @@ -1736,8 +1736,8 @@ pub(super) fn compare_impl_const_raw( pub(super) fn compare_impl_ty<'tcx>( tcx: TyCtxt<'tcx>, - impl_ty: &ty::AssocItem, - trait_ty: &ty::AssocItem, + impl_ty: ty::AssocItem, + trait_ty: ty::AssocItem, impl_trait_ref: ty::TraitRef<'tcx>, ) { debug!("compare_impl_type(impl_trait_ref={:?})", impl_trait_ref); @@ -1754,8 +1754,8 @@ pub(super) fn compare_impl_ty<'tcx>( /// instead of associated functions. fn compare_type_predicate_entailment<'tcx>( tcx: TyCtxt<'tcx>, - impl_ty: &ty::AssocItem, - trait_ty: &ty::AssocItem, + impl_ty: ty::AssocItem, + trait_ty: ty::AssocItem, impl_trait_ref: ty::TraitRef<'tcx>, ) -> Result<(), ErrorGuaranteed> { let impl_substs = InternalSubsts::identity_for_item(tcx, impl_ty.def_id); @@ -1855,8 +1855,8 @@ fn compare_type_predicate_entailment<'tcx>( #[instrument(level = "debug", skip(tcx))] pub(super) fn check_type_bounds<'tcx>( tcx: TyCtxt<'tcx>, - trait_ty: &ty::AssocItem, - impl_ty: &ty::AssocItem, + trait_ty: ty::AssocItem, + impl_ty: ty::AssocItem, impl_trait_ref: ty::TraitRef<'tcx>, ) -> Result<(), ErrorGuaranteed> { // Given diff --git a/compiler/rustc_hir_analysis/src/check/mod.rs b/compiler/rustc_hir_analysis/src/check/mod.rs index 7b013cabc3ab5..69694244924cb 100644 --- a/compiler/rustc_hir_analysis/src/check/mod.rs +++ b/compiler/rustc_hir_analysis/src/check/mod.rs @@ -199,7 +199,7 @@ fn report_forbidden_specialization(tcx: TyCtxt<'_>, impl_item: DefId, parent_imp fn missing_items_err( tcx: TyCtxt<'_>, impl_span: Span, - missing_items: &[&ty::AssocItem], + missing_items: &[ty::AssocItem], full_impl_span: Span, ) { let missing_items_msg = missing_items @@ -225,7 +225,7 @@ fn missing_items_err( let padding = tcx.sess.source_map().indentation_before(sugg_sp).unwrap_or_else(|| String::new()); - for trait_item in missing_items { + for &trait_item in missing_items { let snippet = suggestion_signature(trait_item, tcx); let code = format!("{}{}\n{}", padding, snippet, padding); let msg = format!("implement the missing item: `{snippet}`"); @@ -272,7 +272,7 @@ fn default_body_is_unstable( reason: Option, issue: Option, ) { - let missing_item_name = &tcx.associated_item(item_did).name; + let missing_item_name = tcx.associated_item(item_did).name; let use_of_unstable_library_feature_note = match reason { Some(r) => format!("use of unstable library feature '{feature}': {r}"), None => format!("use of unstable library feature '{feature}'"), @@ -365,7 +365,7 @@ fn fn_sig_suggestion<'tcx>( sig: ty::FnSig<'tcx>, ident: Ident, predicates: ty::GenericPredicates<'tcx>, - assoc: &ty::AssocItem, + assoc: ty::AssocItem, ) -> String { let args = sig .inputs() @@ -433,7 +433,7 @@ pub fn ty_kind_suggestion(ty: Ty<'_>) -> Option<&'static str> { /// Return placeholder code for the given associated item. /// Similar to `ty::AssocItem::suggestion`, but appropriate for use as the code snippet of a /// structured suggestion. -fn suggestion_signature(assoc: &ty::AssocItem, tcx: TyCtxt<'_>) -> String { +fn suggestion_signature(assoc: ty::AssocItem, tcx: TyCtxt<'_>) -> String { match assoc.kind { ty::AssocKind::Fn => { // We skip the binder here because the binder would deanonymize all diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 16e7dcd0060da..4438c14ea21cb 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1183,7 +1183,7 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) { /// /// Assuming the defaults are used, check that all predicates (bounds on the /// assoc type and where clauses on the trait) hold. -fn check_associated_type_bounds(wfcx: &WfCheckingCtxt<'_, '_>, item: &ty::AssocItem, span: Span) { +fn check_associated_type_bounds(wfcx: &WfCheckingCtxt<'_, '_>, item: ty::AssocItem, span: Span) { let bounds = wfcx.tcx().explicit_item_bounds(item.def_id); debug!("check_associated_type_bounds: bounds={:?}", bounds); @@ -1633,7 +1633,7 @@ const HELP_FOR_SELF_TYPE: &str = "consider changing to `self`, `&self`, `&mut se fn check_method_receiver<'tcx>( wfcx: &WfCheckingCtxt<'_, 'tcx>, fn_sig: &hir::FnSig<'_>, - method: &ty::AssocItem, + method: ty::AssocItem, self_ty: Ty<'tcx>, ) { let tcx = wfcx.tcx(); diff --git a/compiler/rustc_hir_analysis/src/coherence/inherent_impls_overlap.rs b/compiler/rustc_hir_analysis/src/coherence/inherent_impls_overlap.rs index a9331af4eab32..7bca4edcc8c96 100644 --- a/compiler/rustc_hir_analysis/src/coherence/inherent_impls_overlap.rs +++ b/compiler/rustc_hir_analysis/src/coherence/inherent_impls_overlap.rs @@ -27,8 +27,8 @@ impl<'tcx> InherentOverlapChecker<'tcx> { /// namespace. fn impls_have_common_items( &self, - impl_items1: &ty::AssocItems<'_>, - impl_items2: &ty::AssocItems<'_>, + impl_items1: &ty::AssocItems, + impl_items2: &ty::AssocItems, ) -> bool { let mut impl_items1 = &impl_items1; let mut impl_items2 = &impl_items2; @@ -38,10 +38,10 @@ impl<'tcx> InherentOverlapChecker<'tcx> { std::mem::swap(&mut impl_items1, &mut impl_items2); } - for item1 in impl_items1.in_definition_order() { + for &item1 in impl_items1.in_definition_order() { let collision = impl_items2 .filter_by_name_unhygienic(item1.name) - .any(|item2| self.compare_hygienically(item1, item2)); + .any(|&item2| self.compare_hygienically(item1, item2)); if collision { return true; @@ -51,7 +51,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> { false } - fn compare_hygienically(&self, item1: &ty::AssocItem, item2: &ty::AssocItem) -> bool { + fn compare_hygienically(&self, item1: ty::AssocItem, item2: ty::AssocItem) -> bool { // Symbols and namespace match, compare hygienically. item1.kind.namespace() == item2.kind.namespace() && item1.ident(self.tcx).normalize_to_macros_2_0() @@ -98,10 +98,10 @@ impl<'tcx> InherentOverlapChecker<'tcx> { let impl_items1 = self.tcx.associated_items(impl1); let impl_items2 = self.tcx.associated_items(impl2); - for item1 in impl_items1.in_definition_order() { + for &item1 in impl_items1.in_definition_order() { let collision = impl_items2 .filter_by_name_unhygienic(item1.name) - .find(|item2| self.compare_hygienically(item1, item2)); + .find(|&&item2| self.compare_hygienically(item1, item2)); if let Some(item2) = collision { let name = item1.ident(self.tcx).normalize_to_macros_2_0(); diff --git a/compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs b/compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs index 9133e6540d445..560ffc620e0de 100644 --- a/compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs +++ b/compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs @@ -423,7 +423,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { fn get_unbound_associated_types(&self) -> Vec { if self.tcx.is_trait(self.def_id) { - let items: &AssocItems<'_> = self.tcx.associated_items(self.def_id); + let items: &AssocItems = self.tcx.associated_items(self.def_id); items .in_definition_order() .filter(|item| item.kind == AssocKind::Type) diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index b5e6727bfbadf..fb60eea1e8bfe 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -736,7 +736,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { debug!("impl_ty: {:?}", impl_ty); // Determine the receiver type that the method itself expects. - let (xform_self_ty, xform_ret_ty) = self.xform_self_ty(&item, impl_ty, impl_substs); + let (xform_self_ty, xform_ret_ty) = self.xform_self_ty(item, impl_ty, impl_substs); debug!("xform_self_ty: {:?}, xform_ret_ty: {:?}", xform_self_ty, xform_ret_ty); // We can't use normalize_associated_types_in as it will pollute the @@ -797,7 +797,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { let new_trait_ref = this.erase_late_bound_regions(new_trait_ref); let (xform_self_ty, xform_ret_ty) = - this.xform_self_ty(&item, new_trait_ref.self_ty(), new_trait_ref.substs); + this.xform_self_ty(item, new_trait_ref.self_ty(), new_trait_ref.substs); this.push_candidate( Candidate { xform_self_ty, @@ -846,7 +846,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { let trait_ref = this.erase_late_bound_regions(poly_trait_ref); let (xform_self_ty, xform_ret_ty) = - this.xform_self_ty(&item, trait_ref.self_ty(), trait_ref.substs); + this.xform_self_ty(item, trait_ref.self_ty(), trait_ref.substs); // Because this trait derives from a where-clause, it // should not contain any inference variables or other @@ -917,7 +917,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { fn matches_return_type( &self, - method: &ty::AssocItem, + method: ty::AssocItem, self_ty: Option>, expected: Ty<'tcx>, ) -> bool { @@ -966,11 +966,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { } else { let new_trait_ref = self.erase_late_bound_regions(bound_trait_ref); - let (xform_self_ty, xform_ret_ty) = self.xform_self_ty( - &item, - new_trait_ref.self_ty(), - new_trait_ref.substs, - ); + let (xform_self_ty, xform_ret_ty) = + self.xform_self_ty(item, new_trait_ref.self_ty(), new_trait_ref.substs); self.push_candidate( Candidate { xform_self_ty, @@ -998,7 +995,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { } let (xform_self_ty, xform_ret_ty) = - self.xform_self_ty(&item, trait_ref.self_ty(), trait_substs); + self.xform_self_ty(item, trait_ref.self_ty(), trait_substs); self.push_candidate( Candidate { xform_self_ty, @@ -1025,7 +1022,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { .filter(|candidate| candidate_filter(&candidate.item)) .filter(|candidate| { if let Some(return_ty) = self.return_type { - self.matches_return_type(&candidate.item, None, return_ty) + self.matches_return_type(candidate.item, None, return_ty) } else { true } @@ -1884,7 +1881,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { #[instrument(level = "debug", skip(self))] fn xform_self_ty( &self, - item: &ty::AssocItem, + item: ty::AssocItem, impl_ty: Ty<'tcx>, substs: SubstsRef<'tcx>, ) -> (Ty<'tcx>, Option>) { diff --git a/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs b/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs index 984e8cf6a0eb9..3dec5bc77e007 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs @@ -326,7 +326,7 @@ impl Trait for X { diag, &trait_ref, pred.bounds, - &assoc, + assoc, assoc_substs, ty, msg, @@ -622,7 +622,7 @@ fn foo(&self) -> Self::T { String::new() } diag: &mut Diagnostic, trait_ref: &ty::TraitRef<'tcx>, bounds: hir::GenericBounds<'_>, - assoc: &ty::AssocItem, + assoc: ty::AssocItem, assoc_substs: &[ty::GenericArg<'tcx>], ty: Ty<'tcx>, msg: &str, @@ -665,7 +665,7 @@ fn foo(&self) -> Self::T { String::new() } &self, diag: &mut Diagnostic, span: Span, - assoc: &ty::AssocItem, + assoc: ty::AssocItem, assoc_substs: &[ty::GenericArg<'tcx>], ty: Ty<'tcx>, msg: &str, diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 420c32ce4770d..a387b845faed2 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -736,7 +736,7 @@ rustc_queries! { } /// Collects the associated items defined on a trait or impl. - query associated_items(key: DefId) -> &'tcx ty::AssocItems<'tcx> { + query associated_items(key: DefId) -> &'tcx ty::AssocItems { arena_cache desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) } } diff --git a/compiler/rustc_middle/src/traits/specialization_graph.rs b/compiler/rustc_middle/src/traits/specialization_graph.rs index aad5b2fbe0769..c90d422df9056 100644 --- a/compiler/rustc_middle/src/traits/specialization_graph.rs +++ b/compiler/rustc_middle/src/traits/specialization_graph.rs @@ -133,11 +133,7 @@ impl Node { /// /// If this returns `None`, the item can potentially still be found in /// parents of this node. - pub fn item<'tcx>( - &self, - tcx: TyCtxt<'tcx>, - trait_item_def_id: DefId, - ) -> Option<&'tcx ty::AssocItem> { + pub fn item<'tcx>(&self, tcx: TyCtxt<'tcx>, trait_item_def_id: DefId) -> Option { match *self { Node::Trait(_) => Some(tcx.associated_item(trait_item_def_id)), Node::Impl(impl_def_id) => { @@ -239,7 +235,7 @@ impl<'tcx> Ancestors<'tcx> { } } - Some(LeafDef { item: *item, defining_node: node, finalizing_node }) + Some(LeafDef { item, defining_node: node, finalizing_node }) } else { // Item not mentioned. This "finalizes" any defaulted item provided by an ancestor. finalizing_node = Some(node); diff --git a/compiler/rustc_middle/src/ty/assoc.rs b/compiler/rustc_middle/src/ty/assoc.rs index 71cecfb558fb2..ace9649236391 100644 --- a/compiler/rustc_middle/src/ty/assoc.rs +++ b/compiler/rustc_middle/src/ty/assoc.rs @@ -129,13 +129,13 @@ impl std::fmt::Display for AssocKind { /// it is relatively expensive. Instead, items are indexed by `Symbol` and hygienic comparison is /// done only on items with the same name. #[derive(Debug, Clone, PartialEq, HashStable)] -pub struct AssocItems<'tcx> { - items: SortedIndexMultiMap, +pub struct AssocItems { + items: SortedIndexMultiMap, } -impl<'tcx> AssocItems<'tcx> { +impl AssocItems { /// Constructs an `AssociatedItems` map from a series of `ty::AssocItem`s in definition order. - pub fn new(items_in_def_order: impl IntoIterator) -> Self { + pub fn new(items_in_def_order: impl IntoIterator) -> Self { let items = items_in_def_order.into_iter().map(|item| (item.name, item)).collect(); AssocItems { items } } @@ -145,7 +145,7 @@ impl<'tcx> AssocItems<'tcx> { /// New code should avoid relying on definition order. If you need a particular associated item /// for a known trait, make that trait a lang item instead of indexing this array. pub fn in_definition_order(&self) -> impl '_ + Iterator { - self.items.iter().map(|(_, v)| *v) + self.items.iter().map(|(_, v)| v) } pub fn len(&self) -> usize { @@ -157,7 +157,7 @@ impl<'tcx> AssocItems<'tcx> { &self, name: Symbol, ) -> impl '_ + Iterator { - self.items.get_by_key(name).copied() + self.items.get_by_key(name) } /// Returns the associated item with the given name and `AssocKind`, if one exists. diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 7d9396ecd6571..9913fc0a3c59d 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -2198,7 +2198,7 @@ impl<'tcx> TyCtxt<'tcx> { Some(Ident::new(def, span)) } - pub fn opt_associated_item(self, def_id: DefId) -> Option<&'tcx AssocItem> { + pub fn opt_associated_item(self, def_id: DefId) -> Option { if let DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy = self.def_kind(def_id) { Some(self.associated_item(def_id)) } else { diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index c12ba103c340c..d474714f2aca4 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -97,7 +97,7 @@ fn check_is_object_safe(tcx: TyCtxt<'_>, trait_def_id: DefId) -> bool { /// object. Note that object-safe traits can have some /// non-vtable-safe methods, so long as they require `Self: Sized` or /// otherwise ensure that they cannot be used when `Self = Trait`. -pub fn is_vtable_safe_method(tcx: TyCtxt<'_>, trait_def_id: DefId, method: &ty::AssocItem) -> bool { +pub fn is_vtable_safe_method(tcx: TyCtxt<'_>, trait_def_id: DefId, method: ty::AssocItem) -> bool { debug_assert!(tcx.generics_of(trait_def_id).has_self); debug!("is_vtable_safe_method({:?}, {:?})", trait_def_id, method); // Any method that has a `Self: Sized` bound cannot be called. @@ -120,8 +120,8 @@ fn object_safety_violations_for_trait( .associated_items(trait_def_id) .in_definition_order() .filter(|item| item.kind == ty::AssocKind::Fn) - .filter_map(|item| { - object_safety_violation_for_method(tcx, trait_def_id, &item) + .filter_map(|&item| { + object_safety_violation_for_method(tcx, trait_def_id, item) .map(|(code, span)| ObjectSafetyViolation::Method(item.name, code, span)) }) .collect(); @@ -382,7 +382,7 @@ fn generics_require_sized_self(tcx: TyCtxt<'_>, def_id: DefId) -> bool { fn object_safety_violation_for_method( tcx: TyCtxt<'_>, trait_def_id: DefId, - method: &ty::AssocItem, + method: ty::AssocItem, ) -> Option<(MethodViolationCode, Span)> { debug!("object_safety_violation_for_method({:?}, {:?})", trait_def_id, method); // Any method that has a `Self : Sized` requisite is otherwise @@ -415,7 +415,7 @@ fn object_safety_violation_for_method( fn virtual_call_violation_for_method<'tcx>( tcx: TyCtxt<'tcx>, trait_def_id: DefId, - method: &ty::AssocItem, + method: ty::AssocItem, ) -> Option { let sig = tcx.fn_sig(method.def_id).subst_identity(); @@ -718,7 +718,7 @@ fn object_ty_for_trait<'tcx>( #[allow(dead_code)] fn receiver_is_dispatchable<'tcx>( tcx: TyCtxt<'tcx>, - method: &ty::AssocItem, + method: ty::AssocItem, receiver_ty: Ty<'tcx>, ) -> bool { debug!("receiver_is_dispatchable: method = {:?}, receiver_ty = {:?}", method, receiver_ty); diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index a380d4697ea26..0d9ef901f229d 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -2149,7 +2149,7 @@ fn confirm_impl_candidate<'cx, 'tcx>( } else { ty.map_bound(|ty| ty.into()) }; - if !check_substs_compatible(tcx, &assoc_ty.item, substs) { + if !check_substs_compatible(tcx, assoc_ty.item, substs) { let err = tcx.ty_error_with_message( obligation.cause.span, "impl item and trait item have different parameters", @@ -2164,7 +2164,7 @@ fn confirm_impl_candidate<'cx, 'tcx>( // Verify that the trait item and its implementation have compatible substs lists fn check_substs_compatible<'tcx>( tcx: TyCtxt<'tcx>, - assoc_item: &ty::AssocItem, + assoc_item: ty::AssocItem, substs: ty::SubstsRef<'tcx>, ) -> bool { fn check_substs_compatible_inner<'tcx>( @@ -2238,7 +2238,7 @@ fn confirm_impl_trait_in_trait_candidate<'tcx>( leaf_def.defining_node, ); - if !check_substs_compatible(tcx, &leaf_def.item, impl_fn_substs) { + if !check_substs_compatible(tcx, leaf_def.item, impl_fn_substs) { let err = tcx.ty_error_with_message( obligation.cause.span, "impl method and trait method have different parameters", diff --git a/compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs b/compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs index 0f9196de4fb19..2c7856210b09d 100644 --- a/compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs +++ b/compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs @@ -399,7 +399,7 @@ pub(crate) fn assoc_def( // If there is no such item in that impl, this function will fail with a // cycle error if the specialization graph is currently being built. if let Some(&impl_item_id) = tcx.impl_item_implementor_ids(impl_def_id).get(&assoc_def_id) { - let &item = tcx.associated_item(impl_item_id); + let item = tcx.associated_item(impl_item_id); let impl_node = Node::Impl(impl_def_id); return Ok(LeafDef { item, diff --git a/compiler/rustc_trait_selection/src/traits/vtable.rs b/compiler/rustc_trait_selection/src/traits/vtable.rs index 64daca714c32d..9f5c5bbeac8de 100644 --- a/compiler/rustc_trait_selection/src/traits/vtable.rs +++ b/compiler/rustc_trait_selection/src/traits/vtable.rs @@ -197,12 +197,12 @@ fn own_existential_vtable_entries(tcx: TyCtxt<'_>, trait_def_id: DefId) -> &[Def .in_definition_order() .filter(|item| item.kind == ty::AssocKind::Fn); // Now list each method's DefId (for within its trait). - let own_entries = trait_methods.filter_map(move |trait_method| { + let own_entries = trait_methods.filter_map(move |&trait_method| { debug!("own_existential_vtable_entry: trait_method={:?}", trait_method); let def_id = trait_method.def_id; // Some methods cannot be called on an object; skip those. - if !is_vtable_safe_method(tcx, trait_def_id, &trait_method) { + if !is_vtable_safe_method(tcx, trait_def_id, trait_method) { debug!("own_existential_vtable_entry: not vtable safe"); return None; } diff --git a/compiler/rustc_ty_utils/src/assoc.rs b/compiler/rustc_ty_utils/src/assoc.rs index a6e0f13f69830..164cac6a010fa 100644 --- a/compiler/rustc_ty_utils/src/assoc.rs +++ b/compiler/rustc_ty_utils/src/assoc.rs @@ -26,7 +26,7 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] { } } -fn associated_items(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AssocItems<'_> { +fn associated_items(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AssocItems { if tcx.is_trait_alias(def_id) { ty::AssocItems::new(Vec::new()) } else { From dce666b797eeba0294ffd253ff5e473bf9f0c3eb Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 6 Feb 2023 09:02:19 +0000 Subject: [PATCH 3/3] Copy `ty::AssocItem` even in rustdoc --- src/librustdoc/passes/collect_intra_doc_links.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index b2208da9060dc..7f9ef376b141b 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -689,12 +689,12 @@ fn resolve_associated_trait_item<'a>( .find_by_name_and_namespace(cx.tcx, Ident::with_dummy_span(item_name), ns, trait_) .map(|trait_assoc| { trait_assoc_to_impl_assoc_item(cx.tcx, impl_, trait_assoc.def_id) - .unwrap_or(trait_assoc) + .unwrap_or(*trait_assoc) }) }); // FIXME(#74563): warn about ambiguity debug!("the candidates were {:?}", candidates.clone().collect::>()); - candidates.next().copied() + candidates.next() } /// Find the associated item in the impl `impl_id` that corresponds to the @@ -711,7 +711,7 @@ fn trait_assoc_to_impl_assoc_item<'tcx>( tcx: TyCtxt<'tcx>, impl_id: DefId, trait_assoc_id: DefId, -) -> Option<&'tcx ty::AssocItem> { +) -> Option { let trait_to_impl_assoc_map = tcx.impl_item_implementor_ids(impl_id); debug!(?trait_to_impl_assoc_map); let impl_assoc_id = *trait_to_impl_assoc_map.get(&trait_assoc_id)?;