Skip to content

Commit 97593ea

Browse files
authored
Merge pull request #20289 from ChayimFriedman2/expr-store-diags-macros
internal: Remove `ExpressionStoreDiagnostics::MacroError`, instead recreate it from the `MacroCallId`
2 parents fa64d3b + 963a131 commit 97593ea

File tree

3 files changed

+9
-44
lines changed

3 files changed

+9
-44
lines changed

crates/hir-def/src/expr_store.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::{
1616

1717
use cfg::{CfgExpr, CfgOptions};
1818
use either::Either;
19-
use hir_expand::{ExpandError, InFile, MacroCallId, mod_path::ModPath, name::Name};
19+
use hir_expand::{InFile, MacroCallId, mod_path::ModPath, name::Name};
2020
use la_arena::{Arena, ArenaMap};
2121
use rustc_hash::FxHashMap;
2222
use smallvec::SmallVec;
@@ -281,7 +281,6 @@ struct FormatTemplate {
281281
#[derive(Debug, Eq, PartialEq)]
282282
pub enum ExpressionStoreDiagnostics {
283283
InactiveCode { node: InFile<SyntaxNodePtr>, cfg: CfgExpr, opts: CfgOptions },
284-
MacroError { node: InFile<MacroCallPtr>, err: ExpandError },
285284
UnresolvedMacroCall { node: InFile<MacroCallPtr>, path: ModPath },
286285
UnreachableLabel { node: InFile<AstPtr<ast::Lifetime>>, name: Name },
287286
AwaitOutsideOfAsync { node: InFile<AstPtr<ast::AwaitExpr>>, location: String },

crates/hir-def/src/expr_store/lower.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,13 +1972,7 @@ impl ExprCollector<'_> {
19721972
return collector(self, None);
19731973
}
19741974
};
1975-
if record_diagnostics {
1976-
if let Some(err) = res.err {
1977-
self.store
1978-
.diagnostics
1979-
.push(ExpressionStoreDiagnostics::MacroError { node: macro_call_ptr, err });
1980-
}
1981-
}
1975+
// No need to push macro and parsing errors as they'll be recreated from `macro_calls()`.
19821976

19831977
match res.value {
19841978
Some((mark, expansion)) => {
@@ -1988,10 +1982,6 @@ impl ExprCollector<'_> {
19881982
self.store.expansions.insert(macro_call_ptr, macro_file);
19891983
}
19901984

1991-
if record_diagnostics {
1992-
// FIXME: Report parse errors here
1993-
}
1994-
19951985
let id = collector(self, expansion.map(|it| it.tree()));
19961986
self.expander.exit(mark);
19971987
id

crates/hir/src/lib.rs

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,10 +1922,6 @@ impl DefWithBody {
19221922
Module { id: def_map.module_id(DefMap::ROOT) }.diagnostics(db, acc, style_lints);
19231923
}
19241924

1925-
source_map
1926-
.macro_calls()
1927-
.for_each(|(_ast_id, call_id)| macro_call_diagnostics(db, call_id, acc));
1928-
19291925
expr_store_diagnostics(db, acc, &source_map);
19301926

19311927
let infer = db.infer(self.into());
@@ -2130,40 +2126,16 @@ impl DefWithBody {
21302126
}
21312127
}
21322128

2133-
fn expr_store_diagnostics(
2134-
db: &dyn HirDatabase,
2135-
acc: &mut Vec<AnyDiagnostic<'_>>,
2129+
fn expr_store_diagnostics<'db>(
2130+
db: &'db dyn HirDatabase,
2131+
acc: &mut Vec<AnyDiagnostic<'db>>,
21362132
source_map: &ExpressionStoreSourceMap,
21372133
) {
21382134
for diag in source_map.diagnostics() {
21392135
acc.push(match diag {
21402136
ExpressionStoreDiagnostics::InactiveCode { node, cfg, opts } => {
21412137
InactiveCode { node: *node, cfg: cfg.clone(), opts: opts.clone() }.into()
21422138
}
2143-
ExpressionStoreDiagnostics::MacroError { node, err } => {
2144-
let RenderedExpandError { message, error, kind } = err.render_to_string(db);
2145-
2146-
let editioned_file_id = EditionedFileId::from_span(db, err.span().anchor.file_id);
2147-
let precise_location = if editioned_file_id == node.file_id {
2148-
Some(
2149-
err.span().range
2150-
+ db.ast_id_map(editioned_file_id.into())
2151-
.get_erased(err.span().anchor.ast_id)
2152-
.text_range()
2153-
.start(),
2154-
)
2155-
} else {
2156-
None
2157-
};
2158-
MacroError {
2159-
node: (node).map(|it| it.into()),
2160-
precise_location,
2161-
message,
2162-
error,
2163-
kind,
2164-
}
2165-
.into()
2166-
}
21672139
ExpressionStoreDiagnostics::UnresolvedMacroCall { node, path } => UnresolvedMacroCall {
21682140
macro_call: (*node).map(|ast_ptr| ast_ptr.into()),
21692141
precise_location: None,
@@ -2182,6 +2154,10 @@ fn expr_store_diagnostics(
21822154
}
21832155
});
21842156
}
2157+
2158+
source_map
2159+
.macro_calls()
2160+
.for_each(|(_ast_id, call_id)| macro_call_diagnostics(db, call_id, acc));
21852161
}
21862162
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
21872163
pub struct Function {

0 commit comments

Comments
 (0)