diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs index 661486d6e01..d1cfc501e5f 100644 --- a/crates/hir_def/src/body/lower.rs +++ b/crates/hir_def/src/body/lower.rs @@ -508,11 +508,8 @@ fn maybe_collect_expr(&mut self, expr: ast::Expr) -> Option { } ast::Expr::MacroCall(e) => { let macro_ptr = AstPtr::new(&e); - let mut id = None; - self.collect_macro_call(e, macro_ptr.clone(), true, |this, expansion| { - if let Some(it) = expansion { - id.get_or_insert(this.collect_expr(it)); - } + let id = self.collect_macro_call(e, macro_ptr.clone(), true, |this, expansion| { + expansion.map(|it| this.collect_expr(it)) }); match id { Some(id) => { @@ -537,13 +534,17 @@ fn maybe_collect_expr(&mut self, expr: ast::Expr) -> Option { }) } - fn collect_macro_call), T: ast::AstNode>( + fn collect_macro_call( &mut self, mcall: ast::MacroCall, syntax_ptr: AstPtr, record_diagnostics: bool, collector: F, - ) { + ) -> U + where + F: FnOnce(&mut Self, Option) -> U, + T: ast::AstNode, + { // File containing the macro call. Expansion errors will be attached here. let outer_file = self.expander.current_file_id; @@ -559,8 +560,7 @@ fn collect_macro_call), T: ast::AstNode>( path, }); } - collector(self, None); - return; + return collector(self, None); } }; @@ -634,7 +634,6 @@ fn collect_stmt(&mut self, s: ast::Stmt) { let syntax_ptr = AstPtr::new(&stmt.expr().unwrap()); let prev_stmt = self.statements_in_scope.len(); - let mut tail = None; self.collect_macro_call(m, macro_ptr.clone(), false, |this, expansion| { match expansion { Some(expansion) => { @@ -643,7 +642,6 @@ fn collect_stmt(&mut self, s: ast::Stmt) { statements.statements().for_each(|stmt| this.collect_stmt(stmt)); if let Some(expr) = statements.expr() { let expr = this.collect_expr(expr); - tail = Some(expr); this.statements_in_scope .push(Statement::Expr { expr, has_semi }); } @@ -654,6 +652,7 @@ fn collect_stmt(&mut self, s: ast::Stmt) { } } }); + let mut macro_exprs = smallvec![]; for stmt in &self.statements_in_scope[prev_stmt..] { match *stmt { @@ -664,7 +663,6 @@ fn collect_stmt(&mut self, s: ast::Stmt) { Statement::Expr { expr, .. } => macro_exprs.push(expr), } } - macro_exprs.extend(tail); if !macro_exprs.is_empty() { self.source_map .macro_call_to_exprs @@ -894,15 +892,11 @@ fn collect_pat_(&mut self, pat: ast::Pat) -> PatId { ast::Pat::MacroPat(mac) => match mac.macro_call() { Some(call) => { let macro_ptr = AstPtr::new(&call); - let mut pat = None; - self.collect_macro_call(call, macro_ptr, true, |this, expanded_pat| { - pat = Some(this.collect_pat_opt_(expanded_pat)); - }); - - match pat { - Some(pat) => return pat, - None => Pat::Missing, - } + let pat = + self.collect_macro_call(call, macro_ptr, true, |this, expanded_pat| { + this.collect_pat_opt_(expanded_pat) + }); + return pat; } None => Pat::Missing, }, diff --git a/crates/hir_ty/src/diagnostics/unsafe_check.rs b/crates/hir_ty/src/diagnostics/unsafe_check.rs index 4e0dcf7b618..b0fc49fc619 100644 --- a/crates/hir_ty/src/diagnostics/unsafe_check.rs +++ b/crates/hir_ty/src/diagnostics/unsafe_check.rs @@ -37,6 +37,7 @@ pub struct UnsafeExpr { pub inside_unsafe_block: bool, } +// FIXME: Move this out, its not a diagnostic only thing anymore, and handle unsafe pattern accesses as well pub fn unsafe_expressions( db: &dyn HirDatabase, infer: &InferenceResult,