3445: Minor cleanup r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-03-04 13:40:38 +00:00 committed by GitHub
commit a5da660bd5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -110,20 +110,16 @@ impl SourceAnalyzer {
fn expand_expr( fn expand_expr(
&self, &self,
db: &impl HirDatabase, db: &impl HirDatabase,
expr: InFile<&ast::Expr>, expr: InFile<ast::MacroCall>,
) -> Option<InFile<ast::Expr>> { ) -> Option<InFile<ast::Expr>> {
let macro_call = ast::MacroCall::cast(expr.value.syntax().clone())?; let macro_file = self.body_source_map.as_ref()?.node_macro_file(expr.as_ref())?;
let macro_file =
self.body_source_map.as_ref()?.node_macro_file(expr.with_value(&macro_call))?;
let expanded = db.parse_or_expand(macro_file)?; let expanded = db.parse_or_expand(macro_file)?;
let kind = expanded.kind();
let expr = InFile::new(macro_file, ast::Expr::cast(expanded)?);
if ast::MacroCall::can_cast(kind) { let res = match ast::MacroCall::cast(expanded.clone()) {
self.expand_expr(db, expr.as_ref()) Some(call) => self.expand_expr(db, InFile::new(macro_file, call))?,
} else { _ => InFile::new(macro_file, ast::Expr::cast(expanded)?),
Some(expr) };
} Some(res)
} }
fn trait_env(&self, db: &impl HirDatabase) -> Arc<TraitEnvironment> { fn trait_env(&self, db: &impl HirDatabase) -> Arc<TraitEnvironment> {
@ -131,11 +127,13 @@ impl SourceAnalyzer {
} }
pub(crate) fn type_of(&self, db: &impl HirDatabase, expr: &ast::Expr) -> Option<Type> { pub(crate) fn type_of(&self, db: &impl HirDatabase, expr: &ast::Expr) -> Option<Type> {
let expr_id = if let Some(expr) = self.expand_expr(db, InFile::new(self.file_id, expr)) { let expr_id = match expr {
self.body_source_map.as_ref()?.node_expr(expr.as_ref())? ast::Expr::MacroCall(call) => {
} else { let expr = self.expand_expr(db, InFile::new(self.file_id, call.clone()))?;
self.expr_id(expr)? self.body_source_map.as_ref()?.node_expr(expr.as_ref())
}; }
_ => self.expr_id(expr),
}?;
let ty = self.infer.as_ref()?[expr_id].clone(); let ty = self.infer.as_ref()?[expr_id].clone();
let environment = self.trait_env(db); let environment = self.trait_env(db);