6896: Node-ify lifetimes r=jonas-schievink a=Veykril

Let's see if this passes the tests 🤞 

Depends on https://github.com/rust-analyzer/ungrammar/pull/15

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
bors[bot] 2020-12-16 17:08:03 +00:00 committed by GitHub
commit 067067a6c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
63 changed files with 420 additions and 274 deletions

View file

@ -178,9 +178,8 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
self.imp.descend_node_at_offset(node, offset).find_map(N::cast)
}
// FIXME: Replace the SyntaxToken with a typed ast Node/Token
pub fn resolve_lifetime_param(&self, lifetime_token: &SyntaxToken) -> Option<LifetimeParam> {
self.imp.resolve_lifetime_param(lifetime_token)
pub fn resolve_lifetime_param(&self, lifetime: &ast::Lifetime) -> Option<LifetimeParam> {
self.imp.resolve_lifetime_param(lifetime)
}
pub fn type_of_expr(&self, expr: &ast::Expr) -> Option<Type> {
@ -402,13 +401,9 @@ impl<'db> SemanticsImpl<'db> {
.kmerge_by(|node1, node2| node1.text_range().len() < node2.text_range().len())
}
// FIXME: Replace the SyntaxToken with a typed ast Node/Token
fn resolve_lifetime_param(&self, lifetime_token: &SyntaxToken) -> Option<LifetimeParam> {
if lifetime_token.kind() != syntax::SyntaxKind::LIFETIME {
return None;
}
let lifetime_text = lifetime_token.text();
let lifetime_param = lifetime_token.parent().ancestors().find_map(|syn| {
fn resolve_lifetime_param(&self, lifetime: &ast::Lifetime) -> Option<LifetimeParam> {
let text = lifetime.text();
let lifetime_param = lifetime.syntax().ancestors().find_map(|syn| {
let gpl = match_ast! {
match syn {
ast::Fn(it) => it.generic_param_list()?,
@ -424,7 +419,7 @@ impl<'db> SemanticsImpl<'db> {
}
};
gpl.lifetime_params()
.find(|tp| tp.lifetime_token().as_ref().map(|lt| lt.text()) == Some(lifetime_text))
.find(|tp| tp.lifetime().as_ref().map(|lt| lt.text()) == Some(text))
})?;
let src = self.find_file(lifetime_param.syntax().clone()).with_value(lifetime_param);
ToDef::to_def(self, src)