From 11f86641829273e2b2b7023c2028bb475fce58ee Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 11 Dec 2020 13:49:32 +0100 Subject: Add Lifetimes to the HIR --- crates/hir_def/src/item_tree/lower.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'crates/hir_def/src/item_tree/lower.rs') diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index 63b2826f8..f7ce2e26d 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs @@ -13,6 +13,7 @@ use syntax::{ use crate::{ attr::Attrs, generics::{GenericParams, TypeParamData, TypeParamProvenance}, + type_ref::LifetimeRef, }; use super::*; @@ -292,12 +293,16 @@ impl Ctx { let self_type = TypeRef::Path(name![Self].into()); match self_param.kind() { ast::SelfParamKind::Owned => self_type, - ast::SelfParamKind::Ref => { - TypeRef::Reference(Box::new(self_type), Mutability::Shared) - } - ast::SelfParamKind::MutRef => { - TypeRef::Reference(Box::new(self_type), Mutability::Mut) - } + ast::SelfParamKind::Ref => TypeRef::Reference( + Box::new(self_type), + self_param.lifetime_token().map(LifetimeRef::from_token), + Mutability::Shared, + ), + ast::SelfParamKind::MutRef => TypeRef::Reference( + Box::new(self_type), + self_param.lifetime_token().map(LifetimeRef::from_token), + Mutability::Mut, + ), } } }; @@ -629,8 +634,7 @@ impl Ctx { // add super traits as bounds on Self // i.e., trait Foo: Bar is equivalent to trait Foo where Self: Bar let self_param = TypeRef::Path(name![Self].into()); - generics.fill_bounds(&self.body_ctx, trait_def, self_param); - + generics.fill_bounds(&self.body_ctx, trait_def, Either::Left(self_param)); generics.fill(&self.body_ctx, &mut sm, node); } GenericsOwner::Impl => { -- cgit v1.2.3