Unnamed repository; edit this file 'description' to name the repository.
Merge #10339
10339: fix: Fix item-level macro errors (eg. `compile_error!`) r=jonas-schievink a=jonas-schievink Fixes https://github.com/rust-analyzer/rust-analyzer/issues/8459 bors r+ Co-authored-by: Jonas Schievink <[email protected]>
bors[bot] 2021-09-25
parent e372bdc · parent 7860d6a · commit 9abea74
-rw-r--r--crates/hir_def/src/lib.rs1
-rw-r--r--crates/hir_def/src/nameres/collector.rs13
-rw-r--r--crates/ide_diagnostics/src/handlers/macro_error.rs6
3 files changed, 15 insertions, 5 deletions
diff --git a/crates/hir_def/src/lib.rs b/crates/hir_def/src/lib.rs
index 4904ebfd63..afcf1bc707 100644
--- a/crates/hir_def/src/lib.rs
+++ b/crates/hir_def/src/lib.rs
@@ -733,7 +733,6 @@ fn macro_call_as_call_id(
&|path: ast::Path| resolver(path::ModPath::from_src(db, path, &hygiene)?),
error_sink,
)
- .map(MacroCallId::from)
} else {
Ok(def.as_lazy_macro(
db.upcast(),
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs
index 24083172b3..d6762d1acf 100644
--- a/crates/hir_def/src/nameres/collector.rs
+++ b/crates/hir_def/src/nameres/collector.rs
@@ -1939,17 +1939,22 @@ impl ModCollector<'_, '_> {
self.macro_depth + 1,
);
+ if let Some(err) = error {
+ self.def_collector.def_map.diagnostics.push(DefDiagnostic::macro_error(
+ self.module_id,
+ MacroCallKind::FnLike { ast_id: ast_id.ast_id, expand_to: mac.expand_to },
+ err.to_string(),
+ ));
+ }
+
return;
}
Ok(Err(_)) => {
// Built-in macro failed eager expansion.
- // FIXME: don't parse the file here
- let macro_call = ast_id.ast_id.to_node(self.def_collector.db.upcast());
- let expand_to = hir_expand::ExpandTo::from_call_site(&macro_call);
self.def_collector.def_map.diagnostics.push(DefDiagnostic::macro_error(
self.module_id,
- MacroCallKind::FnLike { ast_id: ast_id.ast_id, expand_to },
+ MacroCallKind::FnLike { ast_id: ast_id.ast_id, expand_to: mac.expand_to },
error.unwrap().to_string(),
));
return;
diff --git a/crates/ide_diagnostics/src/handlers/macro_error.rs b/crates/ide_diagnostics/src/handlers/macro_error.rs
index 356f089b22..43b525133f 100644
--- a/crates/ide_diagnostics/src/handlers/macro_error.rs
+++ b/crates/ide_diagnostics/src/handlers/macro_error.rs
@@ -26,8 +26,14 @@ mod tests {
#[rustc_builtin_macro]
macro_rules! include { () => {} }
+#[rustc_builtin_macro]
+macro_rules! compile_error { () => {} }
+
include!("doesntexist");
//^^^^^^^^^^^^^^^^^^^^^^^^ error: failed to load file `doesntexist`
+
+ compile_error!("compile_error macro works");
+//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: compile_error macro works
"#,
);
}