aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_def/src')
-rw-r--r--crates/hir_def/src/body/lower.rs24
-rw-r--r--crates/hir_def/src/generics.rs9
-rw-r--r--crates/hir_def/src/item_tree/lower.rs4
-rw-r--r--crates/hir_def/src/path/lower.rs4
-rw-r--r--crates/hir_def/src/type_ref.rs10
5 files changed, 20 insertions, 31 deletions
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<'_> {
233 let res = self.collect_block(block); 233 let res = self.collect_block(block);
234 match &mut self.body.exprs[res] { 234 match &mut self.body.exprs[res] {
235 Expr::Block { label: block_label, .. } => { 235 Expr::Block { label: block_label, .. } => {
236 *block_label = 236 *block_label = label.lifetime().map(|t| Name::new_lifetime(&t))
237 label.lifetime_token().map(|t| Name::new_lifetime(&t))
238 } 237 }
239 _ => unreachable!(), 238 _ => unreachable!(),
240 } 239 }
@@ -254,10 +253,7 @@ impl ExprCollector<'_> {
254 self.alloc_expr( 253 self.alloc_expr(
255 Expr::Loop { 254 Expr::Loop {
256 body, 255 body,
257 label: e 256 label: e.label().and_then(|l| l.lifetime()).map(|l| Name::new_lifetime(&l)),
258 .label()
259 .and_then(|l| l.lifetime_token())
260 .map(|l| Name::new_lifetime(&l)),
261 }, 257 },
262 syntax_ptr, 258 syntax_ptr,
263 ) 259 )
@@ -288,7 +284,7 @@ impl ExprCollector<'_> {
288 body: match_expr, 284 body: match_expr,
289 label: e 285 label: e
290 .label() 286 .label()
291 .and_then(|l| l.lifetime_token()) 287 .and_then(|l| l.lifetime())
292 .map(|l| Name::new_lifetime(&l)), 288 .map(|l| Name::new_lifetime(&l)),
293 }, 289 },
294 syntax_ptr, 290 syntax_ptr,
@@ -301,10 +297,7 @@ impl ExprCollector<'_> {
301 Expr::While { 297 Expr::While {
302 condition, 298 condition,
303 body, 299 body,
304 label: e 300 label: e.label().and_then(|l| l.lifetime()).map(|l| Name::new_lifetime(&l)),
305 .label()
306 .and_then(|l| l.lifetime_token())
307 .map(|l| Name::new_lifetime(&l)),
308 }, 301 },
309 syntax_ptr, 302 syntax_ptr,
310 ) 303 )
@@ -318,10 +311,7 @@ impl ExprCollector<'_> {
318 iterable, 311 iterable,
319 pat, 312 pat,
320 body, 313 body,
321 label: e 314 label: e.label().and_then(|l| l.lifetime()).map(|l| Name::new_lifetime(&l)),
322 .label()
323 .and_then(|l| l.lifetime_token())
324 .map(|l| Name::new_lifetime(&l)),
325 }, 315 },
326 syntax_ptr, 316 syntax_ptr,
327 ) 317 )
@@ -380,13 +370,13 @@ impl ExprCollector<'_> {
380 self.alloc_expr(path, syntax_ptr) 370 self.alloc_expr(path, syntax_ptr)
381 } 371 }
382 ast::Expr::ContinueExpr(e) => self.alloc_expr( 372 ast::Expr::ContinueExpr(e) => self.alloc_expr(
383 Expr::Continue { label: e.lifetime_token().map(|l| Name::new_lifetime(&l)) }, 373 Expr::Continue { label: e.lifetime().map(|l| Name::new_lifetime(&l)) },
384 syntax_ptr, 374 syntax_ptr,
385 ), 375 ),
386 ast::Expr::BreakExpr(e) => { 376 ast::Expr::BreakExpr(e) => {
387 let expr = e.expr().map(|e| self.collect_expr(e)); 377 let expr = e.expr().map(|e| self.collect_expr(e));
388 self.alloc_expr( 378 self.alloc_expr(
389 Expr::Break { expr, label: e.lifetime_token().map(|l| Name::new_lifetime(&l)) }, 379 Expr::Break { expr, label: e.lifetime().map(|l| Name::new_lifetime(&l)) },
390 syntax_ptr, 380 syntax_ptr,
391 ) 381 )
392 } 382 }
diff --git a/crates/hir_def/src/generics.rs b/crates/hir_def/src/generics.rs
index 924046435..41134d23b 100644
--- a/crates/hir_def/src/generics.rs
+++ b/crates/hir_def/src/generics.rs
@@ -260,9 +260,8 @@ impl GenericParams {
260 self.fill_bounds(&lower_ctx, &type_param, Either::Left(type_ref)); 260 self.fill_bounds(&lower_ctx, &type_param, Either::Left(type_ref));
261 } 261 }
262 for lifetime_param in params.lifetime_params() { 262 for lifetime_param in params.lifetime_params() {
263 let name = lifetime_param 263 let name =
264 .lifetime_token() 264 lifetime_param.lifetime().map_or_else(Name::missing, |lt| Name::new_lifetime(&lt));
265 .map_or_else(Name::missing, |tok| Name::new_lifetime(&tok));
266 let param = LifetimeParamData { name: name.clone() }; 265 let param = LifetimeParamData { name: name.clone() };
267 let param_id = self.lifetimes.alloc(param); 266 let param_id = self.lifetimes.alloc(param);
268 sm.lifetime_params.insert(param_id, lifetime_param.clone()); 267 sm.lifetime_params.insert(param_id, lifetime_param.clone());
@@ -275,8 +274,8 @@ impl GenericParams {
275 for pred in where_clause.predicates() { 274 for pred in where_clause.predicates() {
276 let target = if let Some(type_ref) = pred.ty() { 275 let target = if let Some(type_ref) = pred.ty() {
277 Either::Left(TypeRef::from_ast(lower_ctx, type_ref)) 276 Either::Left(TypeRef::from_ast(lower_ctx, type_ref))
278 } else if let Some(lifetime_tok) = pred.lifetime_token() { 277 } else if let Some(lifetime) = pred.lifetime() {
279 Either::Right(LifetimeRef::from_token(lifetime_tok)) 278 Either::Right(LifetimeRef::new(&lifetime))
280 } else { 279 } else {
281 continue; 280 continue;
282 }; 281 };
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 {
300 ast::SelfParamKind::Owned => self_type, 300 ast::SelfParamKind::Owned => self_type,
301 ast::SelfParamKind::Ref => TypeRef::Reference( 301 ast::SelfParamKind::Ref => TypeRef::Reference(
302 Box::new(self_type), 302 Box::new(self_type),
303 self_param.lifetime_token().map(LifetimeRef::from_token), 303 self_param.lifetime().as_ref().map(LifetimeRef::new),
304 Mutability::Shared, 304 Mutability::Shared,
305 ), 305 ),
306 ast::SelfParamKind::MutRef => TypeRef::Reference( 306 ast::SelfParamKind::MutRef => TypeRef::Reference(
307 Box::new(self_type), 307 Box::new(self_type),
308 self_param.lifetime_token().map(LifetimeRef::from_token), 308 self_param.lifetime().as_ref().map(LifetimeRef::new),
309 Mutability::Mut, 309 Mutability::Mut,
310 ), 310 ),
311 } 311 }
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(
169 } 169 }
170 } 170 }
171 ast::GenericArg::LifetimeArg(lifetime_arg) => { 171 ast::GenericArg::LifetimeArg(lifetime_arg) => {
172 if let Some(lifetime) = lifetime_arg.lifetime_token() { 172 if let Some(lifetime) = lifetime_arg.lifetime() {
173 let lifetime_ref = LifetimeRef::from_token(lifetime); 173 let lifetime_ref = LifetimeRef::new(&lifetime);
174 args.push(GenericArg::Lifetime(lifetime_ref)) 174 args.push(GenericArg::Lifetime(lifetime_ref))
175 } 175 }
176 } 176 }
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 @@
1//! HIR for references to types. Paths in these are not yet resolved. They can 1//! HIR for references to types. Paths in these are not yet resolved. They can
2//! be directly created from an ast::TypeRef, without further queries. 2//! be directly created from an ast::TypeRef, without further queries.
3use hir_expand::name::Name; 3use hir_expand::name::Name;
4use syntax::{ast, SyntaxToken}; 4use syntax::ast;
5 5
6use crate::{body::LowerCtx, path::Path}; 6use crate::{body::LowerCtx, path::Path};
7 7
@@ -80,8 +80,8 @@ impl LifetimeRef {
80 LifetimeRef { name } 80 LifetimeRef { name }
81 } 81 }
82 82
83 pub(crate) fn from_token(token: SyntaxToken) -> Self { 83 pub(crate) fn new(lifetime: &ast::Lifetime) -> Self {
84 LifetimeRef { name: Name::new_lifetime(&token) } 84 LifetimeRef { name: Name::new_lifetime(lifetime) }
85 } 85 }
86 86
87 pub fn missing() -> LifetimeRef { 87 pub fn missing() -> LifetimeRef {
@@ -127,7 +127,7 @@ impl TypeRef {
127 } 127 }
128 ast::Type::RefType(inner) => { 128 ast::Type::RefType(inner) => {
129 let inner_ty = TypeRef::from_ast_opt(&ctx, inner.ty()); 129 let inner_ty = TypeRef::from_ast_opt(&ctx, inner.ty());
130 let lifetime = inner.lifetime_token().map(|t| LifetimeRef::from_token(t)); 130 let lifetime = inner.lifetime().map(|lt| LifetimeRef::new(&lt));
131 let mutability = Mutability::from_mutable(inner.mut_token().is_some()); 131 let mutability = Mutability::from_mutable(inner.mut_token().is_some());
132 TypeRef::Reference(Box::new(inner_ty), lifetime, mutability) 132 TypeRef::Reference(Box::new(inner_ty), lifetime, mutability)
133 } 133 }
@@ -259,7 +259,7 @@ impl TypeBound {
259 } 259 }
260 ast::TypeBoundKind::ForType(_) => TypeBound::Error, // FIXME ForType 260 ast::TypeBoundKind::ForType(_) => TypeBound::Error, // FIXME ForType
261 ast::TypeBoundKind::Lifetime(lifetime) => { 261 ast::TypeBoundKind::Lifetime(lifetime) => {
262 TypeBound::Lifetime(LifetimeRef::from_token(lifetime)) 262 TypeBound::Lifetime(LifetimeRef::new(&lifetime))
263 } 263 }
264 } 264 }
265 } 265 }