mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Remove ExpressionStoreDiagnostics::MacroError
, instead recreate it from the MacroCallId
This simplifies the code and also makes us report parse error in macros too.
This commit is contained in:
parent
a54351effd
commit
963a1317e7
@ -16,7 +16,7 @@ use std::{
|
|||||||
|
|
||||||
use cfg::{CfgExpr, CfgOptions};
|
use cfg::{CfgExpr, CfgOptions};
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir_expand::{ExpandError, InFile, MacroCallId, mod_path::ModPath, name::Name};
|
use hir_expand::{InFile, MacroCallId, mod_path::ModPath, name::Name};
|
||||||
use la_arena::{Arena, ArenaMap};
|
use la_arena::{Arena, ArenaMap};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
@ -281,7 +281,6 @@ struct FormatTemplate {
|
|||||||
#[derive(Debug, Eq, PartialEq)]
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
pub enum ExpressionStoreDiagnostics {
|
pub enum ExpressionStoreDiagnostics {
|
||||||
InactiveCode { node: InFile<SyntaxNodePtr>, cfg: CfgExpr, opts: CfgOptions },
|
InactiveCode { node: InFile<SyntaxNodePtr>, cfg: CfgExpr, opts: CfgOptions },
|
||||||
MacroError { node: InFile<MacroCallPtr>, err: ExpandError },
|
|
||||||
UnresolvedMacroCall { node: InFile<MacroCallPtr>, path: ModPath },
|
UnresolvedMacroCall { node: InFile<MacroCallPtr>, path: ModPath },
|
||||||
UnreachableLabel { node: InFile<AstPtr<ast::Lifetime>>, name: Name },
|
UnreachableLabel { node: InFile<AstPtr<ast::Lifetime>>, name: Name },
|
||||||
AwaitOutsideOfAsync { node: InFile<AstPtr<ast::AwaitExpr>>, location: String },
|
AwaitOutsideOfAsync { node: InFile<AstPtr<ast::AwaitExpr>>, location: String },
|
||||||
|
@ -1981,13 +1981,7 @@ impl ExprCollector<'_> {
|
|||||||
return collector(self, None);
|
return collector(self, None);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if record_diagnostics {
|
// No need to push macro and parsing errors as they'll be recreated from `macro_calls()`.
|
||||||
if let Some(err) = res.err {
|
|
||||||
self.store
|
|
||||||
.diagnostics
|
|
||||||
.push(ExpressionStoreDiagnostics::MacroError { node: macro_call_ptr, err });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
match res.value {
|
match res.value {
|
||||||
Some((mark, expansion)) => {
|
Some((mark, expansion)) => {
|
||||||
@ -1997,10 +1991,6 @@ impl ExprCollector<'_> {
|
|||||||
self.store.expansions.insert(macro_call_ptr, macro_file);
|
self.store.expansions.insert(macro_call_ptr, macro_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
if record_diagnostics {
|
|
||||||
// FIXME: Report parse errors here
|
|
||||||
}
|
|
||||||
|
|
||||||
let id = collector(self, expansion.map(|it| it.tree()));
|
let id = collector(self, expansion.map(|it| it.tree()));
|
||||||
self.expander.exit(mark);
|
self.expander.exit(mark);
|
||||||
id
|
id
|
||||||
|
@ -1922,10 +1922,6 @@ impl DefWithBody {
|
|||||||
Module { id: def_map.module_id(DefMap::ROOT) }.diagnostics(db, acc, style_lints);
|
Module { id: def_map.module_id(DefMap::ROOT) }.diagnostics(db, acc, style_lints);
|
||||||
}
|
}
|
||||||
|
|
||||||
source_map
|
|
||||||
.macro_calls()
|
|
||||||
.for_each(|(_ast_id, call_id)| macro_call_diagnostics(db, call_id, acc));
|
|
||||||
|
|
||||||
expr_store_diagnostics(db, acc, &source_map);
|
expr_store_diagnostics(db, acc, &source_map);
|
||||||
|
|
||||||
let infer = db.infer(self.into());
|
let infer = db.infer(self.into());
|
||||||
@ -2130,9 +2126,9 @@ impl DefWithBody {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expr_store_diagnostics(
|
fn expr_store_diagnostics<'db>(
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
acc: &mut Vec<AnyDiagnostic<'_>>,
|
acc: &mut Vec<AnyDiagnostic<'db>>,
|
||||||
source_map: &ExpressionStoreSourceMap,
|
source_map: &ExpressionStoreSourceMap,
|
||||||
) {
|
) {
|
||||||
for diag in source_map.diagnostics() {
|
for diag in source_map.diagnostics() {
|
||||||
@ -2140,30 +2136,6 @@ fn expr_store_diagnostics(
|
|||||||
ExpressionStoreDiagnostics::InactiveCode { node, cfg, opts } => {
|
ExpressionStoreDiagnostics::InactiveCode { node, cfg, opts } => {
|
||||||
InactiveCode { node: *node, cfg: cfg.clone(), opts: opts.clone() }.into()
|
InactiveCode { node: *node, cfg: cfg.clone(), opts: opts.clone() }.into()
|
||||||
}
|
}
|
||||||
ExpressionStoreDiagnostics::MacroError { node, err } => {
|
|
||||||
let RenderedExpandError { message, error, kind } = err.render_to_string(db);
|
|
||||||
|
|
||||||
let editioned_file_id = EditionedFileId::from_span(db, err.span().anchor.file_id);
|
|
||||||
let precise_location = if editioned_file_id == node.file_id {
|
|
||||||
Some(
|
|
||||||
err.span().range
|
|
||||||
+ db.ast_id_map(editioned_file_id.into())
|
|
||||||
.get_erased(err.span().anchor.ast_id)
|
|
||||||
.text_range()
|
|
||||||
.start(),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
MacroError {
|
|
||||||
node: (node).map(|it| it.into()),
|
|
||||||
precise_location,
|
|
||||||
message,
|
|
||||||
error,
|
|
||||||
kind,
|
|
||||||
}
|
|
||||||
.into()
|
|
||||||
}
|
|
||||||
ExpressionStoreDiagnostics::UnresolvedMacroCall { node, path } => UnresolvedMacroCall {
|
ExpressionStoreDiagnostics::UnresolvedMacroCall { node, path } => UnresolvedMacroCall {
|
||||||
macro_call: (*node).map(|ast_ptr| ast_ptr.into()),
|
macro_call: (*node).map(|ast_ptr| ast_ptr.into()),
|
||||||
precise_location: None,
|
precise_location: None,
|
||||||
@ -2182,6 +2154,10 @@ fn expr_store_diagnostics(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
source_map
|
||||||
|
.macro_calls()
|
||||||
|
.for_each(|(_ast_id, call_id)| macro_call_diagnostics(db, call_id, acc));
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct Function {
|
pub struct Function {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user