parse_macro_expansion_error almost never contains values so Option it

This commit is contained in:
Lukas Wirth 2024-05-13 17:02:08 +02:00
parent 56552f4839
commit caddcccea5
3 changed files with 14 additions and 8 deletions

View file

@ -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<ast::Fn>) -> Span;
/// Firewall query that returns the errors from the `parse_macro_expansion` query.
// FIXME: Option<Arc<...>>
fn parse_macro_expansion_error(
&self,
macro_call: MacroCallId,
) -> ExpandResult<Arc<[SyntaxError]>>;
) -> Option<Arc<ExpandResult<Arc<[SyntaxError]>>>>;
}
/// 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<Arc<[SyntaxError]>> {
db.parse_macro_expansion(MacroFileId { macro_call_id }).map(|it| it.0.errors().into())
) -> Option<Arc<ExpandResult<Arc<[SyntaxError]>>>> {
let e: ExpandResult<Arc<[SyntaxError]>> =
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(

View file

@ -831,13 +831,15 @@ fn macro_call_diagnostics(
macro_call_id: MacroCallId,
acc: &mut Vec<AnyDiagnostic>,
) {
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(),

View file

@ -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))