mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 06:41:48 +00:00
Merge #6896
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:
commit
067067a6c1
63 changed files with 420 additions and 274 deletions
|
@ -233,8 +233,7 @@ impl ExprCollector<'_> {
|
|||
let res = self.collect_block(block);
|
||||
match &mut self.body.exprs[res] {
|
||||
Expr::Block { label: block_label, .. } => {
|
||||
*block_label =
|
||||
label.lifetime_token().map(|t| Name::new_lifetime(&t))
|
||||
*block_label = label.lifetime().map(|t| Name::new_lifetime(&t))
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
@ -254,10 +253,7 @@ impl ExprCollector<'_> {
|
|||
self.alloc_expr(
|
||||
Expr::Loop {
|
||||
body,
|
||||
label: e
|
||||
.label()
|
||||
.and_then(|l| l.lifetime_token())
|
||||
.map(|l| Name::new_lifetime(&l)),
|
||||
label: e.label().and_then(|l| l.lifetime()).map(|l| Name::new_lifetime(&l)),
|
||||
},
|
||||
syntax_ptr,
|
||||
)
|
||||
|
@ -288,7 +284,7 @@ impl ExprCollector<'_> {
|
|||
body: match_expr,
|
||||
label: e
|
||||
.label()
|
||||
.and_then(|l| l.lifetime_token())
|
||||
.and_then(|l| l.lifetime())
|
||||
.map(|l| Name::new_lifetime(&l)),
|
||||
},
|
||||
syntax_ptr,
|
||||
|
@ -301,10 +297,7 @@ impl ExprCollector<'_> {
|
|||
Expr::While {
|
||||
condition,
|
||||
body,
|
||||
label: e
|
||||
.label()
|
||||
.and_then(|l| l.lifetime_token())
|
||||
.map(|l| Name::new_lifetime(&l)),
|
||||
label: e.label().and_then(|l| l.lifetime()).map(|l| Name::new_lifetime(&l)),
|
||||
},
|
||||
syntax_ptr,
|
||||
)
|
||||
|
@ -318,10 +311,7 @@ impl ExprCollector<'_> {
|
|||
iterable,
|
||||
pat,
|
||||
body,
|
||||
label: e
|
||||
.label()
|
||||
.and_then(|l| l.lifetime_token())
|
||||
.map(|l| Name::new_lifetime(&l)),
|
||||
label: e.label().and_then(|l| l.lifetime()).map(|l| Name::new_lifetime(&l)),
|
||||
},
|
||||
syntax_ptr,
|
||||
)
|
||||
|
@ -380,13 +370,13 @@ impl ExprCollector<'_> {
|
|||
self.alloc_expr(path, syntax_ptr)
|
||||
}
|
||||
ast::Expr::ContinueExpr(e) => self.alloc_expr(
|
||||
Expr::Continue { label: e.lifetime_token().map(|l| Name::new_lifetime(&l)) },
|
||||
Expr::Continue { label: e.lifetime().map(|l| Name::new_lifetime(&l)) },
|
||||
syntax_ptr,
|
||||
),
|
||||
ast::Expr::BreakExpr(e) => {
|
||||
let expr = e.expr().map(|e| self.collect_expr(e));
|
||||
self.alloc_expr(
|
||||
Expr::Break { expr, label: e.lifetime_token().map(|l| Name::new_lifetime(&l)) },
|
||||
Expr::Break { expr, label: e.lifetime().map(|l| Name::new_lifetime(&l)) },
|
||||
syntax_ptr,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -260,9 +260,8 @@ impl GenericParams {
|
|||
self.fill_bounds(&lower_ctx, &type_param, Either::Left(type_ref));
|
||||
}
|
||||
for lifetime_param in params.lifetime_params() {
|
||||
let name = lifetime_param
|
||||
.lifetime_token()
|
||||
.map_or_else(Name::missing, |tok| Name::new_lifetime(&tok));
|
||||
let name =
|
||||
lifetime_param.lifetime().map_or_else(Name::missing, |lt| Name::new_lifetime(<));
|
||||
let param = LifetimeParamData { name: name.clone() };
|
||||
let param_id = self.lifetimes.alloc(param);
|
||||
sm.lifetime_params.insert(param_id, lifetime_param.clone());
|
||||
|
@ -275,8 +274,8 @@ impl GenericParams {
|
|||
for pred in where_clause.predicates() {
|
||||
let target = if let Some(type_ref) = pred.ty() {
|
||||
Either::Left(TypeRef::from_ast(lower_ctx, type_ref))
|
||||
} else if let Some(lifetime_tok) = pred.lifetime_token() {
|
||||
Either::Right(LifetimeRef::from_token(lifetime_tok))
|
||||
} else if let Some(lifetime) = pred.lifetime() {
|
||||
Either::Right(LifetimeRef::new(&lifetime))
|
||||
} else {
|
||||
continue;
|
||||
};
|
||||
|
|
|
@ -300,12 +300,12 @@ impl Ctx {
|
|||
ast::SelfParamKind::Owned => self_type,
|
||||
ast::SelfParamKind::Ref => TypeRef::Reference(
|
||||
Box::new(self_type),
|
||||
self_param.lifetime_token().map(LifetimeRef::from_token),
|
||||
self_param.lifetime().as_ref().map(LifetimeRef::new),
|
||||
Mutability::Shared,
|
||||
),
|
||||
ast::SelfParamKind::MutRef => TypeRef::Reference(
|
||||
Box::new(self_type),
|
||||
self_param.lifetime_token().map(LifetimeRef::from_token),
|
||||
self_param.lifetime().as_ref().map(LifetimeRef::new),
|
||||
Mutability::Mut,
|
||||
),
|
||||
}
|
||||
|
|
|
@ -169,8 +169,8 @@ pub(super) fn lower_generic_args(
|
|||
}
|
||||
}
|
||||
ast::GenericArg::LifetimeArg(lifetime_arg) => {
|
||||
if let Some(lifetime) = lifetime_arg.lifetime_token() {
|
||||
let lifetime_ref = LifetimeRef::from_token(lifetime);
|
||||
if let Some(lifetime) = lifetime_arg.lifetime() {
|
||||
let lifetime_ref = LifetimeRef::new(&lifetime);
|
||||
args.push(GenericArg::Lifetime(lifetime_ref))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! HIR for references to types. Paths in these are not yet resolved. They can
|
||||
//! be directly created from an ast::TypeRef, without further queries.
|
||||
use hir_expand::name::Name;
|
||||
use syntax::{ast, SyntaxToken};
|
||||
use syntax::ast;
|
||||
|
||||
use crate::{body::LowerCtx, path::Path};
|
||||
|
||||
|
@ -80,8 +80,8 @@ impl LifetimeRef {
|
|||
LifetimeRef { name }
|
||||
}
|
||||
|
||||
pub(crate) fn from_token(token: SyntaxToken) -> Self {
|
||||
LifetimeRef { name: Name::new_lifetime(&token) }
|
||||
pub(crate) fn new(lifetime: &ast::Lifetime) -> Self {
|
||||
LifetimeRef { name: Name::new_lifetime(lifetime) }
|
||||
}
|
||||
|
||||
pub fn missing() -> LifetimeRef {
|
||||
|
@ -127,7 +127,7 @@ impl TypeRef {
|
|||
}
|
||||
ast::Type::RefType(inner) => {
|
||||
let inner_ty = TypeRef::from_ast_opt(&ctx, inner.ty());
|
||||
let lifetime = inner.lifetime_token().map(|t| LifetimeRef::from_token(t));
|
||||
let lifetime = inner.lifetime().map(|lt| LifetimeRef::new(<));
|
||||
let mutability = Mutability::from_mutable(inner.mut_token().is_some());
|
||||
TypeRef::Reference(Box::new(inner_ty), lifetime, mutability)
|
||||
}
|
||||
|
@ -259,7 +259,7 @@ impl TypeBound {
|
|||
}
|
||||
ast::TypeBoundKind::ForType(_) => TypeBound::Error, // FIXME ForType
|
||||
ast::TypeBoundKind::Lifetime(lifetime) => {
|
||||
TypeBound::Lifetime(LifetimeRef::from_token(lifetime))
|
||||
TypeBound::Lifetime(LifetimeRef::new(&lifetime))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue