From caddcccea5b770901ef1ebf292defac48f8dda02 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 13 May 2024 17:02:08 +0200 Subject: [PATCH] `parse_macro_expansion_error` almost never contains values so `Option` it --- crates/hir-expand/src/db.rs | 13 +++++++++---- crates/hir/src/lib.rs | 8 +++++--- crates/ide-diagnostics/src/tests.rs | 1 - 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/crates/hir-expand/src/db.rs b/crates/hir-expand/src/db.rs index 895cf20224..2e5fa6131a 100644 --- a/crates/hir-expand/src/db.rs +++ b/crates/hir-expand/src/db.rs @@ -129,11 +129,10 @@ pub trait ExpandDatabase: SourceDatabase { /// user wrote in the file that defines the proc-macro. fn proc_macro_span(&self, fun: AstId) -> Span; /// Firewall query that returns the errors from the `parse_macro_expansion` query. - // FIXME: Option> fn parse_macro_expansion_error( &self, macro_call: MacroCallId, - ) -> ExpandResult>; + ) -> Option>>>; } /// This expands the given macro call, but with different arguments. This is @@ -358,8 +357,14 @@ fn parse_macro_expansion( fn parse_macro_expansion_error( db: &dyn ExpandDatabase, macro_call_id: MacroCallId, -) -> ExpandResult> { - db.parse_macro_expansion(MacroFileId { macro_call_id }).map(|it| it.0.errors().into()) +) -> Option>>> { + let e: ExpandResult> = + db.parse_macro_expansion(MacroFileId { macro_call_id }).map(|it| Arc::from(it.0.errors())); + if e.value.is_empty() && e.err.is_none() { + None + } else { + Some(Arc::new(e)) + } } pub(crate) fn parse_with_map( diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 6dd1801dae..079aa90600 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -831,13 +831,15 @@ fn macro_call_diagnostics( macro_call_id: MacroCallId, acc: &mut Vec, ) { - let ValueResult { value: parse_errors, err } = db.parse_macro_expansion_error(macro_call_id); - + let Some(e) = db.parse_macro_expansion_error(macro_call_id) else { + return; + }; + let ValueResult { value: parse_errors, err } = &*e; if let Some(err) = err { let loc = db.lookup_intern_macro_call(macro_call_id); let (node, precise_location, macro_name, kind) = precise_macro_call_location(&loc.kind, db); let diag = match err { - hir_expand::ExpandError::UnresolvedProcMacro(krate) => { + &hir_expand::ExpandError::UnresolvedProcMacro(krate) => { UnresolvedProcMacro { node, precise_location, macro_name, kind, krate }.into() } err => MacroError { node, precise_location, message: err.to_string() }.into(), diff --git a/crates/ide-diagnostics/src/tests.rs b/crates/ide-diagnostics/src/tests.rs index 8bf062fd61..cd5e95cc1e 100644 --- a/crates/ide-diagnostics/src/tests.rs +++ b/crates/ide-diagnostics/src/tests.rs @@ -246,7 +246,6 @@ pub(crate) fn check_diagnostics_with_config(config: DiagnosticsConfig, ra_fixtur } } if expected != actual { - dbg!(&actual); let fneg = expected .iter() .filter(|x| !actual.contains(x))