Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 3b7b223

Browse files
committed
Simplify
1 parent 68de7b3 commit 3b7b223

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

crates/hir_def/src/body/lower.rs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -508,11 +508,8 @@ impl ExprCollector<'_> {
508508
}
509509
ast::Expr::MacroCall(e) => {
510510
let macro_ptr = AstPtr::new(&e);
511-
let mut id = None;
512-
self.collect_macro_call(e, macro_ptr.clone(), true, |this, expansion| {
513-
if let Some(it) = expansion {
514-
id.get_or_insert(this.collect_expr(it));
515-
}
511+
let id = self.collect_macro_call(e, macro_ptr.clone(), true, |this, expansion| {
512+
expansion.map(|it| this.collect_expr(it))
516513
});
517514
match id {
518515
Some(id) => {
@@ -537,13 +534,17 @@ impl ExprCollector<'_> {
537534
})
538535
}
539536

540-
fn collect_macro_call<F: FnOnce(&mut Self, Option<T>), T: ast::AstNode>(
537+
fn collect_macro_call<F, T, U>(
541538
&mut self,
542539
mcall: ast::MacroCall,
543540
syntax_ptr: AstPtr<ast::MacroCall>,
544541
record_diagnostics: bool,
545542
collector: F,
546-
) {
543+
) -> U
544+
where
545+
F: FnOnce(&mut Self, Option<T>) -> U,
546+
T: ast::AstNode,
547+
{
547548
// File containing the macro call. Expansion errors will be attached here.
548549
let outer_file = self.expander.current_file_id;
549550

@@ -559,8 +560,7 @@ impl ExprCollector<'_> {
559560
path,
560561
});
561562
}
562-
collector(self, None);
563-
return;
563+
return collector(self, None);
564564
}
565565
};
566566

@@ -634,7 +634,6 @@ impl ExprCollector<'_> {
634634
let syntax_ptr = AstPtr::new(&stmt.expr().unwrap());
635635

636636
let prev_stmt = self.statements_in_scope.len();
637-
let mut tail = None;
638637
self.collect_macro_call(m, macro_ptr.clone(), false, |this, expansion| {
639638
match expansion {
640639
Some(expansion) => {
@@ -643,7 +642,6 @@ impl ExprCollector<'_> {
643642
statements.statements().for_each(|stmt| this.collect_stmt(stmt));
644643
if let Some(expr) = statements.expr() {
645644
let expr = this.collect_expr(expr);
646-
tail = Some(expr);
647645
this.statements_in_scope
648646
.push(Statement::Expr { expr, has_semi });
649647
}
@@ -654,6 +652,7 @@ impl ExprCollector<'_> {
654652
}
655653
}
656654
});
655+
657656
let mut macro_exprs = smallvec![];
658657
for stmt in &self.statements_in_scope[prev_stmt..] {
659658
match *stmt {
@@ -664,7 +663,6 @@ impl ExprCollector<'_> {
664663
Statement::Expr { expr, .. } => macro_exprs.push(expr),
665664
}
666665
}
667-
macro_exprs.extend(tail);
668666
if !macro_exprs.is_empty() {
669667
self.source_map
670668
.macro_call_to_exprs
@@ -894,15 +892,11 @@ impl ExprCollector<'_> {
894892
ast::Pat::MacroPat(mac) => match mac.macro_call() {
895893
Some(call) => {
896894
let macro_ptr = AstPtr::new(&call);
897-
let mut pat = None;
898-
self.collect_macro_call(call, macro_ptr, true, |this, expanded_pat| {
899-
pat = Some(this.collect_pat_opt_(expanded_pat));
900-
});
901-
902-
match pat {
903-
Some(pat) => return pat,
904-
None => Pat::Missing,
905-
}
895+
let pat =
896+
self.collect_macro_call(call, macro_ptr, true, |this, expanded_pat| {
897+
this.collect_pat_opt_(expanded_pat)
898+
});
899+
return pat;
906900
}
907901
None => Pat::Missing,
908902
},

crates/hir_ty/src/diagnostics/unsafe_check.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub struct UnsafeExpr {
3737
pub inside_unsafe_block: bool,
3838
}
3939

40+
// FIXME: Move this out, its not a diagnostic only thing anymore, and handle unsafe pattern accesses as well
4041
pub fn unsafe_expressions(
4142
db: &dyn HirDatabase,
4243
infer: &InferenceResult,

0 commit comments

Comments
 (0)