This commit is contained in:
Lukas Wirth 2023-03-14 20:22:11 +01:00
parent 610a94c421
commit 510e4b4029
2 changed files with 23 additions and 31 deletions

View file

@ -12,7 +12,7 @@ use hir_def::{
use crate::{
db::HirDatabase, from_assoc_type_id, from_chalk_trait_id, from_foreign_def_id,
from_placeholder_idx, to_chalk_trait_id, utils::generics, AdtId, AliasEq, AliasTy, Binders,
CallableDefId, CallableSig, FnPointer, ImplTraitId, Interner, Lifetime, ProjectionTy,
CallableDefId, CallableSig, DynTy, FnPointer, ImplTraitId, Interner, Lifetime, ProjectionTy,
QuantifiedWhereClause, Substitution, TraitRef, Ty, TyBuilder, TyKind, TypeFlags, WhereClause,
};
@ -378,6 +378,19 @@ impl ProjectionTyExt for ProjectionTy {
}
}
pub trait DynTyExt {
fn principal(&self) -> Option<&TraitRef>;
}
impl DynTyExt for DynTy {
fn principal(&self) -> Option<&TraitRef> {
self.bounds.skip_binders().interned().get(0).and_then(|b| match b.skip_binders() {
crate::WhereClause::Implemented(trait_ref) => Some(trait_ref),
_ => None,
})
}
}
pub trait TraitRefExt {
fn hir_trait_id(&self) -> TraitId;
}