Skip to content

Commit

Permalink
Don't return an Option if we always unwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Jan 8, 2025
1 parent 522f45f commit 05afe0d
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion frontend/exporter/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion frontend/exporter/src/traits/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 3 additions & 7 deletions frontend/exporter/src/traits/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PolyTraitRef<'tcx>> {
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
Expand Down
1 change: 0 additions & 1 deletion frontend/exporter/src/types/new/full_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ pub enum FullDefKind<Body> {
let tcx = s.base().tcx;
let pred: ty::TraitPredicate =
crate::traits::self_predicate(tcx, s.owner_id())
.unwrap()
.no_bound_vars()
.unwrap()
.upcast(tcx);
Expand Down

0 comments on commit 05afe0d

Please sign in to comment.