Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/lower.rs')
-rw-r--r--crates/hir-ty/src/lower.rs45
1 files changed, 37 insertions, 8 deletions
diff --git a/crates/hir-ty/src/lower.rs b/crates/hir-ty/src/lower.rs
index 0cb1a2db26..ec42b8a349 100644
--- a/crates/hir-ty/src/lower.rs
+++ b/crates/hir-ty/src/lower.rs
@@ -18,9 +18,12 @@ use hir_def::{
TypeAliasId, TypeOrConstParamId, TypeParamId, UnionId, VariantId,
builtin_type::BuiltinType,
expr_store::{ExpressionStore, path::Path},
- hir::generics::{
- GenericParamDataRef, GenericParams, LocalTypeOrConstParamId, TypeOrConstParamData,
- TypeParamProvenance, WherePredicate,
+ hir::{
+ ExprId,
+ generics::{
+ GenericParamDataRef, GenericParams, LocalTypeOrConstParamId, TypeOrConstParamData,
+ TypeParamProvenance, WherePredicate,
+ },
},
item_tree::FieldsShape,
lang_item::LangItems,
@@ -60,10 +63,10 @@ use crate::{
next_solver::{
AliasTy, Binder, BoundExistentialPredicates, Clause, ClauseKind, Clauses, Const, ConstKind,
DbInterner, DefaultAny, EarlyBinder, EarlyParamRegion, ErrorGuaranteed, FnSigKind,
- FxIndexMap, GenericArg, GenericArgs, ParamConst, ParamEnv, PolyFnSig, Predicate, Region,
- StoredClauses, StoredEarlyBinder, StoredGenericArg, StoredGenericArgs, StoredPolyFnSig,
- StoredTraitRef, StoredTy, TraitPredicate, TraitRef, Ty, Tys, Unnormalized, abi::Safety,
- util::BottomUpFolder,
+ FxIndexMap, GenericArg, GenericArgs, ParamConst, ParamEnv, Pattern, PolyFnSig, Predicate,
+ Region, StoredClauses, StoredEarlyBinder, StoredGenericArg, StoredGenericArgs,
+ StoredPolyFnSig, StoredTraitRef, StoredTy, TraitPredicate, TraitRef, Ty, Tys, Unnormalized,
+ abi::Safety, util::BottomUpFolder,
},
};
@@ -357,6 +360,14 @@ impl<'db, 'a> TyLoweringContext<'db, 'a> {
}
pub(crate) fn lower_const(&mut self, const_ref: ConstRef, const_type: Ty<'db>) -> Const<'db> {
+ self.lower_expr_as_const(const_ref.expr, const_type)
+ }
+
+ pub(crate) fn lower_expr_as_const(
+ &mut self,
+ expr_id: ExprId,
+ const_type: Ty<'db>,
+ ) -> Const<'db> {
#[expect(clippy::manual_map, reason = "a `map()` here generates a borrowck error")]
let create_var = match &mut self.infer_vars {
Some(infer_vars) => Some(
@@ -368,7 +379,7 @@ impl<'db, 'a> TyLoweringContext<'db, 'a> {
self.interner,
self.def,
self.store,
- const_ref.expr,
+ expr_id,
self.resolver,
const_type,
&|| self.generics.get_or_init(|| generics(self.db, self.generic_def)),
@@ -528,6 +539,24 @@ impl<'db, 'a> TyLoweringContext<'db, 'a> {
}
}
}
+ &TypeRef::PatternType(ty, pat) => {
+ let ty = self.lower_ty(ty);
+ // FIXME: Properly do the lowering here
+ let pat_kind = match self.store[pat] {
+ hir_def::hir::Pat::Range {
+ start: Some(start),
+ end: Some(end),
+ range_type: _,
+ } => rustc_type_ir::PatternKind::Range {
+ start: self.lower_expr_as_const(start, ty),
+ end: self.lower_expr_as_const(end, ty),
+ },
+ hir_def::hir::Pat::NotNull => rustc_type_ir::PatternKind::NotNull,
+ _ => rustc_type_ir::PatternKind::NotNull,
+ };
+ let pat = Pattern::new(self.interner, pat_kind);
+ Ty::new_pat(self.interner, ty, pat)
+ }
TypeRef::Error => self.types.types.error,
};
(ty, res)