Skip to content

Commit 9abea74

Browse files
Merge #10339
10339: fix: Fix item-level macro errors (eg. `compile_error!`) r=jonas-schievink a=jonas-schievink Fixes #8459 bors r+ Co-authored-by: Jonas Schievink <[email protected]>
2 parents e372bdc + 7860d6a commit 9abea74

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

crates/hir_def/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,6 @@ fn macro_call_as_call_id(
733733
&|path: ast::Path| resolver(path::ModPath::from_src(db, path, &hygiene)?),
734734
error_sink,
735735
)
736-
.map(MacroCallId::from)
737736
} else {
738737
Ok(def.as_lazy_macro(
739738
db.upcast(),

crates/hir_def/src/nameres/collector.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,17 +1939,22 @@ impl ModCollector<'_, '_> {
19391939
self.macro_depth + 1,
19401940
);
19411941

1942+
if let Some(err) = error {
1943+
self.def_collector.def_map.diagnostics.push(DefDiagnostic::macro_error(
1944+
self.module_id,
1945+
MacroCallKind::FnLike { ast_id: ast_id.ast_id, expand_to: mac.expand_to },
1946+
err.to_string(),
1947+
));
1948+
}
1949+
19421950
return;
19431951
}
19441952
Ok(Err(_)) => {
19451953
// Built-in macro failed eager expansion.
19461954

1947-
// FIXME: don't parse the file here
1948-
let macro_call = ast_id.ast_id.to_node(self.def_collector.db.upcast());
1949-
let expand_to = hir_expand::ExpandTo::from_call_site(&macro_call);
19501955
self.def_collector.def_map.diagnostics.push(DefDiagnostic::macro_error(
19511956
self.module_id,
1952-
MacroCallKind::FnLike { ast_id: ast_id.ast_id, expand_to },
1957+
MacroCallKind::FnLike { ast_id: ast_id.ast_id, expand_to: mac.expand_to },
19531958
error.unwrap().to_string(),
19541959
));
19551960
return;

crates/ide_diagnostics/src/handlers/macro_error.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,14 @@ mod tests {
2626
#[rustc_builtin_macro]
2727
macro_rules! include { () => {} }
2828
29+
#[rustc_builtin_macro]
30+
macro_rules! compile_error { () => {} }
31+
2932
include!("doesntexist");
3033
//^^^^^^^^^^^^^^^^^^^^^^^^ error: failed to load file `doesntexist`
34+
35+
compile_error!("compile_error macro works");
36+
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: compile_error macro works
3137
"#,
3238
);
3339
}

0 commit comments

Comments
 (0)