From 4992d2bf79e9da6db759eb8e1715f90f31ec7eb9 Mon Sep 17 00:00:00 2001 From: oxalica Date: Fri, 29 Nov 2019 03:10:16 +0800 Subject: Infer range types --- crates/ra_hir_def/src/body/lower.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_def/src/body/lower.rs') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 331736cb2..d18964d54 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -8,7 +8,7 @@ use hir_expand::{ use ra_arena::Arena; use ra_syntax::{ ast::{ - self, ArgListOwner, ArrayExprKind, LiteralKind, LoopBodyOwner, NameOwner, + self, ArgListOwner, ArrayExprKind, LiteralKind, LoopBodyOwner, NameOwner, RangeOp, TypeAscriptionOwner, }, AstNode, AstPtr, @@ -429,10 +429,28 @@ where let index = self.collect_expr_opt(e.index()); self.alloc_expr(Expr::Index { base, index }, syntax_ptr) } + ast::Expr::RangeExpr(e) => { + let lhs = e.start().map(|lhs| self.collect_expr(lhs)); + let rhs = e.end().map(|rhs| self.collect_expr(rhs)); + match (lhs, e.op_kind(), rhs) { + (None, _, None) => self.alloc_expr(Expr::RangeFull, syntax_ptr), + (Some(lhs), _, None) => self.alloc_expr(Expr::RangeFrom { lhs }, syntax_ptr), + (None, Some(RangeOp::Inclusive), Some(rhs)) => { + self.alloc_expr(Expr::RangeToInclusive { rhs }, syntax_ptr) + } + (Some(lhs), Some(RangeOp::Inclusive), Some(rhs)) => { + self.alloc_expr(Expr::RangeInclusive { lhs, rhs }, syntax_ptr) + } + // If RangeOp is missing, fallback to exclusive range. + (None, _, Some(rhs)) => self.alloc_expr(Expr::RangeTo { rhs }, syntax_ptr), + (Some(lhs), _, Some(rhs)) => { + self.alloc_expr(Expr::Range { lhs, rhs }, syntax_ptr) + } + } + } // FIXME implement HIR for these: ast::Expr::Label(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), - ast::Expr::RangeExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), ast::Expr::MacroCall(e) => match self.expander.enter_expand(self.db, e) { Some((mark, expansion)) => { let id = self.collect_expr(expansion); -- cgit v1.2.3 From 2cb684bbce1c487b2efb5a8154afe66e4907ceac Mon Sep 17 00:00:00 2001 From: oxalica Date: Fri, 29 Nov 2019 14:49:12 +0800 Subject: Reduce variants of Expr --- crates/ra_hir_def/src/body/lower.rs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'crates/ra_hir_def/src/body/lower.rs') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index d18964d54..be1eaa523 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -8,7 +8,7 @@ use hir_expand::{ use ra_arena::Arena; use ra_syntax::{ ast::{ - self, ArgListOwner, ArrayExprKind, LiteralKind, LoopBodyOwner, NameOwner, RangeOp, + self, ArgListOwner, ArrayExprKind, LiteralKind, LoopBodyOwner, NameOwner, TypeAscriptionOwner, }, AstNode, AstPtr, @@ -432,20 +432,11 @@ where ast::Expr::RangeExpr(e) => { let lhs = e.start().map(|lhs| self.collect_expr(lhs)); let rhs = e.end().map(|rhs| self.collect_expr(rhs)); - match (lhs, e.op_kind(), rhs) { - (None, _, None) => self.alloc_expr(Expr::RangeFull, syntax_ptr), - (Some(lhs), _, None) => self.alloc_expr(Expr::RangeFrom { lhs }, syntax_ptr), - (None, Some(RangeOp::Inclusive), Some(rhs)) => { - self.alloc_expr(Expr::RangeToInclusive { rhs }, syntax_ptr) - } - (Some(lhs), Some(RangeOp::Inclusive), Some(rhs)) => { - self.alloc_expr(Expr::RangeInclusive { lhs, rhs }, syntax_ptr) - } - // If RangeOp is missing, fallback to exclusive range. - (None, _, Some(rhs)) => self.alloc_expr(Expr::RangeTo { rhs }, syntax_ptr), - (Some(lhs), _, Some(rhs)) => { - self.alloc_expr(Expr::Range { lhs, rhs }, syntax_ptr) + match e.op_kind() { + Some(range_type) => { + self.alloc_expr(Expr::Range { lhs, rhs, range_type }, syntax_ptr) } + None => self.alloc_expr(Expr::Missing, syntax_ptr), } } -- cgit v1.2.3 From 009437f5d9949d2276aa26040e03af0ab328acf3 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Tue, 3 Dec 2019 11:07:56 -0500 Subject: Replace `ra_hir_expand::either` with crate --- crates/ra_hir_def/src/body/lower.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'crates/ra_hir_def/src/body/lower.rs') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index be1eaa523..71c08f024 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -1,10 +1,8 @@ //! Transforms `ast::Expr` into an equivalent `hir_def::expr::Expr` //! representation. -use hir_expand::{ - either::Either, - name::{self, AsName, Name}, -}; +use either::Either; +use hir_expand::name::{self, AsName, Name}; use ra_arena::Arena; use ra_syntax::{ ast::{ @@ -74,7 +72,7 @@ where mode: BindingAnnotation::Unannotated, subpat: None, }, - Either::B(ptr), + Either::Right(ptr), ); self.body.params.push(param_pat); } @@ -94,7 +92,7 @@ where } fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr) -> ExprId { - let ptr = Either::A(ptr); + let ptr = Either::Left(ptr); let id = self.body.exprs.alloc(expr); let src = self.expander.to_source(ptr); self.source_map.expr_map.insert(src, id); @@ -107,7 +105,7 @@ where self.body.exprs.alloc(expr) } fn alloc_expr_field_shorthand(&mut self, expr: Expr, ptr: AstPtr) -> ExprId { - let ptr = Either::B(ptr); + let ptr = Either::Right(ptr); let id = self.body.exprs.alloc(expr); let src = self.expander.to_source(ptr); self.source_map.expr_map.insert(src, id); @@ -277,7 +275,7 @@ where ast::Expr::ParenExpr(e) => { let inner = self.collect_expr_opt(e.expr()); // make the paren expr point to the inner expression as well - let src = self.expander.to_source(Either::A(syntax_ptr)); + let src = self.expander.to_source(Either::Left(syntax_ptr)); self.source_map.expr_map.insert(src, inner); inner } @@ -550,7 +548,7 @@ where ast::Pat::SlicePat(_) | ast::Pat::RangePat(_) => Pat::Missing, }; let ptr = AstPtr::new(&pat); - self.alloc_pat(pattern, Either::A(ptr)) + self.alloc_pat(pattern, Either::Left(ptr)) } fn collect_pat_opt(&mut self, pat: Option) -> PatId { -- cgit v1.2.3 From 5e096def15e992938b0e2838ae6c344939aa10f2 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 8 Dec 2019 12:50:49 +0100 Subject: Expand macros in blocks to expressions for now Expanding to statements isn't handled properly yet and breaks things. --- crates/ra_hir_def/src/body/lower.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir_def/src/body/lower.rs') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 71c08f024..cc068ff94 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -437,9 +437,7 @@ where None => self.alloc_expr(Expr::Missing, syntax_ptr), } } - - // FIXME implement HIR for these: - ast::Expr::Label(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), + // FIXME expand to statements in statement position ast::Expr::MacroCall(e) => match self.expander.enter_expand(self.db, e) { Some((mark, expansion)) => { let id = self.collect_expr(expansion); @@ -448,6 +446,9 @@ where } None => self.alloc_expr(Expr::Missing, syntax_ptr), }, + + // FIXME implement HIR for these: + ast::Expr::Label(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), } } -- cgit v1.2.3 From 259c42f00e2e85594c7373166bc8467ce375a045 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 13 Dec 2019 21:43:53 +0100 Subject: Add macros for known names and paths --- crates/ra_hir_def/src/body/lower.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_def/src/body/lower.rs') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index cc068ff94..6c760166f 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -2,7 +2,7 @@ //! representation. use either::Either; -use hir_expand::name::{self, AsName, Name}; +use hir_expand::name::{AsName, Name, N}; use ra_arena::Arena; use ra_syntax::{ ast::{ @@ -68,7 +68,7 @@ where let ptr = AstPtr::new(&self_param); let param_pat = self.alloc_pat( Pat::Bind { - name: name::SELF_PARAM, + name: N![self], mode: BindingAnnotation::Unannotated, subpat: None, }, -- cgit v1.2.3 From 6911bc89a784ce72b4dfd8e0ba72bd22ce898395 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 13 Dec 2019 22:01:06 +0100 Subject: Rename N! to name! --- crates/ra_hir_def/src/body/lower.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_def/src/body/lower.rs') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 6c760166f..61193b4d8 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -2,7 +2,7 @@ //! representation. use either::Either; -use hir_expand::name::{AsName, Name, N}; +use hir_expand::name::{name, AsName, Name}; use ra_arena::Arena; use ra_syntax::{ ast::{ @@ -68,7 +68,7 @@ where let ptr = AstPtr::new(&self_param); let param_pat = self.alloc_pat( Pat::Bind { - name: N![self], + name: name![self], mode: BindingAnnotation::Unannotated, subpat: None, }, -- cgit v1.2.3 From 5bd8de3f5e11732d67d0cc9bacda7d3a1b7cf13a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 19 Dec 2019 17:30:28 +0100 Subject: Allow storing defs in bodies --- crates/ra_hir_def/src/body/lower.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'crates/ra_hir_def/src/body/lower.rs') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 61193b4d8..86960186f 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -41,6 +41,7 @@ pub(super) fn lower( pats: Arena::default(), params: Vec::new(), body_expr: ExprId::dummy(), + defs: Vec::new(), }, } .collect(params, body) -- cgit v1.2.3 From a04177f135be89ddbf1788c6f747c26812e90438 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 20 Dec 2019 11:19:09 +0100 Subject: Add local functions to bodies --- crates/ra_hir_def/src/body/lower.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_def/src/body/lower.rs') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 86960186f..17efa10e2 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -2,11 +2,12 @@ //! representation. use either::Either; + use hir_expand::name::{name, AsName, Name}; use ra_arena::Arena; use ra_syntax::{ ast::{ - self, ArgListOwner, ArrayExprKind, LiteralKind, LoopBodyOwner, NameOwner, + self, ArgListOwner, ArrayExprKind, LiteralKind, LoopBodyOwner, ModuleItemOwner, NameOwner, TypeAscriptionOwner, }, AstNode, AstPtr, @@ -24,17 +25,20 @@ use crate::{ path::GenericArgs, path::Path, type_ref::{Mutability, TypeRef}, + ContainerId, DefWithBodyId, FunctionLoc, Intern, }; pub(super) fn lower( db: &impl DefDatabase, + def: DefWithBodyId, expander: Expander, params: Option, body: Option, ) -> (Body, BodySourceMap) { ExprCollector { - expander, db, + def, + expander, source_map: BodySourceMap::default(), body: Body { exprs: Arena::default(), @@ -49,6 +53,7 @@ pub(super) fn lower( struct ExprCollector { db: DB, + def: DefWithBodyId, expander: Expander, body: Body, @@ -467,6 +472,7 @@ where Some(block) => block, None => return self.alloc_expr(Expr::Missing, syntax_node_ptr), }; + self.collect_block_items(&block); let statements = block .statements() .map(|s| match s { @@ -483,6 +489,20 @@ where self.alloc_expr(Expr::Block { statements, tail }, syntax_node_ptr) } + fn collect_block_items(&mut self, block: &ast::Block) { + let container = ContainerId::DefWithBodyId(self.def); + for item in block.items() { + match item { + ast::ModuleItem::FnDef(def) => { + let ast_id = self.expander.ast_id(&def); + self.body.defs.push(FunctionLoc { container, ast_id }.intern(self.db).into()) + } + // FIXME: handle other items + _ => (), + } + } + } + fn collect_block_opt(&mut self, expr: Option) -> ExprId { if let Some(block) = expr { self.collect_block(block) -- cgit v1.2.3 From 8fc20b65035d93bcc1b3a89127916bd165a8d938 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 20 Dec 2019 11:59:50 +0100 Subject: Rename ContainerId -> AssocContainerId --- crates/ra_hir_def/src/body/lower.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_def/src/body/lower.rs') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 17efa10e2..afd5231cc 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -25,7 +25,7 @@ use crate::{ path::GenericArgs, path::Path, type_ref::{Mutability, TypeRef}, - ContainerId, DefWithBodyId, FunctionLoc, Intern, + AssocContainerId, DefWithBodyId, FunctionLoc, Intern, }; pub(super) fn lower( @@ -490,7 +490,7 @@ where } fn collect_block_items(&mut self, block: &ast::Block) { - let container = ContainerId::DefWithBodyId(self.def); + let container = AssocContainerId::DefWithBodyId(self.def); for item in block.items() { match item { ast::ModuleItem::FnDef(def) => { -- cgit v1.2.3 From 94ad07af4bef6a70602e315bf315c6fce95618dd Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 20 Dec 2019 12:07:23 +0100 Subject: Introduce `ContainerId` --- crates/ra_hir_def/src/body/lower.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_def/src/body/lower.rs') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index afd5231cc..0103a1aab 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -25,7 +25,7 @@ use crate::{ path::GenericArgs, path::Path, type_ref::{Mutability, TypeRef}, - AssocContainerId, DefWithBodyId, FunctionLoc, Intern, + ContainerId, DefWithBodyId, FunctionLoc, Intern, }; pub(super) fn lower( @@ -490,7 +490,7 @@ where } fn collect_block_items(&mut self, block: &ast::Block) { - let container = AssocContainerId::DefWithBodyId(self.def); + let container = ContainerId::DefWithBodyId(self.def).into(); for item in block.items() { match item { ast::ModuleItem::FnDef(def) => { -- cgit v1.2.3 From ac5a3f611b05dbedd286169539335ae9f0fbb7b0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 20 Dec 2019 12:20:49 +0100 Subject: Support for nested ADT --- crates/ra_hir_def/src/body/lower.rs | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'crates/ra_hir_def/src/body/lower.rs') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 0103a1aab..0d3f946df 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -25,7 +25,7 @@ use crate::{ path::GenericArgs, path::Path, type_ref::{Mutability, TypeRef}, - ContainerId, DefWithBodyId, FunctionLoc, Intern, + ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId, StructLoc, UnionLoc, }; pub(super) fn lower( @@ -490,16 +490,28 @@ where } fn collect_block_items(&mut self, block: &ast::Block) { - let container = ContainerId::DefWithBodyId(self.def).into(); + let container = ContainerId::DefWithBodyId(self.def); for item in block.items() { - match item { + let def: ModuleDefId = match item { ast::ModuleItem::FnDef(def) => { let ast_id = self.expander.ast_id(&def); - self.body.defs.push(FunctionLoc { container, ast_id }.intern(self.db).into()) + FunctionLoc { container: container.into(), ast_id }.intern(self.db).into() } - // FIXME: handle other items - _ => (), - } + ast::ModuleItem::StructDef(def) => { + let ast_id = self.expander.ast_id(&def); + StructLoc { container, ast_id }.intern(self.db).into() + } + ast::ModuleItem::EnumDef(def) => { + let ast_id = self.expander.ast_id(&def); + EnumLoc { container, ast_id }.intern(self.db).into() + } + ast::ModuleItem::UnionDef(def) => { + let ast_id = self.expander.ast_id(&def); + UnionLoc { container, ast_id }.intern(self.db).into() + } + _ => continue, + }; + self.body.defs.push(def) } } -- cgit v1.2.3 From fe1b160dcfdeb3f582ccae1440c9580ade0beb39 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 20 Dec 2019 12:22:55 +0100 Subject: Support for nested statics, consts and type aliases --- crates/ra_hir_def/src/body/lower.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir_def/src/body/lower.rs') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 0d3f946df..b61f924b7 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -25,7 +25,8 @@ use crate::{ path::GenericArgs, path::Path, type_ref::{Mutability, TypeRef}, - ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId, StructLoc, UnionLoc, + ConstLoc, ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId, StaticLoc, + StructLoc, TypeAliasLoc, UnionLoc, }; pub(super) fn lower( @@ -497,6 +498,18 @@ where let ast_id = self.expander.ast_id(&def); FunctionLoc { container: container.into(), ast_id }.intern(self.db).into() } + ast::ModuleItem::TypeAliasDef(def) => { + let ast_id = self.expander.ast_id(&def); + TypeAliasLoc { container: container.into(), ast_id }.intern(self.db).into() + } + ast::ModuleItem::ConstDef(def) => { + let ast_id = self.expander.ast_id(&def); + ConstLoc { container: container.into(), ast_id }.intern(self.db).into() + } + ast::ModuleItem::StaticDef(def) => { + let ast_id = self.expander.ast_id(&def); + StaticLoc { container, ast_id }.intern(self.db).into() + } ast::ModuleItem::StructDef(def) => { let ast_id = self.expander.ast_id(&def); StructLoc { container, ast_id }.intern(self.db).into() -- cgit v1.2.3 From f42697e54b9d0a040011cb04c266d51710e249f1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 20 Dec 2019 12:29:25 +0100 Subject: Support for nested traits --- crates/ra_hir_def/src/body/lower.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_def/src/body/lower.rs') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index b61f924b7..853e17bae 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -26,7 +26,7 @@ use crate::{ path::Path, type_ref::{Mutability, TypeRef}, ConstLoc, ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId, StaticLoc, - StructLoc, TypeAliasLoc, UnionLoc, + StructLoc, TraitLoc, TypeAliasLoc, UnionLoc, }; pub(super) fn lower( @@ -522,7 +522,14 @@ where let ast_id = self.expander.ast_id(&def); UnionLoc { container, ast_id }.intern(self.db).into() } - _ => continue, + ast::ModuleItem::TraitDef(def) => { + let ast_id = self.expander.ast_id(&def); + TraitLoc { container, ast_id }.intern(self.db).into() + } + ast::ModuleItem::ImplBlock(_) + | ast::ModuleItem::UseItem(_) + | ast::ModuleItem::ExternCrateItem(_) + | ast::ModuleItem::Module(_) => continue, }; self.body.defs.push(def) } -- cgit v1.2.3 From 2a8c9100bfb1294a469bc039a5b9597eabed7073 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 20 Dec 2019 16:41:32 +0100 Subject: Handle closure return types Fixes #2547. --- crates/ra_hir_def/src/body/lower.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir_def/src/body/lower.rs') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 853e17bae..be5d17d85 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -372,8 +372,9 @@ where arg_types.push(type_ref); } } + let ret_type = e.ret_type().and_then(|r| r.type_ref()).map(TypeRef::from_ast); let body = self.collect_expr_opt(e.body()); - self.alloc_expr(Expr::Lambda { args, arg_types, body }, syntax_ptr) + self.alloc_expr(Expr::Lambda { args, arg_types, ret_type, body }, syntax_ptr) } ast::Expr::BinExpr(e) => { let lhs = self.collect_expr_opt(e.lhs()); -- cgit v1.2.3 From baee74618524ad75819163d701ff9e6fe9883e95 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 22 Dec 2019 15:49:39 +0100 Subject: Share impl Scope between modules and blocks --- crates/ra_hir_def/src/body/lower.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_def/src/body/lower.rs') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index be5d17d85..754924050 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -46,7 +46,7 @@ pub(super) fn lower( pats: Arena::default(), params: Vec::new(), body_expr: ExprId::dummy(), - defs: Vec::new(), + item_scope: Default::default(), }, } .collect(params, body) @@ -532,7 +532,7 @@ where | ast::ModuleItem::ExternCrateItem(_) | ast::ModuleItem::Module(_) => continue, }; - self.body.defs.push(def) + self.body.item_scope.define_def(def) } } -- cgit v1.2.3 From e424545c0f5cbaf135c52764169ea20df7d07d35 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 22 Dec 2019 20:12:23 +0100 Subject: Rudimentary name resolution for local items --- crates/ra_hir_def/src/body/lower.rs | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'crates/ra_hir_def/src/body/lower.rs') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 754924050..5323af097 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -494,45 +494,57 @@ where fn collect_block_items(&mut self, block: &ast::Block) { let container = ContainerId::DefWithBodyId(self.def); for item in block.items() { - let def: ModuleDefId = match item { + let (def, name): (ModuleDefId, Option) = match item { ast::ModuleItem::FnDef(def) => { let ast_id = self.expander.ast_id(&def); - FunctionLoc { container: container.into(), ast_id }.intern(self.db).into() + ( + FunctionLoc { container: container.into(), ast_id }.intern(self.db).into(), + def.name(), + ) } ast::ModuleItem::TypeAliasDef(def) => { let ast_id = self.expander.ast_id(&def); - TypeAliasLoc { container: container.into(), ast_id }.intern(self.db).into() + ( + TypeAliasLoc { container: container.into(), ast_id }.intern(self.db).into(), + def.name(), + ) } ast::ModuleItem::ConstDef(def) => { let ast_id = self.expander.ast_id(&def); - ConstLoc { container: container.into(), ast_id }.intern(self.db).into() + ( + ConstLoc { container: container.into(), ast_id }.intern(self.db).into(), + def.name(), + ) } ast::ModuleItem::StaticDef(def) => { let ast_id = self.expander.ast_id(&def); - StaticLoc { container, ast_id }.intern(self.db).into() + (StaticLoc { container, ast_id }.intern(self.db).into(), def.name()) } ast::ModuleItem::StructDef(def) => { let ast_id = self.expander.ast_id(&def); - StructLoc { container, ast_id }.intern(self.db).into() + (StructLoc { container, ast_id }.intern(self.db).into(), def.name()) } ast::ModuleItem::EnumDef(def) => { let ast_id = self.expander.ast_id(&def); - EnumLoc { container, ast_id }.intern(self.db).into() + (EnumLoc { container, ast_id }.intern(self.db).into(), def.name()) } ast::ModuleItem::UnionDef(def) => { let ast_id = self.expander.ast_id(&def); - UnionLoc { container, ast_id }.intern(self.db).into() + (UnionLoc { container, ast_id }.intern(self.db).into(), def.name()) } ast::ModuleItem::TraitDef(def) => { let ast_id = self.expander.ast_id(&def); - TraitLoc { container, ast_id }.intern(self.db).into() + (TraitLoc { container, ast_id }.intern(self.db).into(), def.name()) } ast::ModuleItem::ImplBlock(_) | ast::ModuleItem::UseItem(_) | ast::ModuleItem::ExternCrateItem(_) | ast::ModuleItem::Module(_) => continue, }; - self.body.item_scope.define_def(def) + self.body.item_scope.define_def(def); + if let Some(name) = name { + self.body.item_scope.push_res(name.as_name(), def.into()); + } } } -- cgit v1.2.3