From 70d7e464009a53f069a90762ae6984dbbb03d640 Mon Sep 17 00:00:00 2001 From: PgBiel <9021226+PgBiel@users.noreply.github.com> Date: Mon, 15 Jul 2024 12:39:13 -0300 Subject: [PATCH] improve warning suppression check --- crates/typst/src/engine.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/typst/src/engine.rs b/crates/typst/src/engine.rs index 5db2dbe0b..b5cbe899d 100644 --- a/crates/typst/src/engine.rs +++ b/crates/typst/src/engine.rs @@ -247,9 +247,9 @@ impl Sink { 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| { - check_warning_suppressed(tracepoint.span, world, identifier) + is_warning_suppressed(tracepoint.span, world, identifier) }); // 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 /// warning suppression decorator sibling right before it suppressing this /// particular warning, the warning is considered suppressed. -fn check_warning_suppressed( +fn is_warning_suppressed( span: Span, world: &dyn World, identifier: &diag::Identifier, ) -> bool { // Don't suppress detached warnings. - let Some(file) = span.id() 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 Some(source) = span.id().and_then(|file| world.source(file).ok()) else { + return false; + }; let search_root = source.find(span); let mut searched_node = search_root.as_ref();