mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Add const type inference
This commit is contained in:
parent
7ffff9c74c
commit
18b0bd9bff
11 changed files with 168 additions and 20 deletions
|
@ -554,11 +554,26 @@ impl Const {
|
|||
self.id.module(db)
|
||||
}
|
||||
|
||||
pub fn signature(&self, db: &impl HirDatabase) -> Arc<ConstSignature> {
|
||||
db.const_signature(*self)
|
||||
}
|
||||
|
||||
/// The containing impl block, if this is a method.
|
||||
pub fn impl_block(&self, db: &impl PersistentHirDatabase) -> Option<ImplBlock> {
|
||||
let module_impls = db.impls_in_module(self.module(db));
|
||||
ImplBlock::containing(module_impls, (*self).into())
|
||||
}
|
||||
|
||||
// TODO: move to a more general type for 'body-having' items
|
||||
/// Builds a resolver for code inside this item.
|
||||
pub fn resolver(&self, db: &impl HirDatabase) -> Resolver {
|
||||
// take the outer scope...
|
||||
let r = self
|
||||
.impl_block(db)
|
||||
.map(|ib| ib.resolver(db))
|
||||
.unwrap_or_else(|| self.module(db).resolver(db));
|
||||
r
|
||||
}
|
||||
}
|
||||
|
||||
impl Docs for Const {
|
||||
|
@ -567,6 +582,23 @@ impl Docs for Const {
|
|||
}
|
||||
}
|
||||
|
||||
/// The declared signature of a const.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct ConstSignature {
|
||||
pub(crate) name: Name,
|
||||
pub(crate) type_ref: TypeRef,
|
||||
}
|
||||
|
||||
impl ConstSignature {
|
||||
pub fn name(&self) -> &Name {
|
||||
&self.name
|
||||
}
|
||||
|
||||
pub fn type_ref(&self) -> &TypeRef {
|
||||
&self.type_ref
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct Static {
|
||||
pub(crate) id: StaticId,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue