diff options
Diffstat (limited to 'crates/ra_hir/src/expr.rs')
-rw-r--r-- | crates/ra_hir/src/expr.rs | 42 |
1 files changed, 13 insertions, 29 deletions
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index cdadf3ba6..692da2895 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs | |||
@@ -5,14 +5,13 @@ use rustc_hash::FxHashMap; | |||
5 | 5 | ||
6 | use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap}; | 6 | use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap}; |
7 | use ra_syntax::{ | 7 | use ra_syntax::{ |
8 | SyntaxNodePtr, AstPtr, AstNode,TreeArc, | 8 | SyntaxNodePtr, AstPtr, AstNode, |
9 | ast::{self, LoopBodyOwner, ArgListOwner, NameOwner, LiteralKind,ArrayExprKind, TypeAscriptionOwner} | 9 | ast::{self, LoopBodyOwner, ArgListOwner, NameOwner, LiteralKind,ArrayExprKind, TypeAscriptionOwner} |
10 | }; | 10 | }; |
11 | 11 | ||
12 | use crate::{ | 12 | use crate::{ |
13 | Path, Name, HirDatabase, Resolver,DefWithBody, Either, HirFileId, | 13 | Path, Name, HirDatabase, Resolver,DefWithBody, Either, HirFileId, |
14 | name::AsName, | 14 | name::AsName, |
15 | ids::{MacroCallId}, | ||
16 | type_ref::{Mutability, TypeRef}, | 15 | type_ref::{Mutability, TypeRef}, |
17 | }; | 16 | }; |
18 | use crate::{path::GenericArgs, ty::primitive::{IntTy, UncertainIntTy, FloatTy, UncertainFloatTy}}; | 17 | use crate::{path::GenericArgs, ty::primitive::{IntTy, UncertainIntTy, FloatTy, UncertainFloatTy}}; |
@@ -826,21 +825,20 @@ where | |||
826 | .with_file_id(self.current_file_id); | 825 | .with_file_id(self.current_file_id); |
827 | 826 | ||
828 | if let Some(call_id) = self.resolver.resolve_macro_call(self.db, path, ast_id) { | 827 | if let Some(call_id) = self.resolver.resolve_macro_call(self.db, path, ast_id) { |
829 | if let Some(expr) = expand_macro_to_expr(self.db, call_id, e.token_tree()) { | 828 | if let Some(tt) = self.db.macro_expand(call_id).ok() { |
830 | log::debug!("macro expansion {}", expr.syntax().debug_dump()); | 829 | if let Some(expr) = mbe::token_tree_to_expr(&tt).ok() { |
831 | let old_file_id = | 830 | log::debug!("macro expansion {}", expr.syntax().debug_dump()); |
832 | std::mem::replace(&mut self.current_file_id, call_id.into()); | 831 | let old_file_id = |
833 | let id = self.collect_expr(&expr); | 832 | std::mem::replace(&mut self.current_file_id, call_id.into()); |
834 | self.current_file_id = old_file_id; | 833 | let id = self.collect_expr(&expr); |
835 | id | 834 | self.current_file_id = old_file_id; |
836 | } else { | 835 | return id; |
837 | // FIXME: Instead of just dropping the error from expansion | 836 | } |
838 | // report it | ||
839 | self.alloc_expr(Expr::Missing, syntax_ptr) | ||
840 | } | 837 | } |
841 | } else { | ||
842 | self.alloc_expr(Expr::Missing, syntax_ptr) | ||
843 | } | 838 | } |
839 | // FIXME: Instead of just dropping the error from expansion | ||
840 | // report it | ||
841 | self.alloc_expr(Expr::Missing, syntax_ptr) | ||
844 | } | 842 | } |
845 | } | 843 | } |
846 | } | 844 | } |
@@ -999,20 +997,6 @@ where | |||
999 | } | 997 | } |
1000 | } | 998 | } |
1001 | 999 | ||
1002 | fn expand_macro_to_expr( | ||
1003 | db: &impl HirDatabase, | ||
1004 | macro_call: MacroCallId, | ||
1005 | args: Option<&ast::TokenTree>, | ||
1006 | ) -> Option<TreeArc<ast::Expr>> { | ||
1007 | let rules = db.macro_def(macro_call.loc(db).def)?; | ||
1008 | |||
1009 | let args = mbe::ast_to_token_tree(args?)?.0; | ||
1010 | |||
1011 | let expanded = rules.expand(&args).ok()?; | ||
1012 | |||
1013 | mbe::token_tree_to_expr(&expanded).ok() | ||
1014 | } | ||
1015 | |||
1016 | pub(crate) fn body_with_source_map_query( | 1000 | pub(crate) fn body_with_source_map_query( |
1017 | db: &impl HirDatabase, | 1001 | db: &impl HirDatabase, |
1018 | def: DefWithBody, | 1002 | def: DefWithBody, |