improve warning suppression check

This commit is contained in:
PgBiel 2024-07-15 12:39:13 -03:00
parent 19f3047cf3
commit 70d7e46400

View File

@ -247,9 +247,9 @@ impl Sink {
return true; return true;
}; };
let should_raise = !check_warning_suppressed(diag.span, world, identifier) let should_raise = !is_warning_suppressed(diag.span, world, identifier)
&& !diag.trace.iter().any(|tracepoint| { && !diag.trace.iter().any(|tracepoint| {
check_warning_suppressed(tracepoint.span, world, identifier) is_warning_suppressed(tracepoint.span, world, identifier)
}); });
// If this warning wasn't suppressed, any further duplicates (with // If this warning wasn't suppressed, any further duplicates (with
@ -333,17 +333,15 @@ impl Sink {
/// in. If one of the ancestors of the node where the warning occurred has a /// in. If one of the ancestors of the node where the warning occurred has a
/// warning suppression decorator sibling right before it suppressing this /// warning suppression decorator sibling right before it suppressing this
/// particular warning, the warning is considered suppressed. /// particular warning, the warning is considered suppressed.
fn check_warning_suppressed( fn is_warning_suppressed(
span: Span, span: Span,
world: &dyn World, world: &dyn World,
identifier: &diag::Identifier, identifier: &diag::Identifier,
) -> bool { ) -> bool {
// Don't suppress detached warnings. // Don't suppress detached warnings.
let Some(file) = span.id() else { return false }; let Some(source) = span.id().and_then(|file| world.source(file).ok()) else {
return false;
// The source must exist if a warning occurred in the file, };
// or has a tracepoint in the file.
let source = world.source(file).unwrap();
let search_root = source.find(span); let search_root = source.find(span);
let mut searched_node = search_root.as_ref(); let mut searched_node = search_root.as_ref();