mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
Switch to StaticLoc for statics
This commit is contained in:
parent
982a32aca3
commit
e0b06cb672
13 changed files with 65 additions and 28 deletions
|
@ -734,7 +734,7 @@ pub struct Static {
|
|||
|
||||
impl Static {
|
||||
pub fn module(self, db: &impl DefDatabase) -> Module {
|
||||
Module { id: self.id.module(db) }
|
||||
Module { id: self.id.lookup(db).module(db) }
|
||||
}
|
||||
|
||||
pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> {
|
||||
|
|
|
@ -88,7 +88,7 @@ impl HasSource for Const {
|
|||
impl HasSource for Static {
|
||||
type Ast = ast::StaticDef;
|
||||
fn source(self, db: &impl DefDatabase) -> Source<ast::StaticDef> {
|
||||
self.id.source(db)
|
||||
self.id.lookup(db).source(db)
|
||||
}
|
||||
}
|
||||
impl HasSource for Trait {
|
||||
|
|
|
@ -104,10 +104,21 @@ impl FromSource for Const {
|
|||
impl FromSource for Static {
|
||||
type Ast = ast::StaticDef;
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
|
||||
let id = from_source(db, src)?;
|
||||
Some(Static { id })
|
||||
let module = match Container::find(db, src.as_ref().map(|it| it.syntax()))? {
|
||||
Container::Module(it) => it,
|
||||
Container::Trait(_) | Container::ImplBlock(_) => return None,
|
||||
};
|
||||
module
|
||||
.declarations(db)
|
||||
.into_iter()
|
||||
.filter_map(|it| match it {
|
||||
ModuleDef::Static(it) => Some(it),
|
||||
_ => None,
|
||||
})
|
||||
.find(|it| same_source(&it.source(db), &src))
|
||||
}
|
||||
}
|
||||
|
||||
impl FromSource for TypeAlias {
|
||||
type Ast = ast::TypeAliasDef;
|
||||
fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
|
||||
|
|
|
@ -11,7 +11,7 @@ use hir_def::{
|
|||
expr::{ExprId, PatId},
|
||||
path::known,
|
||||
resolver::{self, resolver_for_scope, HasResolver, Resolver, TypeNs, ValueNs},
|
||||
DefWithBodyId, LocationCtx,
|
||||
DefWithBodyId,
|
||||
};
|
||||
use hir_expand::{
|
||||
name::AsName, AstId, HirFileId, MacroCallId, MacroCallLoc, MacroFileKind, Source,
|
||||
|
@ -28,8 +28,8 @@ use crate::{
|
|||
expr::{BodySourceMap, ExprScopes, ScopeId},
|
||||
ty::method_resolution::{self, implements_trait},
|
||||
Adt, AssocItem, Const, DefWithBody, Either, Enum, EnumVariant, FromSource, Function,
|
||||
GenericParam, HasBody, Local, MacroDef, Module, Name, Path, ScopeDef, Static, Struct, Trait,
|
||||
Ty, TypeAlias,
|
||||
GenericParam, HasBody, Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Ty,
|
||||
TypeAlias,
|
||||
};
|
||||
|
||||
fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -> Option<Resolver> {
|
||||
|
@ -68,16 +68,12 @@ fn def_with_body_from_child_node(
|
|||
db: &impl HirDatabase,
|
||||
child: Source<&SyntaxNode>,
|
||||
) -> Option<DefWithBody> {
|
||||
let module_source = crate::ModuleSource::from_child_node(db, child);
|
||||
let module = Module::from_definition(db, Source::new(child.file_id, module_source))?;
|
||||
let ctx = LocationCtx::new(db, module.id, child.file_id);
|
||||
|
||||
child.value.ancestors().find_map(|node| {
|
||||
match_ast! {
|
||||
match node {
|
||||
ast::FnDef(def) => { return Function::from_source(db, child.with_value(def)).map(DefWithBody::from); },
|
||||
ast::ConstDef(def) => { return Const::from_source(db, child.with_value(def)).map(DefWithBody::from); },
|
||||
ast::StaticDef(def) => { Some(Static { id: ctx.to_def(&def) }.into()) },
|
||||
ast::StaticDef(def) => { return Static::from_source(db, child.with_value(def)).map(DefWithBody::from); },
|
||||
_ => { None },
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2550,8 +2550,6 @@ fn test() {
|
|||
[233; 246) 'GLOBAL_STATIC': u32
|
||||
[256; 257) 'w': u32
|
||||
[260; 277) 'GLOBAL...IC_MUT': u32
|
||||
[118; 120) '99': u32
|
||||
[161; 163) '99': u32
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue