aboutsummaryrefslogtreecommitdiff
path: root/crates/hir/src
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2020-12-15 18:23:51 +0000
committerLukas Wirth <[email protected]>2020-12-16 13:16:09 +0000
commitdd496223f50232fe98312ee8edc89eb4b5ee3d85 (patch)
tree4d50c04ca78f9458ab536ff1edee76eba6ab1957 /crates/hir/src
parentd34611633b3b2404188b9e12b08c5def589808c2 (diff)
Node-ify lifetimes
Diffstat (limited to 'crates/hir/src')
-rw-r--r--crates/hir/src/semantics.rs17
1 files changed, 6 insertions, 11 deletions
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs
index 5959ac4ca..ee2074602 100644
--- a/crates/hir/src/semantics.rs
+++ b/crates/hir/src/semantics.rs
@@ -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)