mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Merge #7080
7080: Implement ConstParams for HIR r=Veykril a=Veykril r? @flodiebold Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
0e5fe47153
28 changed files with 238 additions and 41 deletions
|
@ -5,8 +5,8 @@ use std::sync::Arc;
|
|||
use arena::map::ArenaMap;
|
||||
use base_db::{impl_intern_key, salsa, CrateId, Upcast};
|
||||
use hir_def::{
|
||||
db::DefDatabase, expr::ExprId, DefWithBodyId, FunctionId, GenericDefId, ImplId, LocalFieldId,
|
||||
TypeParamId, VariantId,
|
||||
db::DefDatabase, expr::ExprId, ConstParamId, DefWithBodyId, FunctionId, GenericDefId, ImplId,
|
||||
LocalFieldId, TypeParamId, VariantId,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
|
@ -37,6 +37,9 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
|
|||
#[salsa::cycle(crate::lower::impl_self_ty_recover)]
|
||||
fn impl_self_ty(&self, def: ImplId) -> Binders<Ty>;
|
||||
|
||||
#[salsa::invoke(crate::lower::const_param_ty_query)]
|
||||
fn const_param_ty(&self, def: ConstParamId) -> Ty;
|
||||
|
||||
#[salsa::invoke(crate::lower::impl_trait_query)]
|
||||
fn impl_trait(&self, def: ImplId) -> Option<Binders<TraitRef>>;
|
||||
|
||||
|
|
|
@ -89,6 +89,7 @@ impl<'a> InferenceContext<'a> {
|
|||
return None;
|
||||
}
|
||||
}
|
||||
ValueNs::GenericParam(it) => return Some(self.db.const_param_ty(it)),
|
||||
};
|
||||
|
||||
let ty = self.db.value_ty(typable);
|
||||
|
|
|
@ -16,9 +16,9 @@ use hir_def::{
|
|||
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;
|
||||
|
@ -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],
|
||||
|
|
|
@ -2375,3 +2375,19 @@ fn infer_operator_overload() {
|
|||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_const_params() {
|
||||
check_infer(
|
||||
r#"
|
||||
fn foo<const FOO: usize>() {
|
||||
let bar = FOO;
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
27..49 '{ ...FOO; }': ()
|
||||
37..40 'bar': usize
|
||||
43..46 'FOO': usize
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue