mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
Report DefDiagnostic
s from inside item bodies
This commit is contained in:
parent
5a711d4f3a
commit
0706de94bb
2 changed files with 226 additions and 220 deletions
|
@ -552,7 +552,7 @@ impl ExprCollector<'_> {
|
|||
ast::Expr::MacroCall(e) => {
|
||||
let macro_ptr = AstPtr::new(&e);
|
||||
let mut ids = vec![];
|
||||
self.collect_macro_call(e, macro_ptr, |this, expansion| {
|
||||
self.collect_macro_call(e, macro_ptr, true, |this, expansion| {
|
||||
ids.push(match expansion {
|
||||
Some(it) => this.collect_expr(it),
|
||||
None => this.alloc_expr(Expr::Missing, syntax_ptr.clone()),
|
||||
|
@ -576,6 +576,7 @@ impl ExprCollector<'_> {
|
|||
&mut self,
|
||||
e: ast::MacroCall,
|
||||
syntax_ptr: AstPtr<ast::MacroCall>,
|
||||
record_diagnostics: bool,
|
||||
mut collector: F,
|
||||
) {
|
||||
// File containing the macro call. Expansion errors will be attached here.
|
||||
|
@ -587,28 +588,32 @@ impl ExprCollector<'_> {
|
|||
let res = match res {
|
||||
Ok(res) => res,
|
||||
Err(UnresolvedMacro { path }) => {
|
||||
self.source_map.diagnostics.push(BodyDiagnostic::UnresolvedMacroCall {
|
||||
node: InFile::new(outer_file, syntax_ptr),
|
||||
path,
|
||||
});
|
||||
if record_diagnostics {
|
||||
self.source_map.diagnostics.push(BodyDiagnostic::UnresolvedMacroCall {
|
||||
node: InFile::new(outer_file, syntax_ptr),
|
||||
path,
|
||||
});
|
||||
}
|
||||
collector(self, None);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
match &res.err {
|
||||
Some(ExpandError::UnresolvedProcMacro) => {
|
||||
self.source_map.diagnostics.push(BodyDiagnostic::UnresolvedProcMacro {
|
||||
node: InFile::new(outer_file, syntax_ptr),
|
||||
});
|
||||
if record_diagnostics {
|
||||
match &res.err {
|
||||
Some(ExpandError::UnresolvedProcMacro) => {
|
||||
self.source_map.diagnostics.push(BodyDiagnostic::UnresolvedProcMacro {
|
||||
node: InFile::new(outer_file, syntax_ptr),
|
||||
});
|
||||
}
|
||||
Some(err) => {
|
||||
self.source_map.diagnostics.push(BodyDiagnostic::MacroError {
|
||||
node: InFile::new(outer_file, syntax_ptr),
|
||||
message: err.to_string(),
|
||||
});
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
Some(err) => {
|
||||
self.source_map.diagnostics.push(BodyDiagnostic::MacroError {
|
||||
node: InFile::new(outer_file, syntax_ptr),
|
||||
message: err.to_string(),
|
||||
});
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
||||
match res.value {
|
||||
|
@ -663,29 +668,33 @@ impl ExprCollector<'_> {
|
|||
let macro_ptr = AstPtr::new(&m);
|
||||
let syntax_ptr = AstPtr::new(&stmt.expr().unwrap());
|
||||
|
||||
self.collect_macro_call(m, macro_ptr, |this, expansion| match expansion {
|
||||
Some(expansion) => {
|
||||
let statements: ast::MacroStmts = expansion;
|
||||
self.collect_macro_call(
|
||||
m,
|
||||
macro_ptr,
|
||||
false,
|
||||
|this, expansion| match expansion {
|
||||
Some(expansion) => {
|
||||
let statements: ast::MacroStmts = expansion;
|
||||
|
||||
statements.statements().for_each(|stmt| this.collect_stmt(stmt));
|
||||
if let Some(expr) = statements.expr() {
|
||||
let expr = this.collect_expr(expr);
|
||||
statements.statements().for_each(|stmt| this.collect_stmt(stmt));
|
||||
if let Some(expr) = statements.expr() {
|
||||
let expr = this.collect_expr(expr);
|
||||
this.statements_in_scope
|
||||
.push(Statement::Expr { expr, has_semi });
|
||||
}
|
||||
}
|
||||
None => {
|
||||
let expr = this.alloc_expr(Expr::Missing, syntax_ptr.clone());
|
||||
this.statements_in_scope.push(Statement::Expr { expr, has_semi });
|
||||
}
|
||||
}
|
||||
None => {
|
||||
let expr = this.alloc_expr(Expr::Missing, syntax_ptr.clone());
|
||||
this.statements_in_scope.push(Statement::Expr { expr, has_semi });
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
} else {
|
||||
let expr = self.collect_expr_opt(stmt.expr());
|
||||
self.statements_in_scope.push(Statement::Expr { expr, has_semi });
|
||||
}
|
||||
}
|
||||
ast::Stmt::Item(item) => {
|
||||
self.check_cfg(&item);
|
||||
}
|
||||
ast::Stmt::Item(_item) => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -878,7 +887,7 @@ impl ExprCollector<'_> {
|
|||
Some(call) => {
|
||||
let macro_ptr = AstPtr::new(&call);
|
||||
let mut pat = None;
|
||||
self.collect_macro_call(call, macro_ptr, |this, expanded_pat| {
|
||||
self.collect_macro_call(call, macro_ptr, true, |this, expanded_pat| {
|
||||
pat = Some(this.collect_pat_opt(expanded_pat));
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue