From 39b95c965aada6bab37c803b24067bbb26644f38 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Wed, 26 Apr 2023 11:59:51 +0000 Subject: [PATCH] Don't return a `Binder` from `TraitRef::identity` --- compiler/rustc_middle/src/ty/sty.rs | 8 ++------ .../src/traits/error_reporting/ambiguity.rs | 2 +- .../rustc_trait_selection/src/traits/object_safety.rs | 11 ++++++----- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 1849a66fa8f..e1d3690b679 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -855,12 +855,8 @@ pub fn from_method( /// Returns a `TraitRef` of the form `P0: Foo` where `Pi` /// are the parameters defined on trait. - pub fn identity(tcx: TyCtxt<'tcx>, def_id: DefId) -> Binder<'tcx, TraitRef<'tcx>> { - ty::Binder::dummy(ty::TraitRef::new( - tcx, - def_id, - InternalSubsts::identity_for_item(tcx, def_id), - )) + pub fn identity(tcx: TyCtxt<'tcx>, def_id: DefId) -> TraitRef<'tcx> { + ty::TraitRef::new(tcx, def_id, InternalSubsts::identity_for_item(tcx, def_id)) } pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self { 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 0475f24d87c..7ab652761a4 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/ambiguity.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/ambiguity.rs @@ -87,7 +87,7 @@ pub fn recompute_applicable_impls<'tcx>( if let ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)) = kind.skip_binder() && param_env_candidate_may_apply(kind.rebind(trait_pred)) { - if kind.rebind(trait_pred.trait_ref) == ty::TraitRef::identity(tcx, trait_pred.def_id()) { + if kind.rebind(trait_pred.trait_ref) == ty::Binder::dummy(ty::TraitRef::identity(tcx, trait_pred.def_id())) { ambiguities.push(Ambiguity::ParamEnv(tcx.def_span(trait_pred.def_id()))) } else { ambiguities.push(Ambiguity::ParamEnv(span)) diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index 3f526e70522..6cb9b213852 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -279,7 +279,7 @@ fn predicates_reference_self( trait_def_id: DefId, supertraits_only: bool, ) -> SmallVec<[Span; 1]> { - let trait_ref = ty::TraitRef::identity(tcx, trait_def_id); + let trait_ref = ty::Binder::dummy(ty::TraitRef::identity(tcx, trait_def_id)); let predicates = if supertraits_only { tcx.super_predicates_of(trait_def_id) } else { @@ -661,9 +661,9 @@ fn object_ty_for_trait<'tcx>( let trait_ref = ty::TraitRef::identity(tcx, trait_def_id); debug!(?trait_ref); - let trait_predicate = trait_ref.map_bound(|trait_ref| { - ty::ExistentialPredicate::Trait(ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref)) - }); + let trait_predicate = ty::Binder::dummy(ty::ExistentialPredicate::Trait( + ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref), + )); debug!(?trait_predicate); let pred: ty::Predicate<'tcx> = trait_ref.to_predicate(tcx); @@ -880,7 +880,8 @@ fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { // Compute supertraits of current trait lazily. if self.supertraits.is_none() { - let trait_ref = ty::TraitRef::identity(self.tcx, self.trait_def_id); + let trait_ref = + ty::Binder::dummy(ty::TraitRef::identity(self.tcx, self.trait_def_id)); self.supertraits = Some( traits::supertraits(self.tcx, trait_ref).map(|t| t.def_id()).collect(), );