]> git.lizzy.rs Git - rust.git/blobdiff - crates/hir_ty/src/lower.rs
Add ConstParams to the HIR
[rust.git] / crates / hir_ty / src / lower.rs
index 8392cb770658652db6bc1238157af30d86091de8..222f61a11d5430a3a2232a332d40a9c993ccc453 100644 (file)
@@ -16,9 +16,9 @@
     path::{GenericArg, Path, PathSegment, PathSegments},
     resolver::{HasResolver, Resolver, TypeNs},
     type_ref::{TypeBound, TypeRef},
-    AdtId, AssocContainerId, AssocItemId, ConstId, EnumId, EnumVariantId, FunctionId, GenericDefId,
-    HasModule, ImplId, LocalFieldId, Lookup, StaticId, StructId, TraitId, TypeAliasId, TypeParamId,
-    UnionId, VariantId,
+    AdtId, AssocContainerId, AssocItemId, ConstId, ConstParamId, EnumId, EnumVariantId, FunctionId,
+    GenericDefId, HasModule, ImplId, LocalFieldId, Lookup, StaticId, StructId, TraitId,
+    TypeAliasId, TypeParamId, UnionId, VariantId,
 };
 use hir_expand::name::Name;
 use smallvec::SmallVec;
@@ -675,7 +675,8 @@ pub(crate) fn from_where_predicate<'a>(
         where_predicate: &'a WherePredicate,
     ) -> impl Iterator<Item = GenericPredicate> + 'a {
         match where_predicate {
-            WherePredicate::TypeBound { target, bound } => {
+            WherePredicate::ForLifetime { target, bound, .. }
+            | WherePredicate::TypeBound { target, bound } => {
                 let self_ty = match target {
                     WherePredicateTypeTarget::TypeRef(type_ref) => Ty::from_hir(ctx, type_ref),
                     WherePredicateTypeTarget::TypeParam(param_id) => {
@@ -888,14 +889,13 @@ pub(crate) fn generic_predicates_for_param_query(
         .where_predicates_in_scope()
         // we have to filter out all other predicates *first*, before attempting to lower them
         .filter(|pred| match pred {
-            WherePredicate::TypeBound {
-                target: WherePredicateTypeTarget::TypeRef(type_ref),
-                ..
-            } => Ty::from_hir_only_param(&ctx, type_ref) == Some(param_id),
-            WherePredicate::TypeBound {
-                target: WherePredicateTypeTarget::TypeParam(local_id),
-                ..
-            } => *local_id == param_id.local_id,
+            WherePredicate::ForLifetime { target, .. }
+            | WherePredicate::TypeBound { target, .. } => match target {
+                WherePredicateTypeTarget::TypeRef(type_ref) => {
+                    Ty::from_hir_only_param(&ctx, type_ref) == Some(param_id)
+                }
+                WherePredicateTypeTarget::TypeParam(local_id) => *local_id == param_id.local_id,
+            },
             WherePredicate::Lifetime { .. } => false,
         })
         .flat_map(|pred| {
@@ -1221,6 +1221,15 @@ pub(crate) fn impl_self_ty_query(db: &dyn HirDatabase, impl_id: ImplId) -> Binde
     Binders::new(generics.len(), Ty::from_hir(&ctx, &impl_data.target_type))
 }
 
+pub(crate) fn const_param_ty_query(db: &dyn HirDatabase, def: ConstParamId) -> Ty {
+    let parent_data = db.generic_params(def.parent);
+    let data = &parent_data.consts[def.local_id];
+    let resolver = def.parent.resolver(db.upcast());
+    let ctx = TyLoweringContext::new(db, &resolver);
+
+    Ty::from_hir(&ctx, &data.ty)
+}
+
 pub(crate) fn impl_self_ty_recover(
     db: &dyn HirDatabase,
     _cycle: &[String],