From dd496223f50232fe98312ee8edc89eb4b5ee3d85 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 15 Dec 2020 19:23:51 +0100 Subject: Node-ify lifetimes --- crates/hir_def/src/body/lower.rs | 24 +++++++----------------- crates/hir_def/src/generics.rs | 9 ++++----- crates/hir_def/src/item_tree/lower.rs | 4 ++-- crates/hir_def/src/path/lower.rs | 4 ++-- crates/hir_def/src/type_ref.rs | 10 +++++----- 5 files changed, 20 insertions(+), 31 deletions(-) (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs index 23e2fd764..3b3d74987 100644 --- a/crates/hir_def/src/body/lower.rs +++ b/crates/hir_def/src/body/lower.rs @@ -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, ) } diff --git a/crates/hir_def/src/generics.rs b/crates/hir_def/src/generics.rs index 81912a454..bc0125f0b 100644 --- a/crates/hir_def/src/generics.rs +++ b/crates/hir_def/src/generics.rs @@ -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; }; diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index 1dc06a211..dd3409762 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs @@ -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, ), } diff --git a/crates/hir_def/src/path/lower.rs b/crates/hir_def/src/path/lower.rs index 609925012..8a01e6eea 100644 --- a/crates/hir_def/src/path/lower.rs +++ b/crates/hir_def/src/path/lower.rs @@ -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)) } } diff --git a/crates/hir_def/src/type_ref.rs b/crates/hir_def/src/type_ref.rs index 347ceabb9..ae93d0d10 100644 --- a/crates/hir_def/src/type_ref.rs +++ b/crates/hir_def/src/type_ref.rs @@ -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)) } } } -- cgit v1.2.3