From 05afe0daa693acf42e148c99bc990439e4e014fe Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 2 Jan 2025 17:05:27 +0100 Subject: [PATCH] Don't return an `Option` if we always unwrap --- frontend/exporter/src/traits.rs | 2 +- frontend/exporter/src/traits/resolution.rs | 2 +- frontend/exporter/src/traits/utils.rs | 10 +++------- frontend/exporter/src/types/new/full_def.rs | 1 - 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/frontend/exporter/src/traits.rs b/frontend/exporter/src/traits.rs index 3b39f033e..9b3175489 100644 --- a/frontend/exporter/src/traits.rs +++ b/frontend/exporter/src/traits.rs @@ -241,7 +241,7 @@ pub fn self_clause_for_item<'tcx, S: UnderOwnerState<'tcx>>( let tr_def_id = tcx.trait_of_item(assoc.def_id)?; // The "self" predicate in the context of the trait. - let self_pred = self_predicate(tcx, tr_def_id).unwrap(); + let self_pred = self_predicate(tcx, tr_def_id); // Substitute to be in the context of the current item. let generics = generics.truncate_to(tcx, tcx.generics_of(tr_def_id)); let self_pred = EarlyBinder::bind(self_pred).instantiate(tcx, generics); diff --git a/frontend/exporter/src/traits/resolution.rs b/frontend/exporter/src/traits/resolution.rs index 1aa5ed7d9..cc5377161 100644 --- a/frontend/exporter/src/traits/resolution.rs +++ b/frontend/exporter/src/traits/resolution.rs @@ -131,7 +131,7 @@ fn initial_search_predicates<'tcx>( acc_predicates(tcx, parent, predicates, pred_id); } Trait => { - let self_pred = self_predicate(tcx, def_id).unwrap().upcast(tcx); + let self_pred = self_predicate(tcx, def_id).upcast(tcx); predicates.push(AnnotatedTraitPred { origin: BoundPredicateOrigin::SelfPred, clause: self_pred, diff --git a/frontend/exporter/src/traits/utils.rs b/frontend/exporter/src/traits/utils.rs index 02241ff9b..235a36df7 100644 --- a/frontend/exporter/src/traits/utils.rs +++ b/frontend/exporter/src/traits/utils.rs @@ -79,13 +79,9 @@ pub fn required_predicates<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> GenericPre } /// The special "self" predicate on a trait. -pub fn self_predicate<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option> { - use DefKind::*; - match tcx.def_kind(def_id) { - // Copied from the code of `tcx.predicates_of()`. - Trait => Some(Binder::dummy(TraitRef::identity(tcx, def_id))), - _ => None, - } +pub fn self_predicate<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> PolyTraitRef<'tcx> { + // Copied from the code of `tcx.predicates_of()`. + Binder::dummy(TraitRef::identity(tcx, def_id)) } /// The predicates that can be deduced from the presence of this item in a signature. We only diff --git a/frontend/exporter/src/types/new/full_def.rs b/frontend/exporter/src/types/new/full_def.rs index b82e7acc6..b432c687f 100644 --- a/frontend/exporter/src/types/new/full_def.rs +++ b/frontend/exporter/src/types/new/full_def.rs @@ -172,7 +172,6 @@ pub enum FullDefKind { let tcx = s.base().tcx; let pred: ty::TraitPredicate = crate::traits::self_predicate(tcx, s.owner_id()) - .unwrap() .no_bound_vars() .unwrap() .upcast(tcx);