From c84917ad2efe6badd83d2acad64a2ad30ec68ddf Mon Sep 17 00:00:00 2001 From: Kyle Matsuda Date: Tue, 10 Jan 2023 11:53:35 -0700 Subject: [PATCH 1/6] add EarlyBinder::subst_identity; impl ParameterizedOverTcx (needed for rustc_metadata) and Value for EarlyBinder --- compiler/rustc_middle/src/ty/parameterized.rs | 4 ++++ compiler/rustc_middle/src/ty/subst.rs | 4 ++++ compiler/rustc_middle/src/values.rs | 12 ++++++++++++ 3 files changed, 20 insertions(+) diff --git a/compiler/rustc_middle/src/ty/parameterized.rs b/compiler/rustc_middle/src/ty/parameterized.rs index 72f451985796b..e32a7ee1c3545 100644 --- a/compiler/rustc_middle/src/ty/parameterized.rs +++ b/compiler/rustc_middle/src/ty/parameterized.rs @@ -32,6 +32,10 @@ impl ParameterizedOverTcx for ty::Binder<'static, T> { type Value<'tcx> = ty::Binder<'tcx, T::Value<'tcx>>; } +impl ParameterizedOverTcx for ty::EarlyBinder { + type Value<'tcx> = ty::EarlyBinder>; +} + #[macro_export] macro_rules! trivially_parameterized_over_tcx { ($($ty:ty),+ $(,)?) => { diff --git a/compiler/rustc_middle/src/ty/subst.rs b/compiler/rustc_middle/src/ty/subst.rs index 2dec58ea82a30..8f764011d0ac3 100644 --- a/compiler/rustc_middle/src/ty/subst.rs +++ b/compiler/rustc_middle/src/ty/subst.rs @@ -713,6 +713,10 @@ impl<'tcx, T: TypeFoldable<'tcx>> ty::EarlyBinder { let mut folder = SubstFolder { tcx, substs, binders_passed: 0 }; self.0.fold_with(&mut folder) } + + pub fn subst_identity(self) -> T { + self.0 + } } /////////////////////////////////////////////////////////////////////////// diff --git a/compiler/rustc_middle/src/values.rs b/compiler/rustc_middle/src/values.rs index c242be5703123..34e8a559784e6 100644 --- a/compiler/rustc_middle/src/values.rs +++ b/compiler/rustc_middle/src/values.rs @@ -94,6 +94,18 @@ impl<'tcx> Value, DepKind> for Representability { } } +impl<'tcx> Value, DepKind> for ty::EarlyBinder> { + fn from_cycle_error(tcx: TyCtxt<'tcx>, cycle: &[QueryInfo]) -> Self { + ty::EarlyBinder(Ty::from_cycle_error(tcx, cycle)) + } +} + +impl<'tcx> Value, DepKind> for ty::EarlyBinder>> { + fn from_cycle_error(tcx: TyCtxt<'tcx>, cycle: &[QueryInfo]) -> Self { + ty::EarlyBinder(ty::Binder::from_cycle_error(tcx, cycle)) + } +} + // item_and_field_ids should form a cycle where each field contains the // type in the next element in the list pub fn recursive_type_error( From bd6c63597b9483aa65b0934f195716635a30a2b8 Mon Sep 17 00:00:00 2001 From: Kyle Matsuda Date: Tue, 10 Jan 2023 12:20:15 -0700 Subject: [PATCH 2/6] change usages of const_param_default query to bound_const_param_default --- compiler/rustc_hir_analysis/src/check/wfcheck.rs | 4 ++-- compiler/rustc_metadata/src/rmeta/encoder.rs | 2 +- compiler/rustc_privacy/src/lib.rs | 4 +++- src/librustdoc/clean/mod.rs | 4 +++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 92fd4625ee835..cc29d40c0becd 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1350,7 +1350,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id // is incorrect when dealing with unused substs, for example // for `struct Foo` // we should eagerly error. - let default_ct = tcx.const_param_default(param.def_id); + let default_ct = tcx.bound_const_param_default(param.def_id).subst_identity(); if !default_ct.needs_subst() { wfcx.register_wf_obligation( tcx.def_span(param.def_id), @@ -1396,7 +1396,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id GenericParamDefKind::Const { .. } => { // If the param has a default, ... if is_our_default(param) { - let default_ct = tcx.const_param_default(param.def_id); + let default_ct = tcx.bound_const_param_default(param.def_id).subst_identity(); // ... and it's not a dependent default, ... if !default_ct.needs_subst() { // ... then substitute it with the default. diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 030328d1e26ff..f7caf30c74c5c 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -2070,7 +2070,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { hir::GenericParamKind::Const { ref default, .. } => { let def_id = param.def_id.to_def_id(); if default.is_some() { - record!(self.tables.const_param_default[def_id] <- self.tcx.const_param_default(def_id)) + record!(self.tables.const_param_default[def_id] <- self.tcx.bound_const_param_default(def_id).subst_identity()) } } } diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 564cb1baa6909..9ee1e012ef20f 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -838,7 +838,9 @@ impl ReachEverythingInTheInterfaceVisitor<'_, '_> { GenericParamDefKind::Const { has_default } => { self.visit(self.ev.tcx.type_of(param.def_id)); if has_default { - self.visit(self.ev.tcx.const_param_default(param.def_id)); + self.visit( + self.ev.tcx.bound_const_param_default(param.def_id).subst_identity(), + ); } } } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 025a4379f45a3..869c1e3512f40 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -506,7 +506,9 @@ fn clean_generic_param_def<'tcx>( Some(def.def_id), )), default: match has_default { - true => Some(Box::new(cx.tcx.const_param_default(def.def_id).to_string())), + true => Some(Box::new( + cx.tcx.bound_const_param_default(def.def_id).subst_identity().to_string(), + )), false => None, }, }, From ef58baf8b8fecc5ca8b5e34921d33650186d4205 Mon Sep 17 00:00:00 2001 From: Kyle Matsuda Date: Tue, 10 Jan 2023 12:27:41 -0700 Subject: [PATCH 3/6] change const_param_default query to return EarlyBinder; remove bound_const_param_default query; add EarlyBinder to const_param_default in metadata --- compiler/rustc_hir_analysis/src/astconv/mod.rs | 4 +--- compiler/rustc_hir_analysis/src/check/wfcheck.rs | 4 ++-- compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs | 4 +--- compiler/rustc_metadata/src/rmeta/encoder.rs | 2 +- compiler/rustc_metadata/src/rmeta/mod.rs | 2 +- compiler/rustc_middle/src/query/mod.rs | 2 +- compiler/rustc_middle/src/ty/consts.rs | 4 ++-- compiler/rustc_middle/src/ty/generics.rs | 2 +- compiler/rustc_middle/src/ty/util.rs | 4 ---- compiler/rustc_privacy/src/lib.rs | 4 +--- src/librustdoc/clean/mod.rs | 2 +- 11 files changed, 12 insertions(+), 22 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 3521911b05527..d32c288337b59 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -511,9 +511,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { return tcx.const_error(ty).into(); } if !infer_args && has_default { - tcx.bound_const_param_default(param.def_id) - .subst(tcx, substs.unwrap()) - .into() + tcx.const_param_default(param.def_id).subst(tcx, substs.unwrap()).into() } else { if infer_args { self.astconv.ct_infer(ty, Some(param), self.span).into() diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index cc29d40c0becd..7c6da009dee3d 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1350,7 +1350,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id // is incorrect when dealing with unused substs, for example // for `struct Foo` // we should eagerly error. - let default_ct = tcx.bound_const_param_default(param.def_id).subst_identity(); + let default_ct = tcx.const_param_default(param.def_id).subst_identity(); if !default_ct.needs_subst() { wfcx.register_wf_obligation( tcx.def_span(param.def_id), @@ -1396,7 +1396,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id GenericParamDefKind::Const { .. } => { // If the param has a default, ... if is_our_default(param) { - let default_ct = tcx.bound_const_param_default(param.def_id).subst_identity(); + let default_ct = tcx.const_param_default(param.def_id).subst_identity(); // ... and it's not a dependent default, ... if !default_ct.needs_subst() { // ... then substitute it with the default. diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index 8570715b41e59..6ed8adb47425a 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -1224,9 +1224,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } GenericParamDefKind::Const { has_default } => { if !infer_args && has_default { - tcx.bound_const_param_default(param.def_id) - .subst(tcx, substs.unwrap()) - .into() + tcx.const_param_default(param.def_id).subst(tcx, substs.unwrap()).into() } else { self.fcx.var_for_def(self.span, param) } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index f7caf30c74c5c..030328d1e26ff 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -2070,7 +2070,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { hir::GenericParamKind::Const { ref default, .. } => { let def_id = param.def_id.to_def_id(); if default.is_some() { - record!(self.tables.const_param_default[def_id] <- self.tcx.bound_const_param_default(def_id).subst_identity()) + record!(self.tables.const_param_default[def_id] <- self.tcx.const_param_default(def_id)) } } } diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index bf9be714daf7e..5beee06d5211e 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -360,7 +360,7 @@ define_tables! { fn_sig: Table>>, codegen_fn_attrs: Table>, impl_trait_ref: Table>>, - const_param_default: Table>>, + const_param_default: Table>>>, object_lifetime_default: Table>, optimized_mir: Table>>, mir_for_ctfe: Table>>, diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 8665591573695..cdc78a86349f1 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -142,7 +142,7 @@ rustc_queries! { /// Given the def_id of a const-generic parameter, computes the associated default const /// parameter. e.g. `fn example` called on `N` would return `3`. - query const_param_default(param: DefId) -> ty::Const<'tcx> { + query const_param_default(param: DefId) -> ty::EarlyBinder> { desc { |tcx| "computing const default for a given parameter `{}`", tcx.def_path_str(param) } cache_on_disk_if { param.is_local() } separate_provide_extern diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index 152a7e9d43fa4..65cbac3e8f1cd 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -239,7 +239,7 @@ impl<'tcx> Const<'tcx> { } } -pub fn const_param_default(tcx: TyCtxt<'_>, def_id: DefId) -> Const<'_> { +pub fn const_param_default(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder> { let default_def_id = match tcx.hir().get_by_def_id(def_id.expect_local()) { hir::Node::GenericParam(hir::GenericParam { kind: hir::GenericParamKind::Const { default: Some(ac), .. }, @@ -250,5 +250,5 @@ pub fn const_param_default(tcx: TyCtxt<'_>, def_id: DefId) -> Const<'_> { "`const_param_default` expected a generic parameter with a constant" ), }; - Const::from_anon_const(tcx, default_def_id) + ty::EarlyBinder(Const::from_anon_const(tcx, default_def_id)) } diff --git a/compiler/rustc_middle/src/ty/generics.rs b/compiler/rustc_middle/src/ty/generics.rs index 705adecd3b90f..8a5e765b9a306 100644 --- a/compiler/rustc_middle/src/ty/generics.rs +++ b/compiler/rustc_middle/src/ty/generics.rs @@ -88,7 +88,7 @@ impl GenericParamDef { Some(tcx.bound_type_of(self.def_id).map_bound(|t| t.into())) } GenericParamDefKind::Const { has_default } if has_default => { - Some(tcx.bound_const_param_default(self.def_id).map_bound(|c| c.into())) + Some(tcx.const_param_default(self.def_id).map_bound(|c| c.into())) } _ => None, } diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index cc53659f82798..1f0c96a93b97d 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -673,10 +673,6 @@ impl<'tcx> TyCtxt<'tcx> { ty::EarlyBinder(self.item_bounds(def_id)) } - pub fn bound_const_param_default(self, def_id: DefId) -> ty::EarlyBinder> { - ty::EarlyBinder(self.const_param_default(def_id)) - } - pub fn bound_predicates_of( self, def_id: DefId, diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 9ee1e012ef20f..0d6d5ab5a1837 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -838,9 +838,7 @@ impl ReachEverythingInTheInterfaceVisitor<'_, '_> { GenericParamDefKind::Const { has_default } => { self.visit(self.ev.tcx.type_of(param.def_id)); if has_default { - self.visit( - self.ev.tcx.bound_const_param_default(param.def_id).subst_identity(), - ); + self.visit(self.ev.tcx.const_param_default(param.def_id).subst_identity()); } } } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 869c1e3512f40..415e7d5a360d0 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -507,7 +507,7 @@ fn clean_generic_param_def<'tcx>( )), default: match has_default { true => Some(Box::new( - cx.tcx.bound_const_param_default(def.def_id).subst_identity().to_string(), + cx.tcx.const_param_default(def.def_id).subst_identity().to_string(), )), false => None, }, From be130b57d477069799158506d7e80145fdf71c73 Mon Sep 17 00:00:00 2001 From: Kyle Matsuda Date: Tue, 10 Jan 2023 14:22:52 -0700 Subject: [PATCH 4/6] change usages of impl_trait_ref to bound_impl_trait_ref --- compiler/rustc_hir_analysis/src/astconv/mod.rs | 4 ++-- compiler/rustc_hir_analysis/src/check/check.rs | 4 ++-- .../src/check/compare_impl_item.rs | 6 ++++-- .../rustc_hir_analysis/src/check/wfcheck.rs | 7 ++++--- .../src/coherence/builtin.rs | 4 ++-- .../rustc_hir_analysis/src/coherence/mod.rs | 2 +- .../rustc_hir_analysis/src/coherence/orphan.rs | 2 +- .../src/coherence/unsafety.rs | 4 +++- .../src/collect/predicates_of.rs | 6 ++++-- .../rustc_hir_analysis/src/collect/type_of.rs | 2 +- .../rustc_hir_analysis/src/impl_wf_check.rs | 3 ++- .../src/impl_wf_check/min_specialization.rs | 8 ++++---- .../rustc_hir_typeck/src/method/confirm.rs | 2 +- .../rustc_hir_typeck/src/method/suggest.rs | 18 +++++++++++------- .../src/infer/error_reporting/note.rs | 3 ++- compiler/rustc_lint/src/nonstandard_style.rs | 2 +- compiler/rustc_lint/src/pass_by_value.rs | 2 +- compiler/rustc_metadata/src/rmeta/encoder.rs | 12 +++++++++--- compiler/rustc_middle/src/hir/mod.rs | 3 ++- compiler/rustc_middle/src/ty/context.rs | 2 +- compiler/rustc_middle/src/ty/mod.rs | 14 +++++++++----- compiler/rustc_monomorphize/src/collector.rs | 5 ++++- compiler/rustc_passes/src/dead.rs | 6 +++--- compiler/rustc_passes/src/stability.rs | 2 +- compiler/rustc_privacy/src/lib.rs | 8 ++++---- .../src/traits/coherence.rs | 6 +++--- .../src/traits/error_reporting/mod.rs | 5 +++-- .../rustc_trait_selection/src/traits/mod.rs | 6 ++++-- .../src/traits/specialize/mod.rs | 4 ++-- .../traits/specialize/specialization_graph.rs | 12 ++++++------ compiler/rustc_traits/src/chalk/db.rs | 3 ++- compiler/rustc_ty_utils/src/implied_bounds.rs | 16 +++++++++------- compiler/rustc_ty_utils/src/ty.rs | 7 ++++--- src/librustdoc/clean/inline.rs | 2 +- src/librustdoc/clean/types.rs | 2 +- .../passes/collect_intra_doc_links.rs | 4 ++-- src/tools/clippy/clippy_lints/src/derive.rs | 8 ++++---- .../clippy_lints/src/fallible_impl_from.rs | 4 ++-- .../clippy/clippy_lints/src/from_over_into.rs | 2 +- .../src/implicit_saturating_sub.rs | 4 ++-- .../clippy_lints/src/methods/implicit_clone.rs | 2 +- .../src/methods/suspicious_splitn.rs | 2 +- .../clippy/clippy_lints/src/missing_doc.rs | 2 +- .../clippy/clippy_lints/src/missing_inline.rs | 2 +- .../src/non_send_fields_in_send_ty.rs | 4 ++-- .../clippy_lints/src/only_used_in_recursion.rs | 2 +- src/tools/clippy/clippy_lints/src/use_self.rs | 4 ++-- 47 files changed, 134 insertions(+), 100 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index d32c288337b59..28d83eea5ef4d 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -2059,14 +2059,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { (_, Res::SelfTyAlias { alias_to: impl_def_id, is_trait_impl: true, .. }) => { // `Self` in an impl of a trait -- we have a concrete self type and a // trait reference. - let Some(trait_ref) = tcx.impl_trait_ref(impl_def_id) else { + let Some(trait_ref) = tcx.bound_impl_trait_ref(impl_def_id) else { // A cycle error occurred, most likely. let guar = tcx.sess.delay_span_bug(span, "expected cycle error"); return Err(guar); }; self.one_bound_for_assoc_type( - || traits::supertraits(tcx, ty::Binder::dummy(trait_ref)), + || traits::supertraits(tcx, ty::Binder::dummy(trait_ref.skip_binder())), || "Self".to_string(), assoc_ident, span, diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 43795cfba3fd8..0042429c6c435 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -535,12 +535,12 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) { return; }; debug!("ItemKind::Impl {} with id {:?}", it.ident, it.owner_id); - if let Some(impl_trait_ref) = tcx.impl_trait_ref(it.owner_id) { + if let Some(impl_trait_ref) = tcx.bound_impl_trait_ref(it.owner_id.to_def_id()) { check_impl_items_against_trait( tcx, it.span, it.owner_id.def_id, - impl_trait_ref, + impl_trait_ref.skip_binder(), &impl_.items, ); check_on_unimplemented(tcx, it); 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 2cdf75794713f..a420232ecbfd2 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -616,7 +616,8 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>( ) -> Result<&'tcx FxHashMap>, ErrorGuaranteed> { let impl_m = tcx.opt_associated_item(def_id).unwrap(); let trait_m = tcx.opt_associated_item(impl_m.trait_item_def_id.unwrap()).unwrap(); - let impl_trait_ref = tcx.impl_trait_ref(impl_m.impl_container(tcx).unwrap()).unwrap(); + let impl_trait_ref = + tcx.bound_impl_trait_ref(impl_m.impl_container(tcx).unwrap()).unwrap().subst_identity(); let param_env = tcx.param_env(def_id); // First, check a few of the same things as `compare_impl_method`, @@ -1684,7 +1685,8 @@ pub(super) fn compare_impl_const_raw( ) -> Result<(), ErrorGuaranteed> { let impl_const_item = tcx.associated_item(impl_const_item_def); let trait_const_item = tcx.associated_item(trait_const_item_def); - let impl_trait_ref = tcx.impl_trait_ref(impl_const_item.container_id(tcx)).unwrap(); + let impl_trait_ref = + tcx.bound_impl_trait_ref(impl_const_item.container_id(tcx)).unwrap().subst_identity(); debug!("compare_const_impl(impl_trait_ref={:?})", impl_trait_ref); let impl_c_span = tcx.def_span(impl_const_item_def.to_def_id()); diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 7c6da009dee3d..6f85dfa4d91e6 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -181,8 +181,8 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) { // for `T` hir::ItemKind::Impl(ref impl_) => { let is_auto = tcx - .impl_trait_ref(def_id) - .map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.def_id)); + .bound_impl_trait_ref(def_id.into()) + .map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.skip_binder().def_id)); if let (hir::Defaultness::Default { .. }, true) = (impl_.defaultness, is_auto) { let sp = impl_.of_trait.as_ref().map_or(item.span, |t| t.path.span); let mut err = @@ -1253,7 +1253,8 @@ fn check_impl<'tcx>( // `#[rustc_reservation_impl]` impls are not real impls and // therefore don't need to be WF (the trait's `Self: Trait` predicate // won't hold). - let trait_ref = tcx.impl_trait_ref(item.owner_id).unwrap(); + let trait_ref = + tcx.bound_impl_trait_ref(item.owner_id.to_def_id()).unwrap().subst_identity(); let trait_ref = wfcx.normalize( ast_trait_ref.path.span, Some(WellFormedLoc::Ty(item.hir_id().expect_owner().def_id)), diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin.rs b/compiler/rustc_hir_analysis/src/coherence/builtin.rs index 2e2c1591e9b44..28a25780f96f0 100644 --- a/compiler/rustc_hir_analysis/src/coherence/builtin.rs +++ b/compiler/rustc_hir_analysis/src/coherence/builtin.rs @@ -192,7 +192,7 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef let source = tcx.type_of(impl_did); assert!(!source.has_escaping_bound_vars()); let target = { - let trait_ref = tcx.impl_trait_ref(impl_did).unwrap(); + let trait_ref = tcx.bound_impl_trait_ref(impl_did.into()).unwrap().subst_identity(); assert_eq!(trait_ref.def_id, dispatch_from_dyn_trait); trait_ref.substs.type_at(1) @@ -354,7 +354,7 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn }); let source = tcx.type_of(impl_did); - let trait_ref = tcx.impl_trait_ref(impl_did).unwrap(); + let trait_ref = tcx.bound_impl_trait_ref(impl_did.into()).unwrap().subst_identity(); assert_eq!(trait_ref.def_id, coerce_unsized_trait); let target = trait_ref.substs.type_at(1); debug!("visit_implementation_of_coerce_unsized: {:?} -> {:?} (bound)", source, target); diff --git a/compiler/rustc_hir_analysis/src/coherence/mod.rs b/compiler/rustc_hir_analysis/src/coherence/mod.rs index 1bf3768fead36..6bfb5a599149b 100644 --- a/compiler/rustc_hir_analysis/src/coherence/mod.rs +++ b/compiler/rustc_hir_analysis/src/coherence/mod.rs @@ -128,7 +128,7 @@ fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) { let impls = tcx.hir().trait_impls(def_id); for &impl_def_id in impls { - let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap(); + let trait_ref = tcx.bound_impl_trait_ref(impl_def_id.into()).unwrap().subst_identity(); check_impl(tcx, impl_def_id, trait_ref); check_object_overlap(tcx, impl_def_id, trait_ref); diff --git a/compiler/rustc_hir_analysis/src/coherence/orphan.rs b/compiler/rustc_hir_analysis/src/coherence/orphan.rs index e8b3f139623ed..9417901d1fdcf 100644 --- a/compiler/rustc_hir_analysis/src/coherence/orphan.rs +++ b/compiler/rustc_hir_analysis/src/coherence/orphan.rs @@ -21,7 +21,7 @@ pub(crate) fn orphan_check_impl( tcx: TyCtxt<'_>, impl_def_id: LocalDefId, ) -> Result<(), ErrorGuaranteed> { - let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap(); + let trait_ref = tcx.bound_impl_trait_ref(impl_def_id.into()).unwrap().skip_binder(); trait_ref.error_reported()?; let ret = do_orphan_check_impl(tcx, trait_ref, impl_def_id); diff --git a/compiler/rustc_hir_analysis/src/coherence/unsafety.rs b/compiler/rustc_hir_analysis/src/coherence/unsafety.rs index 70cc15b2f8c54..8db68067c69cb 100644 --- a/compiler/rustc_hir_analysis/src/coherence/unsafety.rs +++ b/compiler/rustc_hir_analysis/src/coherence/unsafety.rs @@ -13,7 +13,9 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) { let item = tcx.hir().expect_item(def_id); let hir::ItemKind::Impl(ref impl_) = item.kind else { bug!() }; - if let Some(trait_ref) = tcx.impl_trait_ref(item.owner_id) { + if let Some(trait_ref) = + tcx.bound_impl_trait_ref(item.owner_id.to_def_id()).map(|t| t.subst_identity()) + { let trait_def = tcx.trait_def(trait_ref.def_id); let unsafe_attr = impl_.generics.params.iter().find(|p| p.pure_wrt_drop).map(|_| "may_dangle"); diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index 234253556845b..a44d9a6bddde2 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -87,7 +87,9 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP Node::Item(item) => match item.kind { ItemKind::Impl(ref impl_) => { if impl_.defaultness.is_default() { - is_default_impl_trait = tcx.impl_trait_ref(def_id).map(ty::Binder::dummy); + is_default_impl_trait = tcx + .bound_impl_trait_ref(def_id) + .map(|t| ty::Binder::dummy(t.subst_identity())); } &impl_.generics } @@ -251,7 +253,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP // for details. if let Node::Item(&Item { kind: ItemKind::Impl { .. }, .. }) = node { let self_ty = tcx.type_of(def_id); - let trait_ref = tcx.impl_trait_ref(def_id); + let trait_ref = tcx.bound_impl_trait_ref(def_id).map(ty::EarlyBinder::subst_identity); cgp::setup_constraining_predicates( tcx, &mut predicates, diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index 1f9a9f80302e3..f845fa2ca5f09 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -286,7 +286,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { } } ImplItemKind::Type(ty) => { - if tcx.impl_trait_ref(tcx.hir().get_parent_item(hir_id)).is_none() { + if tcx.bound_impl_trait_ref(tcx.hir().get_parent_item(hir_id).to_def_id()).is_none() { check_feature_inherent_assoc_ty(tcx, item.span); } diff --git a/compiler/rustc_hir_analysis/src/impl_wf_check.rs b/compiler/rustc_hir_analysis/src/impl_wf_check.rs index 136f6199911a0..208f146ebbf61 100644 --- a/compiler/rustc_hir_analysis/src/impl_wf_check.rs +++ b/compiler/rustc_hir_analysis/src/impl_wf_check.rs @@ -85,7 +85,8 @@ fn enforce_impl_params_are_constrained(tcx: TyCtxt<'_>, impl_def_id: LocalDefId) } let impl_generics = tcx.generics_of(impl_def_id); let impl_predicates = tcx.predicates_of(impl_def_id); - let impl_trait_ref = tcx.impl_trait_ref(impl_def_id); + let impl_trait_ref = + tcx.bound_impl_trait_ref(impl_def_id.into()).map(ty::EarlyBinder::subst_identity); let mut input_parameters = cgp::parameters_for_impl(impl_self_ty, impl_trait_ref); cgp::identify_constrained_generic_params( diff --git a/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs b/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs index 8b9034d9620e2..ab40fa57acf38 100644 --- a/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs +++ b/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs @@ -89,8 +89,8 @@ pub(super) fn check_min_specialization(tcx: TyCtxt<'_>, impl_def_id: LocalDefId) } fn parent_specialization_node(tcx: TyCtxt<'_>, impl1_def_id: LocalDefId) -> Option { - let trait_ref = tcx.impl_trait_ref(impl1_def_id)?; - let trait_def = tcx.trait_def(trait_ref.def_id); + let trait_ref = tcx.bound_impl_trait_ref(impl1_def_id.into())?; + let trait_def = tcx.trait_def(trait_ref.skip_binder().def_id); let impl2_node = trait_def.ancestors(tcx, impl1_def_id.to_def_id()).ok()?.nth(1)?; @@ -207,7 +207,7 @@ fn unconstrained_parent_impl_substs<'tcx>( let impl_generic_predicates = tcx.predicates_of(impl_def_id); let mut unconstrained_parameters = FxHashSet::default(); let mut constrained_params = FxHashSet::default(); - let impl_trait_ref = tcx.impl_trait_ref(impl_def_id); + let impl_trait_ref = tcx.bound_impl_trait_ref(impl_def_id).map(ty::EarlyBinder::subst_identity); // Unfortunately the functions in `constrained_generic_parameters` don't do // what we want here. We want only a list of constrained parameters while @@ -370,7 +370,7 @@ fn check_predicates<'tcx>( }); // Include the well-formed predicates of the type parameters of the impl. - for arg in tcx.impl_trait_ref(impl1_def_id).unwrap().substs { + for arg in tcx.bound_impl_trait_ref(impl1_def_id.into()).unwrap().subst_identity().substs { let infcx = &tcx.infer_ctxt().build(); let obligations = wf::obligations( infcx, diff --git a/compiler/rustc_hir_typeck/src/method/confirm.rs b/compiler/rustc_hir_typeck/src/method/confirm.rs index 4a33a791e1b7f..1a5a2ec7823b2 100644 --- a/compiler/rustc_hir_typeck/src/method/confirm.rs +++ b/compiler/rustc_hir_typeck/src/method/confirm.rs @@ -240,7 +240,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { probe::InherentImplPick => { let impl_def_id = pick.item.container_id(self.tcx); assert!( - self.tcx.impl_trait_ref(impl_def_id).is_none(), + self.tcx.bound_impl_trait_ref(impl_def_id).is_none(), "impl {:?} is not an inherent impl", impl_def_id ); diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 8166eb8299041..109ceb8956b41 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -1036,8 +1036,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Provide the best span we can. Use the item, if local to crate, else // the impl, if local to crate (item may be defaulted), else nothing. let Some(item) = self.associated_value(impl_did, item_name).or_else(|| { - let impl_trait_ref = self.tcx.impl_trait_ref(impl_did)?; - self.associated_value(impl_trait_ref.def_id, item_name) + let impl_trait_ref = self.tcx.bound_impl_trait_ref(impl_did)?; + self.associated_value(impl_trait_ref.skip_binder().def_id, item_name) }) else { continue; }; @@ -1052,10 +1052,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let impl_ty = self.tcx.at(span).type_of(impl_did); - let insertion = match self.tcx.impl_trait_ref(impl_did) { + let insertion = match self.tcx.bound_impl_trait_ref(impl_did) { None => String::new(), Some(trait_ref) => { - format!(" of the trait `{}`", self.tcx.def_path_str(trait_ref.def_id)) + format!( + " of the trait `{}`", + self.tcx.def_path_str(trait_ref.skip_binder().def_id) + ) } }; @@ -1085,8 +1088,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { err.note(¬e_str); } if let Some(sugg_span) = sugg_span - && let Some(trait_ref) = self.tcx.impl_trait_ref(impl_did) { - let path = self.tcx.def_path_str(trait_ref.def_id); + && let Some(trait_ref) = self.tcx.bound_impl_trait_ref(impl_did) { + let path = self.tcx.def_path_str(trait_ref.skip_binder().def_id); let ty = match item.kind { ty::AssocKind::Const | ty::AssocKind::Type => rcvr_ty, @@ -2581,7 +2584,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.tcx.impl_polarity(*imp_did) == ty::ImplPolarity::Negative }) .any(|imp_did| { - let imp = self.tcx.impl_trait_ref(imp_did).unwrap(); + let imp = + self.tcx.bound_impl_trait_ref(imp_did).unwrap().subst_identity(); let imp_simp = simplify_type(self.tcx, imp.self_ty(), TreatParams::AsPlaceholder); imp_simp.map_or(false, |s| s == simp_rcvr_ty) diff --git a/compiler/rustc_infer/src/infer/error_reporting/note.rs b/compiler/rustc_infer/src/infer/error_reporting/note.rs index 7504ed094a3d4..2670eb0d1455d 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/note.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/note.rs @@ -317,9 +317,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { self.tcx.associated_item(impl_item_def_id).impl_container(self.tcx) else { return; }; let Some(trait_ref) = self .tcx - .impl_trait_ref(impl_def_id) + .bound_impl_trait_ref(impl_def_id) else { return; }; let trait_substs = trait_ref + .subst_identity() // Replace the explicit self type with `Self` for better suggestion rendering .with_self_ty(self.tcx, self.tcx.mk_ty_param(0, kw::SelfUpper)) .substs; diff --git a/compiler/rustc_lint/src/nonstandard_style.rs b/compiler/rustc_lint/src/nonstandard_style.rs index 74d234fabea08..18a040ab8b187 100644 --- a/compiler/rustc_lint/src/nonstandard_style.rs +++ b/compiler/rustc_lint/src/nonstandard_style.rs @@ -26,7 +26,7 @@ pub fn method_context(cx: &LateContext<'_>, id: hir::HirId) -> MethodLateContext let item = cx.tcx.associated_item(def_id); match item.container { ty::TraitContainer => MethodLateContext::TraitAutoImpl, - ty::ImplContainer => match cx.tcx.impl_trait_ref(item.container_id(cx.tcx)) { + ty::ImplContainer => match cx.tcx.bound_impl_trait_ref(item.container_id(cx.tcx)) { Some(_) => MethodLateContext::TraitImpl, None => MethodLateContext::PlainImpl, }, diff --git a/compiler/rustc_lint/src/pass_by_value.rs b/compiler/rustc_lint/src/pass_by_value.rs index 57482a9edba88..212b8aa1574df 100644 --- a/compiler/rustc_lint/src/pass_by_value.rs +++ b/compiler/rustc_lint/src/pass_by_value.rs @@ -24,7 +24,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByValue { match &ty.kind { TyKind::Ref(_, hir::MutTy { ty: inner_ty, mutbl: hir::Mutability::Not }) => { if let Some(impl_did) = cx.tcx.impl_of_method(ty.hir_id.owner.to_def_id()) { - if cx.tcx.impl_trait_ref(impl_did).is_some() { + if cx.tcx.bound_impl_trait_ref(impl_did).is_some() { return; } } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 030328d1e26ff..3504a3bde4507 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1555,7 +1555,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { self.tables.impl_defaultness.set(def_id.index, *defaultness); self.tables.constness.set(def_id.index, *constness); - let trait_ref = self.tcx.impl_trait_ref(def_id); + let trait_ref = + self.tcx.bound_impl_trait_ref(def_id).map(ty::EarlyBinder::skip_binder); if let Some(trait_ref) = trait_ref { let trait_def = self.tcx.trait_def(trait_ref.def_id); if let Ok(mut an) = trait_def.ancestors(self.tcx, def_id) { @@ -1632,7 +1633,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { } } if let hir::ItemKind::Impl { .. } = item.kind { - if let Some(trait_ref) = self.tcx.impl_trait_ref(def_id) { + if let Some(trait_ref) = + self.tcx.bound_impl_trait_ref(def_id).map(ty::EarlyBinder::subst_identity) + { record!(self.tables.impl_trait_ref[def_id] <- trait_ref); } } @@ -1898,7 +1901,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { for id in tcx.hir().items() { if matches!(tcx.def_kind(id.owner_id), DefKind::Impl) { - if let Some(trait_ref) = tcx.impl_trait_ref(id.owner_id) { + if let Some(trait_ref) = tcx + .bound_impl_trait_ref(id.owner_id.to_def_id()) + .map(ty::EarlyBinder::subst_identity) + { let simplified_self_ty = fast_reject::simplify_type( self.tcx, trait_ref.self_ty(), diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index a633201e3d9ae..e43e584b0b0d4 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -101,7 +101,8 @@ impl<'tcx> TyCtxt<'tcx> { } pub fn impl_subject(self, def_id: DefId) -> ImplSubject<'tcx> { - self.impl_trait_ref(def_id) + self.bound_impl_trait_ref(def_id) + .map(|t| t.subst_identity()) .map(ImplSubject::Trait) .unwrap_or_else(|| ImplSubject::Inherent(self.type_of(def_id))) } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 63f31e5a11f39..6270c2ebb28fb 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1027,7 +1027,7 @@ impl<'tcx> TyCtxt<'tcx> { /// Checks if the bound region is in Impl Item. pub fn is_bound_region_in_impl_item(self, suitable_region_binding_scope: LocalDefId) -> bool { let container_id = self.parent(suitable_region_binding_scope.to_def_id()); - if self.impl_trait_ref(container_id).is_some() { + if self.bound_impl_trait_ref(container_id).is_some() { // For now, we do not try to target impls of traits. This is // because this message is going to suggest that the user // change the fn signature, but they may not be free to do so, diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 993e95b351484..ac762b9dfb27b 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -2187,8 +2187,12 @@ impl<'tcx> TyCtxt<'tcx> { ) -> Option { // If either trait impl references an error, they're allowed to overlap, // as one of them essentially doesn't exist. - if self.impl_trait_ref(def_id1).map_or(false, |tr| tr.references_error()) - || self.impl_trait_ref(def_id2).map_or(false, |tr| tr.references_error()) + if self + .bound_impl_trait_ref(def_id1) + .map_or(false, |tr| tr.skip_binder().references_error()) + || self + .bound_impl_trait_ref(def_id2) + .map_or(false, |tr| tr.skip_binder().references_error()) { return Some(ImplOverlapKind::Permitted { marker: false }); } @@ -2217,8 +2221,8 @@ impl<'tcx> TyCtxt<'tcx> { let is_marker_overlap = { let is_marker_impl = |def_id: DefId| -> bool { - let trait_ref = self.impl_trait_ref(def_id); - trait_ref.map_or(false, |tr| self.trait_def(tr.def_id).is_marker) + let trait_ref = self.bound_impl_trait_ref(def_id); + trait_ref.map_or(false, |tr| self.trait_def(tr.skip_binder().def_id).is_marker) }; is_marker_impl(def_id1) && is_marker_impl(def_id2) }; @@ -2364,7 +2368,7 @@ impl<'tcx> TyCtxt<'tcx> { /// Given the `DefId` of an impl, returns the `DefId` of the trait it implements. /// If it implements no trait, returns `None`. pub fn trait_id_of_impl(self, def_id: DefId) -> Option { - self.impl_trait_ref(def_id).map(|tr| tr.def_id) + self.bound_impl_trait_ref(def_id).map(|tr| tr.skip_binder().def_id) } /// If the given `DefId` describes an item belonging to a trait, diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index b573df4325051..070947410f38b 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -1351,7 +1351,10 @@ fn create_mono_items_for_default_impls<'tcx>( tcx.def_path_str(item.owner_id.to_def_id()) ); - if let Some(trait_ref) = tcx.impl_trait_ref(item.owner_id) { + if let Some(trait_ref) = tcx + .bound_impl_trait_ref(item.owner_id.to_def_id()) + .map(ty::EarlyBinder::subst_identity) + { let param_env = ty::ParamEnv::reveal_all(); let trait_ref = tcx.normalize_erasing_regions(param_env, trait_ref); let overridden_methods = tcx.impl_item_implementor_ids(item.owner_id); diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index edb0e4367f273..88ad7b28f544e 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -266,7 +266,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> { if let Some(trait_of) = self.tcx.trait_id_of_impl(impl_of) && self.tcx.has_attr(trait_of, sym::rustc_trivial_field_reads) { - let trait_ref = self.tcx.impl_trait_ref(impl_of).unwrap(); + let trait_ref = self.tcx.bound_impl_trait_ref(impl_of).unwrap().subst_identity(); if let ty::Adt(adt_def, _) = trait_ref.self_ty().kind() && let Some(adt_def_id) = adt_def.did().as_local() { @@ -310,7 +310,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> { } Node::ImplItem(impl_item) => { let item = self.tcx.local_parent(impl_item.owner_id.def_id); - if self.tcx.impl_trait_ref(item).is_none() { + if self.tcx.bound_impl_trait_ref(item.into()).is_none() { //// If it's a type whose items are live, then it's live, too. //// This is done to handle the case where, for example, the static //// method of a private type is used, but the type itself is never @@ -534,7 +534,7 @@ fn check_item<'tcx>( } } DefKind::Impl => { - let of_trait = tcx.impl_trait_ref(id.owner_id); + let of_trait = tcx.bound_impl_trait_ref(id.owner_id.to_def_id()); if of_trait.is_some() { worklist.push(id.owner_id.def_id); diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 96f7236de5cb1..3ecc9faf76620 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -593,7 +593,7 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> { fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem<'tcx>) { let impl_def_id = self.tcx.hir().get_parent_item(ii.hir_id()); - if self.tcx.impl_trait_ref(impl_def_id).is_none() { + if self.tcx.bound_impl_trait_ref(impl_def_id.to_def_id()).is_none() { self.check_missing_stability(ii.owner_id.def_id, ii.span); self.check_missing_const_stability(ii.owner_id.def_id, ii.span); } diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 0d6d5ab5a1837..69bfa8e2709af 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -337,8 +337,8 @@ trait VisibilityLike: Sized { ) -> Self { let mut find = FindMin { tcx, effective_visibilities, min: Self::MAX }; find.visit(tcx.type_of(def_id)); - if let Some(trait_ref) = tcx.impl_trait_ref(def_id) { - find.visit_trait(trait_ref); + if let Some(trait_ref) = tcx.bound_impl_trait_ref(def_id.into()) { + find.visit_trait(trait_ref.subst_identity()); } find.min } @@ -857,8 +857,8 @@ impl ReachEverythingInTheInterfaceVisitor<'_, '_> { } fn trait_ref(&mut self) -> &mut Self { - if let Some(trait_ref) = self.ev.tcx.impl_trait_ref(self.item_def_id) { - self.visit_trait(trait_ref); + if let Some(trait_ref) = self.ev.tcx.bound_impl_trait_ref(self.item_def_id.into()) { + self.visit_trait(trait_ref.subst_identity()); } self } diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 258d2e2d28c9d..623ef7964bf0d 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -77,8 +77,8 @@ pub fn overlapping_impls( // a quick check via fast_reject to tell if the impl headers could possibly // unify. let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsInfer }; - let impl1_ref = tcx.impl_trait_ref(impl1_def_id); - let impl2_ref = tcx.impl_trait_ref(impl2_def_id); + let impl1_ref = tcx.bound_impl_trait_ref(impl1_def_id).map(ty::EarlyBinder::subst_identity); + let impl2_ref = tcx.bound_impl_trait_ref(impl2_def_id).map(ty::EarlyBinder::subst_identity); let may_overlap = match (impl1_ref, impl2_ref) { (Some(a), Some(b)) => iter::zip(a.substs, b.substs) .all(|(arg1, arg2)| drcx.generic_args_may_unify(arg1, arg2)), @@ -461,7 +461,7 @@ pub fn orphan_check(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Result<(), OrphanChe // We only except this routine to be invoked on implementations // of a trait, not inherent implementations. - let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap(); + let trait_ref = tcx.bound_impl_trait_ref(impl_def_id).unwrap().skip_binder(); debug!("orphan_check: trait_ref={:?}", trait_ref); // If the *trait* is local to the crate, ok. diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 0c7ffb056cc02..8b9c6821dafec 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -1940,7 +1940,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { return None; } - let imp = self.tcx.impl_trait_ref(def_id).unwrap(); + let imp = self.tcx.bound_impl_trait_ref(def_id).unwrap().subst_identity(); self.fuzzy_match_tys(trait_pred.skip_binder().self_ty(), imp.self_ty(), false) .map(|similarity| ImplCandidate { trait_ref: imp, similarity }) @@ -2039,7 +2039,8 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { self.tcx.impl_polarity(def_id) != ty::ImplPolarity::Negative || self.tcx.is_builtin_derive(def_id) }) - .filter_map(|def_id| self.tcx.impl_trait_ref(def_id)) + .filter_map(|def_id| self.tcx.bound_impl_trait_ref(def_id)) + .map(ty::EarlyBinder::subst_identity) .filter(|trait_ref| { let self_ty = trait_ref.self_ty(); // Avoid mentioning type parameters. diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 37b40a2f75adc..4c34dc64c26cc 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -521,8 +521,10 @@ fn is_impossible_method(tcx: TyCtxt<'_>, (impl_def_id, trait_item_def_id): (DefI let generics = tcx.generics_of(trait_item_def_id); let predicates = tcx.predicates_of(trait_item_def_id); - let impl_trait_ref = - tcx.impl_trait_ref(impl_def_id).expect("expected impl to correspond to trait"); + let impl_trait_ref = tcx + .bound_impl_trait_ref(impl_def_id) + .expect("expected impl to correspond to trait") + .subst_identity(); let param_env = tcx.param_env(impl_def_id); let mut visitor = ReferencesOnlyParentGenerics { tcx, generics, trait_item_def_id }; diff --git a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs index a251a508b48cf..a352a65fb068f 100644 --- a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs @@ -148,7 +148,7 @@ pub(super) fn specializes(tcx: TyCtxt<'_>, (impl1_def_id, impl2_def_id): (DefId, // create a parameter environment corresponding to a (placeholder) instantiation of impl1 let penv = tcx.param_env(impl1_def_id); - let impl1_trait_ref = tcx.impl_trait_ref(impl1_def_id).unwrap(); + let impl1_trait_ref = tcx.bound_impl_trait_ref(impl1_def_id).unwrap().subst_identity(); // Create an infcx, taking the predicates of impl1 as assumptions: let infcx = tcx.infer_ctxt().build(); @@ -431,7 +431,7 @@ fn report_conflicting_impls<'tcx>( pub(crate) fn to_pretty_impl_header(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Option { use std::fmt::Write; - let trait_ref = tcx.impl_trait_ref(impl_def_id)?; + let trait_ref = tcx.bound_impl_trait_ref(impl_def_id)?.skip_binder(); let mut w = "impl".to_owned(); let substs = InternalSubsts::identity_for_item(tcx, impl_def_id); 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 02b0667774028..a2e39c53d15c8 100644 --- a/compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs +++ b/compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs @@ -48,7 +48,7 @@ trait ChildrenExt<'tcx> { impl<'tcx> ChildrenExt<'tcx> for Children { /// Insert an impl into this set of children without comparing to any existing impls. fn insert_blindly(&mut self, tcx: TyCtxt<'tcx>, impl_def_id: DefId) { - let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap(); + let trait_ref = tcx.bound_impl_trait_ref(impl_def_id).unwrap().subst_identity(); if let Some(st) = fast_reject::simplify_type(tcx, trait_ref.self_ty(), TreatParams::AsInfer) { debug!("insert_blindly: impl_def_id={:?} st={:?}", impl_def_id, st); @@ -63,7 +63,7 @@ impl<'tcx> ChildrenExt<'tcx> for Children { /// an impl with a parent. The impl must be present in the list of /// children already. fn remove_existing(&mut self, tcx: TyCtxt<'tcx>, impl_def_id: DefId) { - let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap(); + let trait_ref = tcx.bound_impl_trait_ref(impl_def_id).unwrap().subst_identity(); let vec: &mut Vec; if let Some(st) = fast_reject::simplify_type(tcx, trait_ref.self_ty(), TreatParams::AsInfer) { @@ -181,7 +181,7 @@ impl<'tcx> ChildrenExt<'tcx> for Children { if le && !ge { debug!( "descending as child of TraitRef {:?}", - tcx.impl_trait_ref(possible_sibling).unwrap() + tcx.bound_impl_trait_ref(possible_sibling).unwrap().subst_identity() ); // The impl specializes `possible_sibling`. @@ -189,7 +189,7 @@ impl<'tcx> ChildrenExt<'tcx> for Children { } else if ge && !le { debug!( "placing as parent of TraitRef {:?}", - tcx.impl_trait_ref(possible_sibling).unwrap() + tcx.bound_impl_trait_ref(possible_sibling).unwrap().subst_identity() ); replace_children.push(possible_sibling); @@ -275,7 +275,7 @@ impl<'tcx> GraphExt<'tcx> for Graph { ) -> Result>, OverlapError<'tcx>> { assert!(impl_def_id.is_local()); - let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap(); + let trait_ref = tcx.bound_impl_trait_ref(impl_def_id).unwrap().subst_identity(); let trait_def_id = trait_ref.def_id; debug!( @@ -388,7 +388,7 @@ pub(crate) fn assoc_def( impl_def_id: DefId, assoc_def_id: DefId, ) -> Result { - let trait_def_id = tcx.impl_trait_ref(impl_def_id).unwrap().def_id; + let trait_def_id = tcx.bound_impl_trait_ref(impl_def_id).unwrap().skip_binder().def_id; let trait_def = tcx.trait_def(trait_def_id); // This function may be called while we are still building the diff --git a/compiler/rustc_traits/src/chalk/db.rs b/compiler/rustc_traits/src/chalk/db.rs index f288eb112582d..dea33f896cf17 100644 --- a/compiler/rustc_traits/src/chalk/db.rs +++ b/compiler/rustc_traits/src/chalk/db.rs @@ -380,7 +380,8 @@ impl<'tcx> chalk_solve::RustIrDatabase> for RustIrDatabase<'t let trait_def_id = auto_trait_id.0; let all_impls = self.interner.tcx.all_impls(trait_def_id); for impl_def_id in all_impls { - let trait_ref = self.interner.tcx.impl_trait_ref(impl_def_id).unwrap(); + let trait_ref = + self.interner.tcx.bound_impl_trait_ref(impl_def_id).unwrap().subst_identity(); let self_ty = trait_ref.self_ty(); let provides = match (self_ty.kind(), chalk_ty) { (&ty::Adt(impl_adt_def, ..), Adt(id, ..)) => impl_adt_def.did() == id.0.did(), diff --git a/compiler/rustc_ty_utils/src/implied_bounds.rs b/compiler/rustc_ty_utils/src/implied_bounds.rs index b7a24a22c53e3..d890a04599b1c 100644 --- a/compiler/rustc_ty_utils/src/implied_bounds.rs +++ b/compiler/rustc_ty_utils/src/implied_bounds.rs @@ -21,14 +21,16 @@ fn assumed_wf_types(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List> { assumed_wf_types.extend(liberated_sig.inputs_and_output); tcx.intern_type_list(&assumed_wf_types) } - DefKind::Impl => match tcx.impl_trait_ref(def_id) { - Some(trait_ref) => { - let types: Vec<_> = trait_ref.substs.types().collect(); - tcx.intern_type_list(&types) + DefKind::Impl => { + match tcx.bound_impl_trait_ref(def_id).map(ty::EarlyBinder::subst_identity) { + Some(trait_ref) => { + let types: Vec<_> = trait_ref.substs.types().collect(); + tcx.intern_type_list(&types) + } + // Only the impl self type + None => tcx.intern_type_list(&[tcx.type_of(def_id)]), } - // Only the impl self type - None => tcx.intern_type_list(&[tcx.type_of(def_id)]), - }, + } DefKind::AssocConst | DefKind::AssocTy => tcx.assumed_wf_types(tcx.parent(def_id)), DefKind::Mod | DefKind::Struct diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index 87923ebbe4bc9..78c3a208e889f 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -289,7 +289,7 @@ fn well_formed_types_in_env(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List { - let trait_ref = tcx.impl_trait_ref(def_id).expect("not an impl"); + let trait_ref = tcx.bound_impl_trait_ref(def_id).expect("not an impl").subst_identity(); // FIXME(chalk): this has problems because of late-bound regions //inputs.extend(trait_ref.substs.iter().flat_map(|arg| arg.walk())); @@ -359,8 +359,9 @@ fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option> { debug!("issue33140_self_ty({:?})", def_id); let trait_ref = tcx - .impl_trait_ref(def_id) - .unwrap_or_else(|| bug!("issue33140_self_ty called on inherent impl {:?}", def_id)); + .bound_impl_trait_ref(def_id) + .unwrap_or_else(|| bug!("issue33140_self_ty called on inherent impl {:?}", def_id)) + .skip_binder(); debug!("issue33140_self_ty({:?}), trait-ref={:?}", def_id, trait_ref); diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index aad24b4a07492..23330daa54bf0 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -376,7 +376,7 @@ pub(crate) fn build_impl( let _prof_timer = cx.tcx.sess.prof.generic_activity("build_impl"); let tcx = cx.tcx; - let associated_trait = tcx.impl_trait_ref(did); + let associated_trait = tcx.bound_impl_trait_ref(did).map(ty::EarlyBinder::skip_binder); // Only inline impl if the implemented trait is // reachable in rustdoc generated documentation diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 87de41fde63c5..cda90955ba116 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -734,7 +734,7 @@ impl Item { ty::ImplContainer => { // Trait impl items always inherit the impl's visibility -- // we don't want to show `pub`. - tcx.impl_trait_ref(tcx.parent(assoc_item.def_id)).is_some() + tcx.bound_impl_trait_ref(tcx.parent(assoc_item.def_id)).is_some() } }; if is_trait_item { diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 4f0eb8b8076e5..fa9174287e272 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -784,9 +784,9 @@ fn trait_impls_for<'a>( // Look at each trait implementation to see if it's an impl for `did` tcx.find_map_relevant_impl(trait_, ty, |impl_| { - let trait_ref = tcx.impl_trait_ref(impl_).expect("this is not an inherent impl"); + let trait_ref = tcx.bound_impl_trait_ref(impl_).expect("this is not an inherent impl"); // Check if these are the same type. - let impl_type = trait_ref.self_ty(); + let impl_type = trait_ref.subst_identity().self_ty(); trace!( "comparing type {} with kind {:?} against type {:?}", impl_type, diff --git a/src/tools/clippy/clippy_lints/src/derive.rs b/src/tools/clippy/clippy_lints/src/derive.rs index f4b15e0916dbf..6b2b18fff76e0 100644 --- a/src/tools/clippy/clippy_lints/src/derive.rs +++ b/src/tools/clippy/clippy_lints/src/derive.rs @@ -247,11 +247,11 @@ fn check_hash_peq<'tcx>( return; } - let trait_ref = cx.tcx.impl_trait_ref(impl_id).expect("must be a trait implementation"); + let trait_ref = cx.tcx.bound_impl_trait_ref(impl_id).expect("must be a trait implementation"); // Only care about `impl PartialEq for Foo` // For `impl PartialEq for A, input_types is [A, B] - if trait_ref.substs.type_at(1) == ty { + if trait_ref.subst_identity().substs.type_at(1) == ty { span_lint_and_then( cx, DERIVED_HASH_WITH_MANUAL_EQ, @@ -295,11 +295,11 @@ fn check_ord_partial_ord<'tcx>( return; } - let trait_ref = cx.tcx.impl_trait_ref(impl_id).expect("must be a trait implementation"); + let trait_ref = cx.tcx.bound_impl_trait_ref(impl_id).expect("must be a trait implementation"); // Only care about `impl PartialOrd for Foo` // For `impl PartialOrd for A, input_types is [A, B] - if trait_ref.substs.type_at(1) == ty { + if trait_ref.subst_identity().substs.type_at(1) == ty { let mess = if partial_ord_is_automatically_derived { "you are implementing `Ord` explicitly but have derived `PartialOrd`" } else { diff --git a/src/tools/clippy/clippy_lints/src/fallible_impl_from.rs b/src/tools/clippy/clippy_lints/src/fallible_impl_from.rs index 9a1058470e18e..a8085122ccf95 100644 --- a/src/tools/clippy/clippy_lints/src/fallible_impl_from.rs +++ b/src/tools/clippy/clippy_lints/src/fallible_impl_from.rs @@ -55,8 +55,8 @@ impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom { // check for `impl From for ..` if_chain! { if let hir::ItemKind::Impl(impl_) = &item.kind; - if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id); - if cx.tcx.is_diagnostic_item(sym::From, impl_trait_ref.def_id); + if let Some(impl_trait_ref) = cx.tcx.bound_impl_trait_ref(item.owner_id.to_def_id()); + if cx.tcx.is_diagnostic_item(sym::From, impl_trait_ref.skip_binder().def_id); then { lint_impl_body(cx, item.span, impl_.items); } diff --git a/src/tools/clippy/clippy_lints/src/from_over_into.rs b/src/tools/clippy/clippy_lints/src/from_over_into.rs index a92f7548ff254..97d414bfa95e4 100644 --- a/src/tools/clippy/clippy_lints/src/from_over_into.rs +++ b/src/tools/clippy/clippy_lints/src/from_over_into.rs @@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto { && let Some(into_trait_seg) = hir_trait_ref.path.segments.last() // `impl Into for self_ty` && let Some(GenericArgs { args: [GenericArg::Type(target_ty)], .. }) = into_trait_seg.args - && let Some(middle_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id) + && let Some(middle_trait_ref) = cx.tcx.bound_impl_trait_ref(item.owner_id.to_def_id()).map(ty::EarlyBinder::subst_identity) && cx.tcx.is_diagnostic_item(sym::Into, middle_trait_ref.def_id) && !matches!(middle_trait_ref.substs.type_at(1).kind(), ty::Alias(ty::Opaque, _)) { diff --git a/src/tools/clippy/clippy_lints/src/implicit_saturating_sub.rs b/src/tools/clippy/clippy_lints/src/implicit_saturating_sub.rs index 29d59c26d92c4..37e33529a9a60 100644 --- a/src/tools/clippy/clippy_lints/src/implicit_saturating_sub.rs +++ b/src/tools/clippy/clippy_lints/src/implicit_saturating_sub.rs @@ -101,7 +101,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub { if name.ident.as_str() == "MIN"; if let Some(const_id) = cx.typeck_results().type_dependent_def_id(cond_num_val.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(const_id); - if let None = cx.tcx.impl_trait_ref(impl_id); // An inherent impl + if let None = cx.tcx.bound_impl_trait_ref(impl_id); // An inherent impl if cx.tcx.type_of(impl_id).is_integral(); then { print_lint_and_sugg(cx, var_name, expr) @@ -114,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub { if name.ident.as_str() == "min_value"; if let Some(func_id) = cx.typeck_results().type_dependent_def_id(func.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(func_id); - if let None = cx.tcx.impl_trait_ref(impl_id); // An inherent impl + if let None = cx.tcx.bound_impl_trait_ref(impl_id); // An inherent impl if cx.tcx.type_of(impl_id).is_integral(); then { print_lint_and_sugg(cx, var_name, expr) diff --git a/src/tools/clippy/clippy_lints/src/methods/implicit_clone.rs b/src/tools/clippy/clippy_lints/src/methods/implicit_clone.rs index 06ecbce4e70e9..16a25a98800de 100644 --- a/src/tools/clippy/clippy_lints/src/methods/implicit_clone.rs +++ b/src/tools/clippy/clippy_lints/src/methods/implicit_clone.rs @@ -53,7 +53,7 @@ pub fn is_clone_like(cx: &LateContext<'_>, method_name: &str, method_def_id: hir "to_vec" => cx .tcx .impl_of_method(method_def_id) - .filter(|&impl_did| cx.tcx.type_of(impl_did).is_slice() && cx.tcx.impl_trait_ref(impl_did).is_none()) + .filter(|&impl_did| cx.tcx.type_of(impl_did).is_slice() && cx.tcx.bound_impl_trait_ref(impl_did).is_none()) .is_some(), _ => false, } diff --git a/src/tools/clippy/clippy_lints/src/methods/suspicious_splitn.rs b/src/tools/clippy/clippy_lints/src/methods/suspicious_splitn.rs index 219a9edd65768..dba0663467b7d 100644 --- a/src/tools/clippy/clippy_lints/src/methods/suspicious_splitn.rs +++ b/src/tools/clippy/clippy_lints/src/methods/suspicious_splitn.rs @@ -12,7 +12,7 @@ pub(super) fn check(cx: &LateContext<'_>, method_name: &str, expr: &Expr<'_>, se if count <= 1; if let Some(call_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(call_id); - if cx.tcx.impl_trait_ref(impl_id).is_none(); + if cx.tcx.bound_impl_trait_ref(impl_id).is_none(); let self_ty = cx.tcx.type_of(impl_id); if self_ty.is_slice() || self_ty.is_str(); then { diff --git a/src/tools/clippy/clippy_lints/src/missing_doc.rs b/src/tools/clippy/clippy_lints/src/missing_doc.rs index 6fd100762b49d..d0c99b352452f 100644 --- a/src/tools/clippy/clippy_lints/src/missing_doc.rs +++ b/src/tools/clippy/clippy_lints/src/missing_doc.rs @@ -175,7 +175,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) { // If the method is an impl for a trait, don't doc. if let Some(cid) = cx.tcx.associated_item(impl_item.owner_id).impl_container(cx.tcx) { - if cx.tcx.impl_trait_ref(cid).is_some() { + if cx.tcx.bound_impl_trait_ref(cid).is_some() { return; } } else { diff --git a/src/tools/clippy/clippy_lints/src/missing_inline.rs b/src/tools/clippy/clippy_lints/src/missing_inline.rs index 758ce47cf114b..0594fb175458d 100644 --- a/src/tools/clippy/clippy_lints/src/missing_inline.rs +++ b/src/tools/clippy/clippy_lints/src/missing_inline.rs @@ -155,7 +155,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { let container_id = assoc_item.container_id(cx.tcx); let trait_def_id = match assoc_item.container { TraitContainer => Some(container_id), - ImplContainer => cx.tcx.impl_trait_ref(container_id).map(|t| t.def_id), + ImplContainer => cx.tcx.bound_impl_trait_ref(container_id).map(|t| t.skip_binder().def_id), }; if let Some(trait_def_id) = trait_def_id { diff --git a/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs b/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs index 714c0ff227bf8..9c112ade948ff 100644 --- a/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs +++ b/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs @@ -89,8 +89,8 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy { if let Some(trait_id) = trait_ref.trait_def_id(); if send_trait == trait_id; if hir_impl.polarity == ImplPolarity::Positive; - if let Some(ty_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id); - if let self_ty = ty_trait_ref.self_ty(); + if let Some(ty_trait_ref) = cx.tcx.bound_impl_trait_ref(item.owner_id.to_def_id()); + if let self_ty = ty_trait_ref.subst_identity().self_ty(); if let ty::Adt(adt_def, impl_trait_substs) = self_ty.kind(); then { let mut non_send_fields = Vec::new(); diff --git a/src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs b/src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs index 7722a476d7b4e..82b1716a216e6 100644 --- a/src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs +++ b/src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs @@ -244,7 +244,7 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion { })) => { #[allow(trivial_casts)] if let Some(Node::Item(item)) = get_parent_node(cx.tcx, owner_id.into()) - && let Some(trait_ref) = cx.tcx.impl_trait_ref(item.owner_id) + && let Some(trait_ref) = cx.tcx.bound_impl_trait_ref(item.owner_id.to_def_id()).map(|t| t.subst_identity()) && let Some(trait_item_id) = cx.tcx.associated_item(owner_id).trait_item_def_id { ( diff --git a/src/tools/clippy/clippy_lints/src/use_self.rs b/src/tools/clippy/clippy_lints/src/use_self.rs index 4c755d812a0e0..9f31a13aa984b 100644 --- a/src/tools/clippy/clippy_lints/src/use_self.rs +++ b/src/tools/clippy/clippy_lints/src/use_self.rs @@ -133,11 +133,11 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { ref mut types_to_skip, .. }) = self.stack.last_mut(); - if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_id); + if let Some(impl_trait_ref) = cx.tcx.bound_impl_trait_ref(impl_id.to_def_id()); then { // `self_ty` is the semantic self type of `impl for `. This cannot be // `Self`. - let self_ty = impl_trait_ref.self_ty(); + let self_ty = impl_trait_ref.subst_identity().self_ty(); // `trait_method_sig` is the signature of the function, how it is declared in the // trait, not in the impl of the trait. From f29a334c90e29ffbe236f9abba9aa08bfda597c6 Mon Sep 17 00:00:00 2001 From: Kyle Matsuda Date: Tue, 10 Jan 2023 14:57:22 -0700 Subject: [PATCH 5/6] change impl_trait_ref query to return EarlyBinder; remove bound_impl_trait_ref query; add EarlyBinder to impl_trait_ref in metadata --- .../rustc_hir_analysis/src/astconv/mod.rs | 6 ++--- .../rustc_hir_analysis/src/check/check.rs | 2 +- .../src/check/compare_impl_item.rs | 4 ++-- .../rustc_hir_analysis/src/check/wfcheck.rs | 5 ++--- .../src/coherence/builtin.rs | 4 ++-- .../rustc_hir_analysis/src/coherence/mod.rs | 2 +- .../src/coherence/orphan.rs | 2 +- .../src/coherence/unsafety.rs | 4 +--- compiler/rustc_hir_analysis/src/collect.rs | 22 +++++++++++-------- .../src/collect/predicates_of.rs | 7 +++--- .../rustc_hir_analysis/src/collect/type_of.rs | 2 +- .../rustc_hir_analysis/src/impl_wf_check.rs | 3 +-- .../src/impl_wf_check/min_specialization.rs | 6 ++--- .../rustc_hir_typeck/src/method/confirm.rs | 2 +- .../rustc_hir_typeck/src/method/suggest.rs | 9 ++++---- .../src/infer/error_reporting/note.rs | 2 +- compiler/rustc_lint/src/nonstandard_style.rs | 2 +- compiler/rustc_lint/src/pass_by_value.rs | 2 +- compiler/rustc_metadata/src/rmeta/encoder.rs | 12 ++++------ compiler/rustc_metadata/src/rmeta/mod.rs | 2 +- compiler/rustc_middle/src/hir/mod.rs | 2 +- compiler/rustc_middle/src/query/mod.rs | 2 +- compiler/rustc_middle/src/ty/context.rs | 2 +- compiler/rustc_middle/src/ty/mod.rs | 12 ++++------ compiler/rustc_middle/src/ty/print/mod.rs | 2 +- compiler/rustc_middle/src/ty/util.rs | 7 ------ compiler/rustc_monomorphize/src/collector.rs | 5 ++--- compiler/rustc_passes/src/dead.rs | 6 ++--- compiler/rustc_passes/src/stability.rs | 2 +- compiler/rustc_privacy/src/lib.rs | 4 ++-- .../src/solve/project_goals.rs | 2 +- .../src/solve/trait_goals.rs | 2 +- .../src/traits/coherence.rs | 8 +++---- .../src/traits/error_reporting/ambiguity.rs | 2 +- .../src/traits/error_reporting/mod.rs | 4 ++-- .../error_reporting/on_unimplemented.rs | 2 +- .../rustc_trait_selection/src/traits/mod.rs | 2 +- .../src/traits/select/candidate_assembly.rs | 2 +- .../src/traits/select/mod.rs | 2 +- .../src/traits/specialize/mod.rs | 6 ++--- .../traits/specialize/specialization_graph.rs | 12 +++++----- compiler/rustc_traits/src/chalk/db.rs | 7 +++--- compiler/rustc_ty_utils/src/implied_bounds.rs | 2 +- compiler/rustc_ty_utils/src/ty.rs | 4 ++-- src/librustdoc/clean/blanket_impl.rs | 2 +- src/librustdoc/clean/inline.rs | 2 +- src/librustdoc/clean/types.rs | 2 +- .../passes/collect_intra_doc_links.rs | 2 +- src/tools/clippy/clippy_lints/src/derive.rs | 4 ++-- .../clippy_lints/src/fallible_impl_from.rs | 2 +- .../clippy/clippy_lints/src/from_over_into.rs | 2 +- .../src/implicit_saturating_sub.rs | 4 ++-- .../src/methods/implicit_clone.rs | 2 +- .../src/methods/suspicious_splitn.rs | 2 +- .../clippy/clippy_lints/src/missing_doc.rs | 2 +- .../clippy/clippy_lints/src/missing_inline.rs | 2 +- .../src/non_send_fields_in_send_ty.rs | 2 +- .../src/only_used_in_recursion.rs | 2 +- src/tools/clippy/clippy_lints/src/use_self.rs | 2 +- 59 files changed, 108 insertions(+), 127 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 28d83eea5ef4d..7567a02d1454e 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -2059,7 +2059,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { (_, Res::SelfTyAlias { alias_to: impl_def_id, is_trait_impl: true, .. }) => { // `Self` in an impl of a trait -- we have a concrete self type and a // trait reference. - let Some(trait_ref) = tcx.bound_impl_trait_ref(impl_def_id) else { + let Some(trait_ref) = tcx.impl_trait_ref(impl_def_id) else { // A cycle error occurred, most likely. let guar = tcx.sess.delay_span_bug(span, "expected cycle error"); return Err(guar); @@ -2155,7 +2155,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { .is_accessible_from(self.item_def_id(), tcx) && tcx.all_impls(*trait_def_id) .any(|impl_def_id| { - let trait_ref = tcx.bound_impl_trait_ref(impl_def_id); + let trait_ref = tcx.impl_trait_ref(impl_def_id); trait_ref.map_or(false, |trait_ref| { let impl_ = trait_ref.subst( tcx, @@ -2308,7 +2308,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { && tcx.impl_polarity(impl_def_id) != ty::ImplPolarity::Negative }) .filter_map(|impl_def_id| tcx.impl_trait_ref(impl_def_id)) - .map(|impl_| impl_.self_ty()) + .map(|impl_| impl_.subst_identity().self_ty()) // We don't care about blanket impls. .filter(|self_ty| !self_ty.has_non_region_param()) .map(|self_ty| tcx.erase_regions(self_ty).to_string()) diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 0042429c6c435..7df19ba6d36bf 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -535,7 +535,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) { return; }; debug!("ItemKind::Impl {} with id {:?}", it.ident, it.owner_id); - if let Some(impl_trait_ref) = tcx.bound_impl_trait_ref(it.owner_id.to_def_id()) { + if let Some(impl_trait_ref) = tcx.impl_trait_ref(it.owner_id) { check_impl_items_against_trait( tcx, it.span, 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 a420232ecbfd2..770d7b6f927e4 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -617,7 +617,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>( let impl_m = tcx.opt_associated_item(def_id).unwrap(); let trait_m = tcx.opt_associated_item(impl_m.trait_item_def_id.unwrap()).unwrap(); let impl_trait_ref = - tcx.bound_impl_trait_ref(impl_m.impl_container(tcx).unwrap()).unwrap().subst_identity(); + tcx.impl_trait_ref(impl_m.impl_container(tcx).unwrap()).unwrap().subst_identity(); let param_env = tcx.param_env(def_id); // First, check a few of the same things as `compare_impl_method`, @@ -1686,7 +1686,7 @@ pub(super) fn compare_impl_const_raw( let impl_const_item = tcx.associated_item(impl_const_item_def); let trait_const_item = tcx.associated_item(trait_const_item_def); let impl_trait_ref = - tcx.bound_impl_trait_ref(impl_const_item.container_id(tcx)).unwrap().subst_identity(); + tcx.impl_trait_ref(impl_const_item.container_id(tcx)).unwrap().subst_identity(); debug!("compare_const_impl(impl_trait_ref={:?})", impl_trait_ref); let impl_c_span = tcx.def_span(impl_const_item_def.to_def_id()); diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 6f85dfa4d91e6..912e0ec560b49 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -181,7 +181,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) { // for `T` hir::ItemKind::Impl(ref impl_) => { let is_auto = tcx - .bound_impl_trait_ref(def_id.into()) + .impl_trait_ref(def_id) .map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.skip_binder().def_id)); if let (hir::Defaultness::Default { .. }, true) = (impl_.defaultness, is_auto) { let sp = impl_.of_trait.as_ref().map_or(item.span, |t| t.path.span); @@ -1253,8 +1253,7 @@ fn check_impl<'tcx>( // `#[rustc_reservation_impl]` impls are not real impls and // therefore don't need to be WF (the trait's `Self: Trait` predicate // won't hold). - let trait_ref = - tcx.bound_impl_trait_ref(item.owner_id.to_def_id()).unwrap().subst_identity(); + let trait_ref = tcx.impl_trait_ref(item.owner_id).unwrap().subst_identity(); let trait_ref = wfcx.normalize( ast_trait_ref.path.span, Some(WellFormedLoc::Ty(item.hir_id().expect_owner().def_id)), diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin.rs b/compiler/rustc_hir_analysis/src/coherence/builtin.rs index 28a25780f96f0..5bdd18fcd637c 100644 --- a/compiler/rustc_hir_analysis/src/coherence/builtin.rs +++ b/compiler/rustc_hir_analysis/src/coherence/builtin.rs @@ -192,7 +192,7 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef let source = tcx.type_of(impl_did); assert!(!source.has_escaping_bound_vars()); let target = { - let trait_ref = tcx.bound_impl_trait_ref(impl_did.into()).unwrap().subst_identity(); + let trait_ref = tcx.impl_trait_ref(impl_did).unwrap().subst_identity(); assert_eq!(trait_ref.def_id, dispatch_from_dyn_trait); trait_ref.substs.type_at(1) @@ -354,7 +354,7 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn }); let source = tcx.type_of(impl_did); - let trait_ref = tcx.bound_impl_trait_ref(impl_did.into()).unwrap().subst_identity(); + let trait_ref = tcx.impl_trait_ref(impl_did).unwrap().subst_identity(); assert_eq!(trait_ref.def_id, coerce_unsized_trait); let target = trait_ref.substs.type_at(1); debug!("visit_implementation_of_coerce_unsized: {:?} -> {:?} (bound)", source, target); diff --git a/compiler/rustc_hir_analysis/src/coherence/mod.rs b/compiler/rustc_hir_analysis/src/coherence/mod.rs index 6bfb5a599149b..2e9cd2fca01c1 100644 --- a/compiler/rustc_hir_analysis/src/coherence/mod.rs +++ b/compiler/rustc_hir_analysis/src/coherence/mod.rs @@ -128,7 +128,7 @@ fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) { let impls = tcx.hir().trait_impls(def_id); for &impl_def_id in impls { - let trait_ref = tcx.bound_impl_trait_ref(impl_def_id.into()).unwrap().subst_identity(); + let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().subst_identity(); check_impl(tcx, impl_def_id, trait_ref); check_object_overlap(tcx, impl_def_id, trait_ref); diff --git a/compiler/rustc_hir_analysis/src/coherence/orphan.rs b/compiler/rustc_hir_analysis/src/coherence/orphan.rs index 9417901d1fdcf..e8fe92814576e 100644 --- a/compiler/rustc_hir_analysis/src/coherence/orphan.rs +++ b/compiler/rustc_hir_analysis/src/coherence/orphan.rs @@ -21,7 +21,7 @@ pub(crate) fn orphan_check_impl( tcx: TyCtxt<'_>, impl_def_id: LocalDefId, ) -> Result<(), ErrorGuaranteed> { - let trait_ref = tcx.bound_impl_trait_ref(impl_def_id.into()).unwrap().skip_binder(); + let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().skip_binder(); trait_ref.error_reported()?; let ret = do_orphan_check_impl(tcx, trait_ref, impl_def_id); diff --git a/compiler/rustc_hir_analysis/src/coherence/unsafety.rs b/compiler/rustc_hir_analysis/src/coherence/unsafety.rs index 8db68067c69cb..c7693cab47412 100644 --- a/compiler/rustc_hir_analysis/src/coherence/unsafety.rs +++ b/compiler/rustc_hir_analysis/src/coherence/unsafety.rs @@ -13,9 +13,7 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) { let item = tcx.hir().expect_item(def_id); let hir::ItemKind::Impl(ref impl_) = item.kind else { bug!() }; - if let Some(trait_ref) = - tcx.bound_impl_trait_ref(item.owner_id.to_def_id()).map(|t| t.subst_identity()) - { + if let Some(trait_ref) = tcx.impl_trait_ref(item.owner_id).map(|t| t.subst_identity()) { let trait_def = tcx.trait_def(trait_ref.def_id); let unsafe_attr = impl_.generics.params.iter().find(|p| p.pure_wrt_drop).map(|_| "may_dangle"); diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index cd745ee8cab69..35f47dfc1a5e2 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -1339,18 +1339,22 @@ fn suggest_impl_trait<'tcx>( None } -fn impl_trait_ref(tcx: TyCtxt<'_>, def_id: DefId) -> Option> { +fn impl_trait_ref(tcx: TyCtxt<'_>, def_id: DefId) -> Option>> { let icx = ItemCtxt::new(tcx, def_id); let item = tcx.hir().expect_item(def_id.expect_local()); match item.kind { - hir::ItemKind::Impl(ref impl_) => impl_.of_trait.as_ref().map(|ast_trait_ref| { - let selfty = tcx.type_of(def_id); - icx.astconv().instantiate_mono_trait_ref( - ast_trait_ref, - selfty, - check_impl_constness(tcx, impl_.constness, ast_trait_ref), - ) - }), + hir::ItemKind::Impl(ref impl_) => impl_ + .of_trait + .as_ref() + .map(|ast_trait_ref| { + let selfty = tcx.type_of(def_id); + icx.astconv().instantiate_mono_trait_ref( + ast_trait_ref, + selfty, + check_impl_constness(tcx, impl_.constness, ast_trait_ref), + ) + }) + .map(ty::EarlyBinder), _ => bug!(), } } diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index a44d9a6bddde2..a7e6494c15adb 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -87,9 +87,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP Node::Item(item) => match item.kind { ItemKind::Impl(ref impl_) => { if impl_.defaultness.is_default() { - is_default_impl_trait = tcx - .bound_impl_trait_ref(def_id) - .map(|t| ty::Binder::dummy(t.subst_identity())); + is_default_impl_trait = + tcx.impl_trait_ref(def_id).map(|t| ty::Binder::dummy(t.subst_identity())); } &impl_.generics } @@ -253,7 +252,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP // for details. if let Node::Item(&Item { kind: ItemKind::Impl { .. }, .. }) = node { let self_ty = tcx.type_of(def_id); - let trait_ref = tcx.bound_impl_trait_ref(def_id).map(ty::EarlyBinder::subst_identity); + let trait_ref = tcx.impl_trait_ref(def_id).map(ty::EarlyBinder::subst_identity); cgp::setup_constraining_predicates( tcx, &mut predicates, diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index f845fa2ca5f09..1f9a9f80302e3 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -286,7 +286,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { } } ImplItemKind::Type(ty) => { - if tcx.bound_impl_trait_ref(tcx.hir().get_parent_item(hir_id).to_def_id()).is_none() { + if tcx.impl_trait_ref(tcx.hir().get_parent_item(hir_id)).is_none() { check_feature_inherent_assoc_ty(tcx, item.span); } diff --git a/compiler/rustc_hir_analysis/src/impl_wf_check.rs b/compiler/rustc_hir_analysis/src/impl_wf_check.rs index 208f146ebbf61..4fe893442b9bd 100644 --- a/compiler/rustc_hir_analysis/src/impl_wf_check.rs +++ b/compiler/rustc_hir_analysis/src/impl_wf_check.rs @@ -85,8 +85,7 @@ fn enforce_impl_params_are_constrained(tcx: TyCtxt<'_>, impl_def_id: LocalDefId) } let impl_generics = tcx.generics_of(impl_def_id); let impl_predicates = tcx.predicates_of(impl_def_id); - let impl_trait_ref = - tcx.bound_impl_trait_ref(impl_def_id.into()).map(ty::EarlyBinder::subst_identity); + let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).map(ty::EarlyBinder::subst_identity); let mut input_parameters = cgp::parameters_for_impl(impl_self_ty, impl_trait_ref); cgp::identify_constrained_generic_params( diff --git a/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs b/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs index ab40fa57acf38..bcda26c4cc854 100644 --- a/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs +++ b/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs @@ -89,7 +89,7 @@ pub(super) fn check_min_specialization(tcx: TyCtxt<'_>, impl_def_id: LocalDefId) } fn parent_specialization_node(tcx: TyCtxt<'_>, impl1_def_id: LocalDefId) -> Option { - let trait_ref = tcx.bound_impl_trait_ref(impl1_def_id.into())?; + let trait_ref = tcx.impl_trait_ref(impl1_def_id)?; let trait_def = tcx.trait_def(trait_ref.skip_binder().def_id); let impl2_node = trait_def.ancestors(tcx, impl1_def_id.to_def_id()).ok()?.nth(1)?; @@ -207,7 +207,7 @@ fn unconstrained_parent_impl_substs<'tcx>( let impl_generic_predicates = tcx.predicates_of(impl_def_id); let mut unconstrained_parameters = FxHashSet::default(); let mut constrained_params = FxHashSet::default(); - let impl_trait_ref = tcx.bound_impl_trait_ref(impl_def_id).map(ty::EarlyBinder::subst_identity); + let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).map(ty::EarlyBinder::subst_identity); // Unfortunately the functions in `constrained_generic_parameters` don't do // what we want here. We want only a list of constrained parameters while @@ -370,7 +370,7 @@ fn check_predicates<'tcx>( }); // Include the well-formed predicates of the type parameters of the impl. - for arg in tcx.bound_impl_trait_ref(impl1_def_id.into()).unwrap().subst_identity().substs { + for arg in tcx.impl_trait_ref(impl1_def_id).unwrap().subst_identity().substs { let infcx = &tcx.infer_ctxt().build(); let obligations = wf::obligations( infcx, diff --git a/compiler/rustc_hir_typeck/src/method/confirm.rs b/compiler/rustc_hir_typeck/src/method/confirm.rs index 1a5a2ec7823b2..4a33a791e1b7f 100644 --- a/compiler/rustc_hir_typeck/src/method/confirm.rs +++ b/compiler/rustc_hir_typeck/src/method/confirm.rs @@ -240,7 +240,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { probe::InherentImplPick => { let impl_def_id = pick.item.container_id(self.tcx); assert!( - self.tcx.bound_impl_trait_ref(impl_def_id).is_none(), + self.tcx.impl_trait_ref(impl_def_id).is_none(), "impl {:?} is not an inherent impl", impl_def_id ); diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 109ceb8956b41..723d489ec46f8 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -1036,7 +1036,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Provide the best span we can. Use the item, if local to crate, else // the impl, if local to crate (item may be defaulted), else nothing. let Some(item) = self.associated_value(impl_did, item_name).or_else(|| { - let impl_trait_ref = self.tcx.bound_impl_trait_ref(impl_did)?; + let impl_trait_ref = self.tcx.impl_trait_ref(impl_did)?; self.associated_value(impl_trait_ref.skip_binder().def_id, item_name) }) else { continue; @@ -1052,7 +1052,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let impl_ty = self.tcx.at(span).type_of(impl_did); - let insertion = match self.tcx.bound_impl_trait_ref(impl_did) { + let insertion = match self.tcx.impl_trait_ref(impl_did) { None => String::new(), Some(trait_ref) => { format!( @@ -1088,7 +1088,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { err.note(¬e_str); } if let Some(sugg_span) = sugg_span - && let Some(trait_ref) = self.tcx.bound_impl_trait_ref(impl_did) { + && let Some(trait_ref) = self.tcx.impl_trait_ref(impl_did) { let path = self.tcx.def_path_str(trait_ref.skip_binder().def_id); let ty = match item.kind { @@ -2584,8 +2584,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.tcx.impl_polarity(*imp_did) == ty::ImplPolarity::Negative }) .any(|imp_did| { - let imp = - self.tcx.bound_impl_trait_ref(imp_did).unwrap().subst_identity(); + let imp = self.tcx.impl_trait_ref(imp_did).unwrap().subst_identity(); let imp_simp = simplify_type(self.tcx, imp.self_ty(), TreatParams::AsPlaceholder); imp_simp.map_or(false, |s| s == simp_rcvr_ty) diff --git a/compiler/rustc_infer/src/infer/error_reporting/note.rs b/compiler/rustc_infer/src/infer/error_reporting/note.rs index 2670eb0d1455d..021e741ee2f71 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/note.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/note.rs @@ -317,7 +317,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { self.tcx.associated_item(impl_item_def_id).impl_container(self.tcx) else { return; }; let Some(trait_ref) = self .tcx - .bound_impl_trait_ref(impl_def_id) + .impl_trait_ref(impl_def_id) else { return; }; let trait_substs = trait_ref .subst_identity() diff --git a/compiler/rustc_lint/src/nonstandard_style.rs b/compiler/rustc_lint/src/nonstandard_style.rs index 18a040ab8b187..74d234fabea08 100644 --- a/compiler/rustc_lint/src/nonstandard_style.rs +++ b/compiler/rustc_lint/src/nonstandard_style.rs @@ -26,7 +26,7 @@ pub fn method_context(cx: &LateContext<'_>, id: hir::HirId) -> MethodLateContext let item = cx.tcx.associated_item(def_id); match item.container { ty::TraitContainer => MethodLateContext::TraitAutoImpl, - ty::ImplContainer => match cx.tcx.bound_impl_trait_ref(item.container_id(cx.tcx)) { + ty::ImplContainer => match cx.tcx.impl_trait_ref(item.container_id(cx.tcx)) { Some(_) => MethodLateContext::TraitImpl, None => MethodLateContext::PlainImpl, }, diff --git a/compiler/rustc_lint/src/pass_by_value.rs b/compiler/rustc_lint/src/pass_by_value.rs index 212b8aa1574df..57482a9edba88 100644 --- a/compiler/rustc_lint/src/pass_by_value.rs +++ b/compiler/rustc_lint/src/pass_by_value.rs @@ -24,7 +24,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByValue { match &ty.kind { TyKind::Ref(_, hir::MutTy { ty: inner_ty, mutbl: hir::Mutability::Not }) => { if let Some(impl_did) = cx.tcx.impl_of_method(ty.hir_id.owner.to_def_id()) { - if cx.tcx.bound_impl_trait_ref(impl_did).is_some() { + if cx.tcx.impl_trait_ref(impl_did).is_some() { return; } } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 3504a3bde4507..ba856a11890e5 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1555,8 +1555,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { self.tables.impl_defaultness.set(def_id.index, *defaultness); self.tables.constness.set(def_id.index, *constness); - let trait_ref = - self.tcx.bound_impl_trait_ref(def_id).map(ty::EarlyBinder::skip_binder); + let trait_ref = self.tcx.impl_trait_ref(def_id).map(ty::EarlyBinder::skip_binder); if let Some(trait_ref) = trait_ref { let trait_def = self.tcx.trait_def(trait_ref.def_id); if let Ok(mut an) = trait_def.ancestors(self.tcx, def_id) { @@ -1633,9 +1632,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { } } if let hir::ItemKind::Impl { .. } = item.kind { - if let Some(trait_ref) = - self.tcx.bound_impl_trait_ref(def_id).map(ty::EarlyBinder::subst_identity) - { + if let Some(trait_ref) = self.tcx.impl_trait_ref(def_id) { record!(self.tables.impl_trait_ref[def_id] <- trait_ref); } } @@ -1901,9 +1898,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { for id in tcx.hir().items() { if matches!(tcx.def_kind(id.owner_id), DefKind::Impl) { - if let Some(trait_ref) = tcx - .bound_impl_trait_ref(id.owner_id.to_def_id()) - .map(ty::EarlyBinder::subst_identity) + if let Some(trait_ref) = + tcx.impl_trait_ref(id.owner_id).map(ty::EarlyBinder::subst_identity) { let simplified_self_ty = fast_reject::simplify_type( self.tcx, diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 5beee06d5211e..5b7b096b4edf1 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -359,7 +359,7 @@ define_tables! { variances_of: Table>, fn_sig: Table>>, codegen_fn_attrs: Table>, - impl_trait_ref: Table>>, + impl_trait_ref: Table>>>, const_param_default: Table>>>, object_lifetime_default: Table>, optimized_mir: Table>>, diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index e43e584b0b0d4..f567eaf967724 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -101,7 +101,7 @@ impl<'tcx> TyCtxt<'tcx> { } pub fn impl_subject(self, def_id: DefId) -> ImplSubject<'tcx> { - self.bound_impl_trait_ref(def_id) + self.impl_trait_ref(def_id) .map(|t| t.subst_identity()) .map(ImplSubject::Trait) .unwrap_or_else(|| ImplSubject::Inherent(self.type_of(def_id))) diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index cdc78a86349f1..b3acf815e0c10 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -737,7 +737,7 @@ rustc_queries! { /// Given an `impl_id`, return the trait it implements. /// Return `None` if this is an inherent impl. - query impl_trait_ref(impl_id: DefId) -> Option> { + query impl_trait_ref(impl_id: DefId) -> Option>> { desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) } cache_on_disk_if { impl_id.is_local() } separate_provide_extern diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 6270c2ebb28fb..63f31e5a11f39 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1027,7 +1027,7 @@ impl<'tcx> TyCtxt<'tcx> { /// Checks if the bound region is in Impl Item. pub fn is_bound_region_in_impl_item(self, suitable_region_binding_scope: LocalDefId) -> bool { let container_id = self.parent(suitable_region_binding_scope.to_def_id()); - if self.bound_impl_trait_ref(container_id).is_some() { + if self.impl_trait_ref(container_id).is_some() { // For now, we do not try to target impls of traits. This is // because this message is going to suggest that the user // change the fn signature, but they may not be free to do so, diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index ac762b9dfb27b..7cc4ad4ca46cd 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -2187,12 +2187,8 @@ impl<'tcx> TyCtxt<'tcx> { ) -> Option { // If either trait impl references an error, they're allowed to overlap, // as one of them essentially doesn't exist. - if self - .bound_impl_trait_ref(def_id1) - .map_or(false, |tr| tr.skip_binder().references_error()) - || self - .bound_impl_trait_ref(def_id2) - .map_or(false, |tr| tr.skip_binder().references_error()) + if self.impl_trait_ref(def_id1).map_or(false, |tr| tr.skip_binder().references_error()) + || self.impl_trait_ref(def_id2).map_or(false, |tr| tr.skip_binder().references_error()) { return Some(ImplOverlapKind::Permitted { marker: false }); } @@ -2221,7 +2217,7 @@ impl<'tcx> TyCtxt<'tcx> { let is_marker_overlap = { let is_marker_impl = |def_id: DefId| -> bool { - let trait_ref = self.bound_impl_trait_ref(def_id); + let trait_ref = self.impl_trait_ref(def_id); trait_ref.map_or(false, |tr| self.trait_def(tr.skip_binder().def_id).is_marker) }; is_marker_impl(def_id1) && is_marker_impl(def_id2) @@ -2368,7 +2364,7 @@ impl<'tcx> TyCtxt<'tcx> { /// Given the `DefId` of an impl, returns the `DefId` of the trait it implements. /// If it implements no trait, returns `None`. pub fn trait_id_of_impl(self, def_id: DefId) -> Option { - self.bound_impl_trait_ref(def_id).map(|tr| tr.skip_binder().def_id) + self.impl_trait_ref(def_id).map(|tr| tr.skip_binder().def_id) } /// If the given `DefId` describes an item belonging to a trait, diff --git a/compiler/rustc_middle/src/ty/print/mod.rs b/compiler/rustc_middle/src/ty/print/mod.rs index 29bad33e4bc0f..c302c461195aa 100644 --- a/compiler/rustc_middle/src/ty/print/mod.rs +++ b/compiler/rustc_middle/src/ty/print/mod.rs @@ -116,7 +116,7 @@ pub trait Printer<'tcx>: Sized { DefPathData::Impl => { let generics = self.tcx().generics_of(def_id); let self_ty = self.tcx().bound_type_of(def_id); - let impl_trait_ref = self.tcx().bound_impl_trait_ref(def_id); + let impl_trait_ref = self.tcx().impl_trait_ref(def_id); let (self_ty, impl_trait_ref) = if substs.len() >= generics.count() { ( self_ty.subst(self.tcx(), substs), diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 1f0c96a93b97d..1286a5253c068 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -652,13 +652,6 @@ impl<'tcx> TyCtxt<'tcx> { ty::EarlyBinder(self.fn_sig(def_id)) } - pub fn bound_impl_trait_ref( - self, - def_id: DefId, - ) -> Option>> { - self.impl_trait_ref(def_id).map(|i| ty::EarlyBinder(i)) - } - pub fn bound_explicit_item_bounds( self, def_id: DefId, diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 070947410f38b..3080248d50824 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -1351,9 +1351,8 @@ fn create_mono_items_for_default_impls<'tcx>( tcx.def_path_str(item.owner_id.to_def_id()) ); - if let Some(trait_ref) = tcx - .bound_impl_trait_ref(item.owner_id.to_def_id()) - .map(ty::EarlyBinder::subst_identity) + if let Some(trait_ref) = + tcx.impl_trait_ref(item.owner_id).map(ty::EarlyBinder::subst_identity) { let param_env = ty::ParamEnv::reveal_all(); let trait_ref = tcx.normalize_erasing_regions(param_env, trait_ref); diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index 88ad7b28f544e..94171b4b0c8f1 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -266,7 +266,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> { if let Some(trait_of) = self.tcx.trait_id_of_impl(impl_of) && self.tcx.has_attr(trait_of, sym::rustc_trivial_field_reads) { - let trait_ref = self.tcx.bound_impl_trait_ref(impl_of).unwrap().subst_identity(); + let trait_ref = self.tcx.impl_trait_ref(impl_of).unwrap().subst_identity(); if let ty::Adt(adt_def, _) = trait_ref.self_ty().kind() && let Some(adt_def_id) = adt_def.did().as_local() { @@ -310,7 +310,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> { } Node::ImplItem(impl_item) => { let item = self.tcx.local_parent(impl_item.owner_id.def_id); - if self.tcx.bound_impl_trait_ref(item.into()).is_none() { + if self.tcx.impl_trait_ref(item).is_none() { //// If it's a type whose items are live, then it's live, too. //// This is done to handle the case where, for example, the static //// method of a private type is used, but the type itself is never @@ -534,7 +534,7 @@ fn check_item<'tcx>( } } DefKind::Impl => { - let of_trait = tcx.bound_impl_trait_ref(id.owner_id.to_def_id()); + let of_trait = tcx.impl_trait_ref(id.owner_id); if of_trait.is_some() { worklist.push(id.owner_id.def_id); diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 3ecc9faf76620..96f7236de5cb1 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -593,7 +593,7 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> { fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem<'tcx>) { let impl_def_id = self.tcx.hir().get_parent_item(ii.hir_id()); - if self.tcx.bound_impl_trait_ref(impl_def_id.to_def_id()).is_none() { + if self.tcx.impl_trait_ref(impl_def_id).is_none() { self.check_missing_stability(ii.owner_id.def_id, ii.span); self.check_missing_const_stability(ii.owner_id.def_id, ii.span); } diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 69bfa8e2709af..fb55bb4afaac3 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -337,7 +337,7 @@ trait VisibilityLike: Sized { ) -> Self { let mut find = FindMin { tcx, effective_visibilities, min: Self::MAX }; find.visit(tcx.type_of(def_id)); - if let Some(trait_ref) = tcx.bound_impl_trait_ref(def_id.into()) { + if let Some(trait_ref) = tcx.impl_trait_ref(def_id) { find.visit_trait(trait_ref.subst_identity()); } find.min @@ -857,7 +857,7 @@ impl ReachEverythingInTheInterfaceVisitor<'_, '_> { } fn trait_ref(&mut self) -> &mut Self { - if let Some(trait_ref) = self.ev.tcx.bound_impl_trait_ref(self.item_def_id.into()) { + if let Some(trait_ref) = self.ev.tcx.impl_trait_ref(self.item_def_id) { self.visit_trait(trait_ref.subst_identity()); } self diff --git a/compiler/rustc_trait_selection/src/solve/project_goals.rs b/compiler/rustc_trait_selection/src/solve/project_goals.rs index 3d649bea19ddf..e9140507192e1 100644 --- a/compiler/rustc_trait_selection/src/solve/project_goals.rs +++ b/compiler/rustc_trait_selection/src/solve/project_goals.rs @@ -110,7 +110,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> { ) { let tcx = acx.cx.tcx; let goal_trait_ref = goal.predicate.projection_ty.trait_ref(tcx); - let impl_trait_ref = tcx.bound_impl_trait_ref(impl_def_id).unwrap(); + let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap(); let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsPlaceholder }; if iter::zip(goal_trait_ref.substs, impl_trait_ref.skip_binder().substs) .any(|(goal, imp)| !drcx.generic_args_may_unify(goal, imp)) diff --git a/compiler/rustc_trait_selection/src/solve/trait_goals.rs b/compiler/rustc_trait_selection/src/solve/trait_goals.rs index c69cc39acb53c..a43fef5cdb0c8 100644 --- a/compiler/rustc_trait_selection/src/solve/trait_goals.rs +++ b/compiler/rustc_trait_selection/src/solve/trait_goals.rs @@ -73,7 +73,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { ) { let tcx = acx.cx.tcx; - let impl_trait_ref = tcx.bound_impl_trait_ref(impl_def_id).unwrap(); + let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap(); let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsPlaceholder }; if iter::zip(goal.predicate.trait_ref.substs, impl_trait_ref.skip_binder().substs) .any(|(goal, imp)| !drcx.generic_args_may_unify(goal, imp)) diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 623ef7964bf0d..185810ed3d8ee 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -77,8 +77,8 @@ pub fn overlapping_impls( // a quick check via fast_reject to tell if the impl headers could possibly // unify. let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsInfer }; - let impl1_ref = tcx.bound_impl_trait_ref(impl1_def_id).map(ty::EarlyBinder::subst_identity); - let impl2_ref = tcx.bound_impl_trait_ref(impl2_def_id).map(ty::EarlyBinder::subst_identity); + let impl1_ref = tcx.impl_trait_ref(impl1_def_id).map(ty::EarlyBinder::subst_identity); + let impl2_ref = tcx.impl_trait_ref(impl2_def_id).map(ty::EarlyBinder::subst_identity); let may_overlap = match (impl1_ref, impl2_ref) { (Some(a), Some(b)) => iter::zip(a.substs, b.substs) .all(|(arg1, arg2)| drcx.generic_args_may_unify(arg1, arg2)), @@ -126,7 +126,7 @@ fn with_fresh_ty_vars<'cx, 'tcx>( let header = ty::ImplHeader { impl_def_id, self_ty: tcx.bound_type_of(impl_def_id).subst(tcx, impl_substs), - trait_ref: tcx.bound_impl_trait_ref(impl_def_id).map(|i| i.subst(tcx, impl_substs)), + trait_ref: tcx.impl_trait_ref(impl_def_id).map(|i| i.subst(tcx, impl_substs)), predicates: tcx.predicates_of(impl_def_id).instantiate(tcx, impl_substs).predicates, }; @@ -461,7 +461,7 @@ pub fn orphan_check(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Result<(), OrphanChe // We only except this routine to be invoked on implementations // of a trait, not inherent implementations. - let trait_ref = tcx.bound_impl_trait_ref(impl_def_id).unwrap().skip_binder(); + let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().skip_binder(); debug!("orphan_check: trait_ref={:?}", trait_ref); // If the *trait* is local to the crate, ok. diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/ambiguity.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/ambiguity.rs index 0c1717cff332c..df57c0f60fa6d 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/ambiguity.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/ambiguity.rs @@ -27,7 +27,7 @@ pub fn recompute_applicable_impls<'tcx>( ocx.normalize(&ObligationCause::dummy(), param_env, placeholder_obligation.trait_ref); let impl_substs = infcx.fresh_substs_for_item(DUMMY_SP, impl_def_id); - let impl_trait_ref = tcx.bound_impl_trait_ref(impl_def_id).unwrap().subst(tcx, impl_substs); + let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().subst(tcx, impl_substs); let impl_trait_ref = ocx.normalize(&ObligationCause::dummy(), param_env, impl_trait_ref); if let Err(_) = diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 8b9c6821dafec..5d2e0bd5afa45 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -1940,7 +1940,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { return None; } - let imp = self.tcx.bound_impl_trait_ref(def_id).unwrap().subst_identity(); + let imp = self.tcx.impl_trait_ref(def_id).unwrap().subst_identity(); self.fuzzy_match_tys(trait_pred.skip_binder().self_ty(), imp.self_ty(), false) .map(|similarity| ImplCandidate { trait_ref: imp, similarity }) @@ -2039,7 +2039,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { self.tcx.impl_polarity(def_id) != ty::ImplPolarity::Negative || self.tcx.is_builtin_derive(def_id) }) - .filter_map(|def_id| self.tcx.bound_impl_trait_ref(def_id)) + .filter_map(|def_id| self.tcx.impl_trait_ref(def_id)) .map(ty::EarlyBinder::subst_identity) .filter(|trait_ref| { let self_ty = trait_ref.self_ty(); diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs index e599996230f51..18d308f7123ae 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs @@ -68,7 +68,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { self.tcx.for_each_relevant_impl(trait_ref.def_id, trait_self_ty, |def_id| { let impl_substs = self.fresh_substs_for_item(obligation.cause.span, def_id); - let impl_trait_ref = tcx.bound_impl_trait_ref(def_id).unwrap().subst(tcx, impl_substs); + let impl_trait_ref = tcx.impl_trait_ref(def_id).unwrap().subst(tcx, impl_substs); let impl_self_ty = impl_trait_ref.self_ty(); diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 4c34dc64c26cc..241ae0275cec8 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -522,7 +522,7 @@ fn is_impossible_method(tcx: TyCtxt<'_>, (impl_def_id, trait_item_def_id): (DefI let generics = tcx.generics_of(trait_item_def_id); let predicates = tcx.predicates_of(trait_item_def_id); let impl_trait_ref = tcx - .bound_impl_trait_ref(impl_def_id) + .impl_trait_ref(impl_def_id) .expect("expected impl to correspond to trait") .subst_identity(); let param_env = tcx.param_env(impl_def_id); diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index 8c291d1595d96..e29ad30d5f2ec 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -357,7 +357,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // Before we create the substitutions and everything, first // consider a "quick reject". This avoids creating more types // and so forth that we need to. - let impl_trait_ref = self.tcx().bound_impl_trait_ref(impl_def_id).unwrap(); + let impl_trait_ref = self.tcx().impl_trait_ref(impl_def_id).unwrap(); if self.fast_reject_trait_refs(obligation, &impl_trait_ref.0) { return; } diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 305902af7c829..ba4e668f52ddd 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -2335,7 +2335,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { impl_def_id: DefId, obligation: &TraitObligation<'tcx>, ) -> Normalized<'tcx, SubstsRef<'tcx>> { - let impl_trait_ref = self.tcx().bound_impl_trait_ref(impl_def_id).unwrap(); + let impl_trait_ref = self.tcx().impl_trait_ref(impl_def_id).unwrap(); match self.match_impl(impl_def_id, impl_trait_ref, obligation) { Ok(substs) => substs, Err(()) => { diff --git a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs index a352a65fb068f..69b671b27bd51 100644 --- a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs @@ -87,7 +87,7 @@ pub fn translate_substs<'tcx>( param_env, source_impl, source_substs, target_node ); let source_trait_ref = - infcx.tcx.bound_impl_trait_ref(source_impl).unwrap().subst(infcx.tcx, &source_substs); + infcx.tcx.impl_trait_ref(source_impl).unwrap().subst(infcx.tcx, &source_substs); // translate the Self and Param parts of the substitution, since those // vary across impls @@ -148,7 +148,7 @@ pub(super) fn specializes(tcx: TyCtxt<'_>, (impl1_def_id, impl2_def_id): (DefId, // create a parameter environment corresponding to a (placeholder) instantiation of impl1 let penv = tcx.param_env(impl1_def_id); - let impl1_trait_ref = tcx.bound_impl_trait_ref(impl1_def_id).unwrap().subst_identity(); + let impl1_trait_ref = tcx.impl_trait_ref(impl1_def_id).unwrap().subst_identity(); // Create an infcx, taking the predicates of impl1 as assumptions: let infcx = tcx.infer_ctxt().build(); @@ -431,7 +431,7 @@ fn report_conflicting_impls<'tcx>( pub(crate) fn to_pretty_impl_header(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Option { use std::fmt::Write; - let trait_ref = tcx.bound_impl_trait_ref(impl_def_id)?.skip_binder(); + let trait_ref = tcx.impl_trait_ref(impl_def_id)?.skip_binder(); let mut w = "impl".to_owned(); let substs = InternalSubsts::identity_for_item(tcx, impl_def_id); 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 a2e39c53d15c8..eb4815122c33e 100644 --- a/compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs +++ b/compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs @@ -48,7 +48,7 @@ trait ChildrenExt<'tcx> { impl<'tcx> ChildrenExt<'tcx> for Children { /// Insert an impl into this set of children without comparing to any existing impls. fn insert_blindly(&mut self, tcx: TyCtxt<'tcx>, impl_def_id: DefId) { - let trait_ref = tcx.bound_impl_trait_ref(impl_def_id).unwrap().subst_identity(); + let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().subst_identity(); if let Some(st) = fast_reject::simplify_type(tcx, trait_ref.self_ty(), TreatParams::AsInfer) { debug!("insert_blindly: impl_def_id={:?} st={:?}", impl_def_id, st); @@ -63,7 +63,7 @@ impl<'tcx> ChildrenExt<'tcx> for Children { /// an impl with a parent. The impl must be present in the list of /// children already. fn remove_existing(&mut self, tcx: TyCtxt<'tcx>, impl_def_id: DefId) { - let trait_ref = tcx.bound_impl_trait_ref(impl_def_id).unwrap().subst_identity(); + let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().subst_identity(); let vec: &mut Vec; if let Some(st) = fast_reject::simplify_type(tcx, trait_ref.self_ty(), TreatParams::AsInfer) { @@ -181,7 +181,7 @@ impl<'tcx> ChildrenExt<'tcx> for Children { if le && !ge { debug!( "descending as child of TraitRef {:?}", - tcx.bound_impl_trait_ref(possible_sibling).unwrap().subst_identity() + tcx.impl_trait_ref(possible_sibling).unwrap().subst_identity() ); // The impl specializes `possible_sibling`. @@ -189,7 +189,7 @@ impl<'tcx> ChildrenExt<'tcx> for Children { } else if ge && !le { debug!( "placing as parent of TraitRef {:?}", - tcx.bound_impl_trait_ref(possible_sibling).unwrap().subst_identity() + tcx.impl_trait_ref(possible_sibling).unwrap().subst_identity() ); replace_children.push(possible_sibling); @@ -275,7 +275,7 @@ impl<'tcx> GraphExt<'tcx> for Graph { ) -> Result>, OverlapError<'tcx>> { assert!(impl_def_id.is_local()); - let trait_ref = tcx.bound_impl_trait_ref(impl_def_id).unwrap().subst_identity(); + let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().subst_identity(); let trait_def_id = trait_ref.def_id; debug!( @@ -388,7 +388,7 @@ pub(crate) fn assoc_def( impl_def_id: DefId, assoc_def_id: DefId, ) -> Result { - let trait_def_id = tcx.bound_impl_trait_ref(impl_def_id).unwrap().skip_binder().def_id; + let trait_def_id = tcx.impl_trait_ref(impl_def_id).unwrap().skip_binder().def_id; let trait_def = tcx.trait_def(trait_def_id); // This function may be called while we are still building the diff --git a/compiler/rustc_traits/src/chalk/db.rs b/compiler/rustc_traits/src/chalk/db.rs index dea33f896cf17..7c0cae1e7bdc2 100644 --- a/compiler/rustc_traits/src/chalk/db.rs +++ b/compiler/rustc_traits/src/chalk/db.rs @@ -309,7 +309,7 @@ impl<'tcx> chalk_solve::RustIrDatabase> for RustIrDatabase<'t let bound_vars = bound_vars_for_item(self.interner.tcx, def_id); let binders = binders_for(self.interner, bound_vars); - let trait_ref = self.interner.tcx.bound_impl_trait_ref(def_id).expect("not an impl"); + let trait_ref = self.interner.tcx.impl_trait_ref(def_id).expect("not an impl"); let trait_ref = trait_ref.subst(self.interner.tcx, bound_vars); let where_clauses = self.where_clauses_for(def_id, bound_vars); @@ -351,7 +351,7 @@ impl<'tcx> chalk_solve::RustIrDatabase> for RustIrDatabase<'t let all_impls = self.interner.tcx.all_impls(def_id); let matched_impls = all_impls.filter(|impl_def_id| { use chalk_ir::could_match::CouldMatch; - let trait_ref = self.interner.tcx.bound_impl_trait_ref(*impl_def_id).unwrap(); + let trait_ref = self.interner.tcx.impl_trait_ref(*impl_def_id).unwrap(); let bound_vars = bound_vars_for_item(self.interner.tcx, *impl_def_id); let self_ty = trait_ref.map_bound(|t| t.self_ty()); @@ -380,8 +380,7 @@ impl<'tcx> chalk_solve::RustIrDatabase> for RustIrDatabase<'t let trait_def_id = auto_trait_id.0; let all_impls = self.interner.tcx.all_impls(trait_def_id); for impl_def_id in all_impls { - let trait_ref = - self.interner.tcx.bound_impl_trait_ref(impl_def_id).unwrap().subst_identity(); + let trait_ref = self.interner.tcx.impl_trait_ref(impl_def_id).unwrap().subst_identity(); let self_ty = trait_ref.self_ty(); let provides = match (self_ty.kind(), chalk_ty) { (&ty::Adt(impl_adt_def, ..), Adt(id, ..)) => impl_adt_def.did() == id.0.did(), diff --git a/compiler/rustc_ty_utils/src/implied_bounds.rs b/compiler/rustc_ty_utils/src/implied_bounds.rs index d890a04599b1c..7a9c1d8ffe7d4 100644 --- a/compiler/rustc_ty_utils/src/implied_bounds.rs +++ b/compiler/rustc_ty_utils/src/implied_bounds.rs @@ -22,7 +22,7 @@ fn assumed_wf_types(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List> { tcx.intern_type_list(&assumed_wf_types) } DefKind::Impl => { - match tcx.bound_impl_trait_ref(def_id).map(ty::EarlyBinder::subst_identity) { + match tcx.impl_trait_ref(def_id).map(ty::EarlyBinder::subst_identity) { Some(trait_ref) => { let types: Vec<_> = trait_ref.substs.types().collect(); tcx.intern_type_list(&types) diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index 78c3a208e889f..eb5454bf2634b 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -289,7 +289,7 @@ fn well_formed_types_in_env(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List { - let trait_ref = tcx.bound_impl_trait_ref(def_id).expect("not an impl").subst_identity(); + let trait_ref = tcx.impl_trait_ref(def_id).expect("not an impl").subst_identity(); // FIXME(chalk): this has problems because of late-bound regions //inputs.extend(trait_ref.substs.iter().flat_map(|arg| arg.walk())); @@ -359,7 +359,7 @@ fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option> { debug!("issue33140_self_ty({:?})", def_id); let trait_ref = tcx - .bound_impl_trait_ref(def_id) + .impl_trait_ref(def_id) .unwrap_or_else(|| bug!("issue33140_self_ty called on inherent impl {:?}", def_id)) .skip_binder(); diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index 4ef5747596bb3..e6b2b2349452a 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -33,7 +33,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> { trait_def_id, impl_def_id ); - let trait_ref = cx.tcx.bound_impl_trait_ref(impl_def_id).unwrap(); + let trait_ref = cx.tcx.impl_trait_ref(impl_def_id).unwrap(); if !matches!(trait_ref.0.self_ty().kind(), ty::Param(_)) { continue; } diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 23330daa54bf0..c6939326144ea 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -376,7 +376,7 @@ pub(crate) fn build_impl( let _prof_timer = cx.tcx.sess.prof.generic_activity("build_impl"); let tcx = cx.tcx; - let associated_trait = tcx.bound_impl_trait_ref(did).map(ty::EarlyBinder::skip_binder); + let associated_trait = tcx.impl_trait_ref(did).map(ty::EarlyBinder::skip_binder); // Only inline impl if the implemented trait is // reachable in rustdoc generated documentation diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index cda90955ba116..87de41fde63c5 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -734,7 +734,7 @@ impl Item { ty::ImplContainer => { // Trait impl items always inherit the impl's visibility -- // we don't want to show `pub`. - tcx.bound_impl_trait_ref(tcx.parent(assoc_item.def_id)).is_some() + tcx.impl_trait_ref(tcx.parent(assoc_item.def_id)).is_some() } }; if is_trait_item { diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index fa9174287e272..62588040685fc 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -784,7 +784,7 @@ fn trait_impls_for<'a>( // Look at each trait implementation to see if it's an impl for `did` tcx.find_map_relevant_impl(trait_, ty, |impl_| { - let trait_ref = tcx.bound_impl_trait_ref(impl_).expect("this is not an inherent impl"); + let trait_ref = tcx.impl_trait_ref(impl_).expect("this is not an inherent impl"); // Check if these are the same type. let impl_type = trait_ref.subst_identity().self_ty(); trace!( diff --git a/src/tools/clippy/clippy_lints/src/derive.rs b/src/tools/clippy/clippy_lints/src/derive.rs index 6b2b18fff76e0..248d738841067 100644 --- a/src/tools/clippy/clippy_lints/src/derive.rs +++ b/src/tools/clippy/clippy_lints/src/derive.rs @@ -247,7 +247,7 @@ fn check_hash_peq<'tcx>( return; } - let trait_ref = cx.tcx.bound_impl_trait_ref(impl_id).expect("must be a trait implementation"); + let trait_ref = cx.tcx.impl_trait_ref(impl_id).expect("must be a trait implementation"); // Only care about `impl PartialEq for Foo` // For `impl PartialEq for A, input_types is [A, B] @@ -295,7 +295,7 @@ fn check_ord_partial_ord<'tcx>( return; } - let trait_ref = cx.tcx.bound_impl_trait_ref(impl_id).expect("must be a trait implementation"); + let trait_ref = cx.tcx.impl_trait_ref(impl_id).expect("must be a trait implementation"); // Only care about `impl PartialOrd for Foo` // For `impl PartialOrd for A, input_types is [A, B] diff --git a/src/tools/clippy/clippy_lints/src/fallible_impl_from.rs b/src/tools/clippy/clippy_lints/src/fallible_impl_from.rs index a8085122ccf95..2ef547526d4f7 100644 --- a/src/tools/clippy/clippy_lints/src/fallible_impl_from.rs +++ b/src/tools/clippy/clippy_lints/src/fallible_impl_from.rs @@ -55,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom { // check for `impl From for ..` if_chain! { if let hir::ItemKind::Impl(impl_) = &item.kind; - if let Some(impl_trait_ref) = cx.tcx.bound_impl_trait_ref(item.owner_id.to_def_id()); + if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id); if cx.tcx.is_diagnostic_item(sym::From, impl_trait_ref.skip_binder().def_id); then { lint_impl_body(cx, item.span, impl_.items); diff --git a/src/tools/clippy/clippy_lints/src/from_over_into.rs b/src/tools/clippy/clippy_lints/src/from_over_into.rs index 97d414bfa95e4..bd66ace4500a8 100644 --- a/src/tools/clippy/clippy_lints/src/from_over_into.rs +++ b/src/tools/clippy/clippy_lints/src/from_over_into.rs @@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto { && let Some(into_trait_seg) = hir_trait_ref.path.segments.last() // `impl Into for self_ty` && let Some(GenericArgs { args: [GenericArg::Type(target_ty)], .. }) = into_trait_seg.args - && let Some(middle_trait_ref) = cx.tcx.bound_impl_trait_ref(item.owner_id.to_def_id()).map(ty::EarlyBinder::subst_identity) + && let Some(middle_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id).map(ty::EarlyBinder::subst_identity) && cx.tcx.is_diagnostic_item(sym::Into, middle_trait_ref.def_id) && !matches!(middle_trait_ref.substs.type_at(1).kind(), ty::Alias(ty::Opaque, _)) { diff --git a/src/tools/clippy/clippy_lints/src/implicit_saturating_sub.rs b/src/tools/clippy/clippy_lints/src/implicit_saturating_sub.rs index 37e33529a9a60..29d59c26d92c4 100644 --- a/src/tools/clippy/clippy_lints/src/implicit_saturating_sub.rs +++ b/src/tools/clippy/clippy_lints/src/implicit_saturating_sub.rs @@ -101,7 +101,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub { if name.ident.as_str() == "MIN"; if let Some(const_id) = cx.typeck_results().type_dependent_def_id(cond_num_val.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(const_id); - if let None = cx.tcx.bound_impl_trait_ref(impl_id); // An inherent impl + if let None = cx.tcx.impl_trait_ref(impl_id); // An inherent impl if cx.tcx.type_of(impl_id).is_integral(); then { print_lint_and_sugg(cx, var_name, expr) @@ -114,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub { if name.ident.as_str() == "min_value"; if let Some(func_id) = cx.typeck_results().type_dependent_def_id(func.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(func_id); - if let None = cx.tcx.bound_impl_trait_ref(impl_id); // An inherent impl + if let None = cx.tcx.impl_trait_ref(impl_id); // An inherent impl if cx.tcx.type_of(impl_id).is_integral(); then { print_lint_and_sugg(cx, var_name, expr) diff --git a/src/tools/clippy/clippy_lints/src/methods/implicit_clone.rs b/src/tools/clippy/clippy_lints/src/methods/implicit_clone.rs index 16a25a98800de..06ecbce4e70e9 100644 --- a/src/tools/clippy/clippy_lints/src/methods/implicit_clone.rs +++ b/src/tools/clippy/clippy_lints/src/methods/implicit_clone.rs @@ -53,7 +53,7 @@ pub fn is_clone_like(cx: &LateContext<'_>, method_name: &str, method_def_id: hir "to_vec" => cx .tcx .impl_of_method(method_def_id) - .filter(|&impl_did| cx.tcx.type_of(impl_did).is_slice() && cx.tcx.bound_impl_trait_ref(impl_did).is_none()) + .filter(|&impl_did| cx.tcx.type_of(impl_did).is_slice() && cx.tcx.impl_trait_ref(impl_did).is_none()) .is_some(), _ => false, } diff --git a/src/tools/clippy/clippy_lints/src/methods/suspicious_splitn.rs b/src/tools/clippy/clippy_lints/src/methods/suspicious_splitn.rs index dba0663467b7d..219a9edd65768 100644 --- a/src/tools/clippy/clippy_lints/src/methods/suspicious_splitn.rs +++ b/src/tools/clippy/clippy_lints/src/methods/suspicious_splitn.rs @@ -12,7 +12,7 @@ pub(super) fn check(cx: &LateContext<'_>, method_name: &str, expr: &Expr<'_>, se if count <= 1; if let Some(call_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); if let Some(impl_id) = cx.tcx.impl_of_method(call_id); - if cx.tcx.bound_impl_trait_ref(impl_id).is_none(); + if cx.tcx.impl_trait_ref(impl_id).is_none(); let self_ty = cx.tcx.type_of(impl_id); if self_ty.is_slice() || self_ty.is_str(); then { diff --git a/src/tools/clippy/clippy_lints/src/missing_doc.rs b/src/tools/clippy/clippy_lints/src/missing_doc.rs index d0c99b352452f..6fd100762b49d 100644 --- a/src/tools/clippy/clippy_lints/src/missing_doc.rs +++ b/src/tools/clippy/clippy_lints/src/missing_doc.rs @@ -175,7 +175,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) { // If the method is an impl for a trait, don't doc. if let Some(cid) = cx.tcx.associated_item(impl_item.owner_id).impl_container(cx.tcx) { - if cx.tcx.bound_impl_trait_ref(cid).is_some() { + if cx.tcx.impl_trait_ref(cid).is_some() { return; } } else { diff --git a/src/tools/clippy/clippy_lints/src/missing_inline.rs b/src/tools/clippy/clippy_lints/src/missing_inline.rs index 0594fb175458d..5a459548153aa 100644 --- a/src/tools/clippy/clippy_lints/src/missing_inline.rs +++ b/src/tools/clippy/clippy_lints/src/missing_inline.rs @@ -155,7 +155,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { let container_id = assoc_item.container_id(cx.tcx); let trait_def_id = match assoc_item.container { TraitContainer => Some(container_id), - ImplContainer => cx.tcx.bound_impl_trait_ref(container_id).map(|t| t.skip_binder().def_id), + ImplContainer => cx.tcx.impl_trait_ref(container_id).map(|t| t.skip_binder().def_id), }; if let Some(trait_def_id) = trait_def_id { diff --git a/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs b/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs index 9c112ade948ff..839c3a3815c29 100644 --- a/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs +++ b/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs @@ -89,7 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy { if let Some(trait_id) = trait_ref.trait_def_id(); if send_trait == trait_id; if hir_impl.polarity == ImplPolarity::Positive; - if let Some(ty_trait_ref) = cx.tcx.bound_impl_trait_ref(item.owner_id.to_def_id()); + if let Some(ty_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id); if let self_ty = ty_trait_ref.subst_identity().self_ty(); if let ty::Adt(adt_def, impl_trait_substs) = self_ty.kind(); then { diff --git a/src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs b/src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs index 82b1716a216e6..7b1d974f2f877 100644 --- a/src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs +++ b/src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs @@ -244,7 +244,7 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion { })) => { #[allow(trivial_casts)] if let Some(Node::Item(item)) = get_parent_node(cx.tcx, owner_id.into()) - && let Some(trait_ref) = cx.tcx.bound_impl_trait_ref(item.owner_id.to_def_id()).map(|t| t.subst_identity()) + && let Some(trait_ref) = cx.tcx.impl_trait_ref(item.owner_id).map(|t| t.subst_identity()) && let Some(trait_item_id) = cx.tcx.associated_item(owner_id).trait_item_def_id { ( diff --git a/src/tools/clippy/clippy_lints/src/use_self.rs b/src/tools/clippy/clippy_lints/src/use_self.rs index 9f31a13aa984b..6ae9d9d635380 100644 --- a/src/tools/clippy/clippy_lints/src/use_self.rs +++ b/src/tools/clippy/clippy_lints/src/use_self.rs @@ -133,7 +133,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { ref mut types_to_skip, .. }) = self.stack.last_mut(); - if let Some(impl_trait_ref) = cx.tcx.bound_impl_trait_ref(impl_id.to_def_id()); + if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_id); then { // `self_ty` is the semantic self type of `impl for `. This cannot be // `Self`. From 6e969ea85eb8f5e504c1a0a06c0a63c515fadf3b Mon Sep 17 00:00:00 2001 From: Kyle Matsuda Date: Wed, 11 Jan 2023 11:32:33 -0700 Subject: [PATCH 6/6] fix various subst_identity vs skip_binder --- compiler/rustc_hir_analysis/src/astconv/mod.rs | 2 +- compiler/rustc_hir_analysis/src/check/check.rs | 2 +- compiler/rustc_hir_analysis/src/coherence/orphan.rs | 2 +- compiler/rustc_hir_analysis/src/coherence/unsafety.rs | 3 ++- compiler/rustc_metadata/src/rmeta/encoder.rs | 6 +++--- compiler/rustc_middle/src/ty/mod.rs | 6 ++++-- compiler/rustc_monomorphize/src/collector.rs | 6 +++--- compiler/rustc_trait_selection/src/traits/coherence.rs | 8 ++++---- .../src/traits/error_reporting/mod.rs | 2 +- .../rustc_trait_selection/src/traits/specialize/mod.rs | 2 +- .../src/traits/specialize/specialization_graph.rs | 9 +++++---- compiler/rustc_ty_utils/src/implied_bounds.rs | 4 ++-- src/librustdoc/passes/collect_intra_doc_links.rs | 2 +- 13 files changed, 29 insertions(+), 25 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 7567a02d1454e..8d2cc70c05f16 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -2066,7 +2066,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { }; self.one_bound_for_assoc_type( - || traits::supertraits(tcx, ty::Binder::dummy(trait_ref.skip_binder())), + || traits::supertraits(tcx, ty::Binder::dummy(trait_ref.subst_identity())), || "Self".to_string(), assoc_ident, span, diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 7df19ba6d36bf..e58669433e218 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -540,7 +540,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) { tcx, it.span, it.owner_id.def_id, - impl_trait_ref.skip_binder(), + impl_trait_ref.subst_identity(), &impl_.items, ); check_on_unimplemented(tcx, it); diff --git a/compiler/rustc_hir_analysis/src/coherence/orphan.rs b/compiler/rustc_hir_analysis/src/coherence/orphan.rs index e8fe92814576e..0aadc9f311b03 100644 --- a/compiler/rustc_hir_analysis/src/coherence/orphan.rs +++ b/compiler/rustc_hir_analysis/src/coherence/orphan.rs @@ -21,7 +21,7 @@ pub(crate) fn orphan_check_impl( tcx: TyCtxt<'_>, impl_def_id: LocalDefId, ) -> Result<(), ErrorGuaranteed> { - let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().skip_binder(); + let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().subst_identity(); trait_ref.error_reported()?; let ret = do_orphan_check_impl(tcx, trait_ref, impl_def_id); diff --git a/compiler/rustc_hir_analysis/src/coherence/unsafety.rs b/compiler/rustc_hir_analysis/src/coherence/unsafety.rs index c7693cab47412..a485768e37b83 100644 --- a/compiler/rustc_hir_analysis/src/coherence/unsafety.rs +++ b/compiler/rustc_hir_analysis/src/coherence/unsafety.rs @@ -13,7 +13,8 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) { let item = tcx.hir().expect_item(def_id); let hir::ItemKind::Impl(ref impl_) = item.kind else { bug!() }; - if let Some(trait_ref) = tcx.impl_trait_ref(item.owner_id).map(|t| t.subst_identity()) { + if let Some(trait_ref) = tcx.impl_trait_ref(item.owner_id) { + let trait_ref = trait_ref.subst_identity(); let trait_def = tcx.trait_def(trait_ref.def_id); let unsafe_attr = impl_.generics.params.iter().find(|p| p.pure_wrt_drop).map(|_| "may_dangle"); diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index ba856a11890e5..a8000aa3c8a83 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1898,9 +1898,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { for id in tcx.hir().items() { if matches!(tcx.def_kind(id.owner_id), DefKind::Impl) { - if let Some(trait_ref) = - tcx.impl_trait_ref(id.owner_id).map(ty::EarlyBinder::subst_identity) - { + if let Some(trait_ref) = tcx.impl_trait_ref(id.owner_id) { + let trait_ref = trait_ref.subst_identity(); + let simplified_self_ty = fast_reject::simplify_type( self.tcx, trait_ref.self_ty(), diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 7cc4ad4ca46cd..e9bd0e9866fdc 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -2187,8 +2187,10 @@ impl<'tcx> TyCtxt<'tcx> { ) -> Option { // If either trait impl references an error, they're allowed to overlap, // as one of them essentially doesn't exist. - if self.impl_trait_ref(def_id1).map_or(false, |tr| tr.skip_binder().references_error()) - || self.impl_trait_ref(def_id2).map_or(false, |tr| tr.skip_binder().references_error()) + if self.impl_trait_ref(def_id1).map_or(false, |tr| tr.subst_identity().references_error()) + || self + .impl_trait_ref(def_id2) + .map_or(false, |tr| tr.subst_identity().references_error()) { return Some(ImplOverlapKind::Permitted { marker: false }); } diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 3080248d50824..ec1de3056872b 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -1351,9 +1351,9 @@ fn create_mono_items_for_default_impls<'tcx>( tcx.def_path_str(item.owner_id.to_def_id()) ); - if let Some(trait_ref) = - tcx.impl_trait_ref(item.owner_id).map(ty::EarlyBinder::subst_identity) - { + if let Some(trait_ref) = tcx.impl_trait_ref(item.owner_id) { + let trait_ref = trait_ref.subst_identity(); + let param_env = ty::ParamEnv::reveal_all(); let trait_ref = tcx.normalize_erasing_regions(param_env, trait_ref); let overridden_methods = tcx.impl_item_implementor_ids(item.owner_id); diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 185810ed3d8ee..0edae34190c30 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -77,10 +77,10 @@ pub fn overlapping_impls( // a quick check via fast_reject to tell if the impl headers could possibly // unify. let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsInfer }; - let impl1_ref = tcx.impl_trait_ref(impl1_def_id).map(ty::EarlyBinder::subst_identity); - let impl2_ref = tcx.impl_trait_ref(impl2_def_id).map(ty::EarlyBinder::subst_identity); + let impl1_ref = tcx.impl_trait_ref(impl1_def_id); + let impl2_ref = tcx.impl_trait_ref(impl2_def_id); let may_overlap = match (impl1_ref, impl2_ref) { - (Some(a), Some(b)) => iter::zip(a.substs, b.substs) + (Some(a), Some(b)) => iter::zip(a.skip_binder().substs, b.skip_binder().substs) .all(|(arg1, arg2)| drcx.generic_args_may_unify(arg1, arg2)), (None, None) => { let self_ty1 = tcx.type_of(impl1_def_id); @@ -461,7 +461,7 @@ pub fn orphan_check(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Result<(), OrphanChe // We only except this routine to be invoked on implementations // of a trait, not inherent implementations. - let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().skip_binder(); + let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().subst_identity(); debug!("orphan_check: trait_ref={:?}", trait_ref); // If the *trait* is local to the crate, ok. diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 5d2e0bd5afa45..052db2cfe7b90 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -1940,7 +1940,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { return None; } - let imp = self.tcx.impl_trait_ref(def_id).unwrap().subst_identity(); + let imp = self.tcx.impl_trait_ref(def_id).unwrap().skip_binder(); self.fuzzy_match_tys(trait_pred.skip_binder().self_ty(), imp.self_ty(), false) .map(|similarity| ImplCandidate { trait_ref: imp, similarity }) diff --git a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs index 69b671b27bd51..3b796c623c0ab 100644 --- a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs @@ -431,7 +431,7 @@ fn report_conflicting_impls<'tcx>( pub(crate) fn to_pretty_impl_header(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Option { use std::fmt::Write; - let trait_ref = tcx.impl_trait_ref(impl_def_id)?.skip_binder(); + let trait_ref = tcx.impl_trait_ref(impl_def_id)?.subst_identity(); let mut w = "impl".to_owned(); let substs = InternalSubsts::identity_for_item(tcx, impl_def_id); 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 eb4815122c33e..6411206a5a40c 100644 --- a/compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs +++ b/compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs @@ -48,7 +48,7 @@ trait ChildrenExt<'tcx> { impl<'tcx> ChildrenExt<'tcx> for Children { /// Insert an impl into this set of children without comparing to any existing impls. fn insert_blindly(&mut self, tcx: TyCtxt<'tcx>, impl_def_id: DefId) { - let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().subst_identity(); + let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().skip_binder(); if let Some(st) = fast_reject::simplify_type(tcx, trait_ref.self_ty(), TreatParams::AsInfer) { debug!("insert_blindly: impl_def_id={:?} st={:?}", impl_def_id, st); @@ -63,7 +63,7 @@ impl<'tcx> ChildrenExt<'tcx> for Children { /// an impl with a parent. The impl must be present in the list of /// children already. fn remove_existing(&mut self, tcx: TyCtxt<'tcx>, impl_def_id: DefId) { - let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().subst_identity(); + let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().skip_binder(); let vec: &mut Vec; if let Some(st) = fast_reject::simplify_type(tcx, trait_ref.self_ty(), TreatParams::AsInfer) { @@ -275,7 +275,8 @@ impl<'tcx> GraphExt<'tcx> for Graph { ) -> Result>, OverlapError<'tcx>> { assert!(impl_def_id.is_local()); - let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().subst_identity(); + // FIXME: use `EarlyBinder` in `self.children` + let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().skip_binder(); let trait_def_id = trait_ref.def_id; debug!( @@ -388,7 +389,7 @@ pub(crate) fn assoc_def( impl_def_id: DefId, assoc_def_id: DefId, ) -> Result { - let trait_def_id = tcx.impl_trait_ref(impl_def_id).unwrap().skip_binder().def_id; + let trait_def_id = tcx.trait_id_of_impl(impl_def_id).unwrap(); let trait_def = tcx.trait_def(trait_def_id); // This function may be called while we are still building the diff --git a/compiler/rustc_ty_utils/src/implied_bounds.rs b/compiler/rustc_ty_utils/src/implied_bounds.rs index 7a9c1d8ffe7d4..7a24645803c96 100644 --- a/compiler/rustc_ty_utils/src/implied_bounds.rs +++ b/compiler/rustc_ty_utils/src/implied_bounds.rs @@ -22,9 +22,9 @@ fn assumed_wf_types(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List> { tcx.intern_type_list(&assumed_wf_types) } DefKind::Impl => { - match tcx.impl_trait_ref(def_id).map(ty::EarlyBinder::subst_identity) { + match tcx.impl_trait_ref(def_id) { Some(trait_ref) => { - let types: Vec<_> = trait_ref.substs.types().collect(); + let types: Vec<_> = trait_ref.skip_binder().substs.types().collect(); tcx.intern_type_list(&types) } // Only the impl self type diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 62588040685fc..075951312a639 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -786,7 +786,7 @@ fn trait_impls_for<'a>( tcx.find_map_relevant_impl(trait_, ty, |impl_| { let trait_ref = tcx.impl_trait_ref(impl_).expect("this is not an inherent impl"); // Check if these are the same type. - let impl_type = trait_ref.subst_identity().self_ty(); + let impl_type = trait_ref.skip_binder().self_ty(); trace!( "comparing type {} with kind {:?} against type {:?}", impl_type,