mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Simplify
This commit is contained in:
parent
68de7b30e0
commit
3b7b223b25
@ -508,11 +508,8 @@ impl ExprCollector<'_> {
|
|||||||
}
|
}
|
||||||
ast::Expr::MacroCall(e) => {
|
ast::Expr::MacroCall(e) => {
|
||||||
let macro_ptr = AstPtr::new(&e);
|
let macro_ptr = AstPtr::new(&e);
|
||||||
let mut id = None;
|
let id = self.collect_macro_call(e, macro_ptr.clone(), true, |this, expansion| {
|
||||||
self.collect_macro_call(e, macro_ptr.clone(), true, |this, expansion| {
|
expansion.map(|it| this.collect_expr(it))
|
||||||
if let Some(it) = expansion {
|
|
||||||
id.get_or_insert(this.collect_expr(it));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
match id {
|
match id {
|
||||||
Some(id) => {
|
Some(id) => {
|
||||||
@ -537,13 +534,17 @@ impl ExprCollector<'_> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_macro_call<F: FnOnce(&mut Self, Option<T>), T: ast::AstNode>(
|
fn collect_macro_call<F, T, U>(
|
||||||
&mut self,
|
&mut self,
|
||||||
mcall: ast::MacroCall,
|
mcall: ast::MacroCall,
|
||||||
syntax_ptr: AstPtr<ast::MacroCall>,
|
syntax_ptr: AstPtr<ast::MacroCall>,
|
||||||
record_diagnostics: bool,
|
record_diagnostics: bool,
|
||||||
collector: F,
|
collector: F,
|
||||||
) {
|
) -> U
|
||||||
|
where
|
||||||
|
F: FnOnce(&mut Self, Option<T>) -> U,
|
||||||
|
T: ast::AstNode,
|
||||||
|
{
|
||||||
// File containing the macro call. Expansion errors will be attached here.
|
// File containing the macro call. Expansion errors will be attached here.
|
||||||
let outer_file = self.expander.current_file_id;
|
let outer_file = self.expander.current_file_id;
|
||||||
|
|
||||||
@ -559,8 +560,7 @@ impl ExprCollector<'_> {
|
|||||||
path,
|
path,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
collector(self, None);
|
return collector(self, None);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -634,7 +634,6 @@ impl ExprCollector<'_> {
|
|||||||
let syntax_ptr = AstPtr::new(&stmt.expr().unwrap());
|
let syntax_ptr = AstPtr::new(&stmt.expr().unwrap());
|
||||||
|
|
||||||
let prev_stmt = self.statements_in_scope.len();
|
let prev_stmt = self.statements_in_scope.len();
|
||||||
let mut tail = None;
|
|
||||||
self.collect_macro_call(m, macro_ptr.clone(), false, |this, expansion| {
|
self.collect_macro_call(m, macro_ptr.clone(), false, |this, expansion| {
|
||||||
match expansion {
|
match expansion {
|
||||||
Some(expansion) => {
|
Some(expansion) => {
|
||||||
@ -643,7 +642,6 @@ impl ExprCollector<'_> {
|
|||||||
statements.statements().for_each(|stmt| this.collect_stmt(stmt));
|
statements.statements().for_each(|stmt| this.collect_stmt(stmt));
|
||||||
if let Some(expr) = statements.expr() {
|
if let Some(expr) = statements.expr() {
|
||||||
let expr = this.collect_expr(expr);
|
let expr = this.collect_expr(expr);
|
||||||
tail = Some(expr);
|
|
||||||
this.statements_in_scope
|
this.statements_in_scope
|
||||||
.push(Statement::Expr { expr, has_semi });
|
.push(Statement::Expr { expr, has_semi });
|
||||||
}
|
}
|
||||||
@ -654,6 +652,7 @@ impl ExprCollector<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut macro_exprs = smallvec![];
|
let mut macro_exprs = smallvec![];
|
||||||
for stmt in &self.statements_in_scope[prev_stmt..] {
|
for stmt in &self.statements_in_scope[prev_stmt..] {
|
||||||
match *stmt {
|
match *stmt {
|
||||||
@ -664,7 +663,6 @@ impl ExprCollector<'_> {
|
|||||||
Statement::Expr { expr, .. } => macro_exprs.push(expr),
|
Statement::Expr { expr, .. } => macro_exprs.push(expr),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
macro_exprs.extend(tail);
|
|
||||||
if !macro_exprs.is_empty() {
|
if !macro_exprs.is_empty() {
|
||||||
self.source_map
|
self.source_map
|
||||||
.macro_call_to_exprs
|
.macro_call_to_exprs
|
||||||
@ -894,15 +892,11 @@ impl ExprCollector<'_> {
|
|||||||
ast::Pat::MacroPat(mac) => match mac.macro_call() {
|
ast::Pat::MacroPat(mac) => match mac.macro_call() {
|
||||||
Some(call) => {
|
Some(call) => {
|
||||||
let macro_ptr = AstPtr::new(&call);
|
let macro_ptr = AstPtr::new(&call);
|
||||||
let mut pat = None;
|
let pat =
|
||||||
self.collect_macro_call(call, macro_ptr, true, |this, expanded_pat| {
|
self.collect_macro_call(call, macro_ptr, true, |this, expanded_pat| {
|
||||||
pat = Some(this.collect_pat_opt_(expanded_pat));
|
this.collect_pat_opt_(expanded_pat)
|
||||||
});
|
});
|
||||||
|
return pat;
|
||||||
match pat {
|
|
||||||
Some(pat) => return pat,
|
|
||||||
None => Pat::Missing,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None => Pat::Missing,
|
None => Pat::Missing,
|
||||||
},
|
},
|
||||||
|
@ -37,6 +37,7 @@ pub struct UnsafeExpr {
|
|||||||
pub inside_unsafe_block: bool,
|
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(
|
pub fn unsafe_expressions(
|
||||||
db: &dyn HirDatabase,
|
db: &dyn HirDatabase,
|
||||||
infer: &InferenceResult,
|
infer: &InferenceResult,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user