aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/source_analyzer.rs30
1 files changed, 14 insertions, 16 deletions
diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/ra_hir/src/source_analyzer.rs
index 73cff17c9..33c566025 100644
--- a/crates/ra_hir/src/source_analyzer.rs
+++ b/crates/ra_hir/src/source_analyzer.rs
@@ -110,20 +110,16 @@ impl SourceAnalyzer {
110 fn expand_expr( 110 fn expand_expr(
111 &self, 111 &self,
112 db: &impl HirDatabase, 112 db: &impl HirDatabase,
113 expr: InFile<&ast::Expr>, 113 expr: InFile<ast::MacroCall>,
114 ) -> Option<InFile<ast::Expr>> { 114 ) -> Option<InFile<ast::Expr>> {
115 let macro_call = ast::MacroCall::cast(expr.value.syntax().clone())?; 115 let macro_file = self.body_source_map.as_ref()?.node_macro_file(expr.as_ref())?;
116 let macro_file =
117 self.body_source_map.as_ref()?.node_macro_file(expr.with_value(&macro_call))?;
118 let expanded = db.parse_or_expand(macro_file)?; 116 let expanded = db.parse_or_expand(macro_file)?;
119 let kind = expanded.kind();
120 let expr = InFile::new(macro_file, ast::Expr::cast(expanded)?);
121 117
122 if ast::MacroCall::can_cast(kind) { 118 let res = match ast::MacroCall::cast(expanded.clone()) {
123 self.expand_expr(db, expr.as_ref()) 119 Some(call) => self.expand_expr(db, InFile::new(macro_file, call))?,
124 } else { 120 _ => InFile::new(macro_file, ast::Expr::cast(expanded)?),
125 Some(expr) 121 };
126 } 122 Some(res)
127 } 123 }
128 124
129 fn trait_env(&self, db: &impl HirDatabase) -> Arc<TraitEnvironment> { 125 fn trait_env(&self, db: &impl HirDatabase) -> Arc<TraitEnvironment> {
@@ -131,11 +127,13 @@ impl SourceAnalyzer {
131 } 127 }
132 128
133 pub(crate) fn type_of(&self, db: &impl HirDatabase, expr: &ast::Expr) -> Option<Type> { 129 pub(crate) fn type_of(&self, db: &impl HirDatabase, expr: &ast::Expr) -> Option<Type> {
134 let expr_id = if let Some(expr) = self.expand_expr(db, InFile::new(self.file_id, expr)) { 130 let expr_id = match expr {
135 self.body_source_map.as_ref()?.node_expr(expr.as_ref())? 131 ast::Expr::MacroCall(call) => {
136 } else { 132 let expr = self.expand_expr(db, InFile::new(self.file_id, call.clone()))?;
137 self.expr_id(expr)? 133 self.body_source_map.as_ref()?.node_expr(expr.as_ref())
138 }; 134 }
135 _ => self.expr_id(expr),
136 }?;
139 137
140 let ty = self.infer.as_ref()?[expr_id].clone(); 138 let ty = self.infer.as_ref()?[expr_id].clone();
141 let environment = self.trait_env(db); 139 let environment = self.trait_env(db);