diff --git a/crates/hir_def/src/lib.rs b/crates/hir_def/src/lib.rs index 4904ebfd638..afcf1bc7078 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 24083172b30..d6762d1acf0 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(¯o_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 356f089b228..43b525133f1 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 "#, ); }