aboutsummaryrefslogtreecommitdiff
path: root/crates/hir/src/semantics.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir/src/semantics.rs')
-rw-r--r--crates/hir/src/semantics.rs23
1 files changed, 9 insertions, 14 deletions
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs
index 5959ac4ca..83ec91f58 100644
--- a/crates/hir/src/semantics.rs
+++ b/crates/hir/src/semantics.rs
@@ -25,7 +25,7 @@ use crate::{
25 diagnostics::Diagnostic, 25 diagnostics::Diagnostic,
26 semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx}, 26 semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx},
27 source_analyzer::{resolve_hir_path, SourceAnalyzer}, 27 source_analyzer::{resolve_hir_path, SourceAnalyzer},
28 AssocItem, Callable, Crate, Field, Function, HirFileId, ImplDef, InFile, LifetimeParam, Local, 28 AssocItem, Callable, Crate, Field, Function, HirFileId, Impl, InFile, LifetimeParam, Local,
29 MacroDef, Module, ModuleDef, Name, Path, ScopeDef, Trait, Type, TypeAlias, TypeParam, 29 MacroDef, Module, ModuleDef, Name, Path, ScopeDef, Trait, Type, TypeAlias, TypeParam,
30 VariantDef, 30 VariantDef,
31}; 31};
@@ -38,7 +38,7 @@ pub enum PathResolution {
38 Local(Local), 38 Local(Local),
39 /// A generic parameter 39 /// A generic parameter
40 TypeParam(TypeParam), 40 TypeParam(TypeParam),
41 SelfType(ImplDef), 41 SelfType(Impl),
42 Macro(MacroDef), 42 Macro(MacroDef),
43 AssocItem(AssocItem), 43 AssocItem(AssocItem),
44} 44}
@@ -178,9 +178,8 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
178 self.imp.descend_node_at_offset(node, offset).find_map(N::cast) 178 self.imp.descend_node_at_offset(node, offset).find_map(N::cast)
179 } 179 }
180 180
181 // FIXME: Replace the SyntaxToken with a typed ast Node/Token 181 pub fn resolve_lifetime_param(&self, lifetime: &ast::Lifetime) -> Option<LifetimeParam> {
182 pub fn resolve_lifetime_param(&self, lifetime_token: &SyntaxToken) -> Option<LifetimeParam> { 182 self.imp.resolve_lifetime_param(lifetime)
183 self.imp.resolve_lifetime_param(lifetime_token)
184 } 183 }
185 184
186 pub fn type_of_expr(&self, expr: &ast::Expr) -> Option<Type> { 185 pub fn type_of_expr(&self, expr: &ast::Expr) -> Option<Type> {
@@ -402,13 +401,9 @@ impl<'db> SemanticsImpl<'db> {
402 .kmerge_by(|node1, node2| node1.text_range().len() < node2.text_range().len()) 401 .kmerge_by(|node1, node2| node1.text_range().len() < node2.text_range().len())
403 } 402 }
404 403
405 // FIXME: Replace the SyntaxToken with a typed ast Node/Token 404 fn resolve_lifetime_param(&self, lifetime: &ast::Lifetime) -> Option<LifetimeParam> {
406 fn resolve_lifetime_param(&self, lifetime_token: &SyntaxToken) -> Option<LifetimeParam> { 405 let text = lifetime.text();
407 if lifetime_token.kind() != syntax::SyntaxKind::LIFETIME { 406 let lifetime_param = lifetime.syntax().ancestors().find_map(|syn| {
408 return None;
409 }
410 let lifetime_text = lifetime_token.text();
411 let lifetime_param = lifetime_token.parent().ancestors().find_map(|syn| {
412 let gpl = match_ast! { 407 let gpl = match_ast! {
413 match syn { 408 match syn {
414 ast::Fn(it) => it.generic_param_list()?, 409 ast::Fn(it) => it.generic_param_list()?,
@@ -424,7 +419,7 @@ impl<'db> SemanticsImpl<'db> {
424 } 419 }
425 }; 420 };
426 gpl.lifetime_params() 421 gpl.lifetime_params()
427 .find(|tp| tp.lifetime_token().as_ref().map(|lt| lt.text()) == Some(lifetime_text)) 422 .find(|tp| tp.lifetime().as_ref().map(|lt| lt.text()) == Some(text))
428 })?; 423 })?;
429 let src = self.find_file(lifetime_param.syntax().clone()).with_value(lifetime_param); 424 let src = self.find_file(lifetime_param.syntax().clone()).with_value(lifetime_param);
430 ToDef::to_def(self, src) 425 ToDef::to_def(self, src)
@@ -713,7 +708,7 @@ to_def_impls![
713 (crate::Enum, ast::Enum, enum_to_def), 708 (crate::Enum, ast::Enum, enum_to_def),
714 (crate::Union, ast::Union, union_to_def), 709 (crate::Union, ast::Union, union_to_def),
715 (crate::Trait, ast::Trait, trait_to_def), 710 (crate::Trait, ast::Trait, trait_to_def),
716 (crate::ImplDef, ast::Impl, impl_to_def), 711 (crate::Impl, ast::Impl, impl_to_def),
717 (crate::TypeAlias, ast::TypeAlias, type_alias_to_def), 712 (crate::TypeAlias, ast::TypeAlias, type_alias_to_def),
718 (crate::Const, ast::Const, const_to_def), 713 (crate::Const, ast::Const, const_to_def),
719 (crate::Static, ast::Static, static_to_def), 714 (crate::Static, ast::Static, static_to_def),