Add Lifetimes to the HIR

This commit is contained in:
Lukas Wirth 2020-12-11 13:49:32 +01:00
parent 41321d9678
commit 11f8664182
16 changed files with 249 additions and 96 deletions

View file

@ -2,11 +2,10 @@
//! query, but can't be computed directly from `*Data` (ie, which need a `db`).
use std::sync::Arc;
use hir_def::generics::WherePredicateTarget;
use hir_def::{
adt::VariantData,
db::DefDatabase,
generics::{GenericParams, TypeParamData, TypeParamProvenance},
generics::{GenericParams, TypeParamData, TypeParamProvenance, WherePredicateTypeTarget},
path::Path,
resolver::{HasResolver, TypeNs},
type_ref::TypeRef,
@ -27,14 +26,19 @@ fn direct_super_traits(db: &dyn DefDatabase, trait_: TraitId) -> Vec<TraitId> {
generic_params
.where_predicates
.iter()
.filter_map(|pred| match &pred.target {
WherePredicateTarget::TypeRef(TypeRef::Path(p)) if p == &Path::from(name![Self]) => {
pred.bound.as_path()
}
WherePredicateTarget::TypeParam(local_id) if Some(*local_id) == trait_self => {
pred.bound.as_path()
}
_ => None,
.filter_map(|pred| match pred {
hir_def::generics::WherePredicate::TypeBound { target, bound } => match target {
WherePredicateTypeTarget::TypeRef(TypeRef::Path(p))
if p == &Path::from(name![Self]) =>
{
bound.as_path()
}
WherePredicateTypeTarget::TypeParam(local_id) if Some(*local_id) == trait_self => {
bound.as_path()
}
_ => None,
},
hir_def::generics::WherePredicate::Lifetime { .. } => None,
})
.filter_map(|path| match resolver.resolve_path_in_type_ns_fully(db, path.mod_path()) {
Some(TypeNs::TraitId(t)) => Some(t),