diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 4c9b3df2dbd..2f54227c425 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -661,6 +661,10 @@ fn emit_unused_delims( keep_space: (bool, bool), ) { let primary_span = if let Some((lo, hi)) = spans { + if hi.is_empty() { + // do not point at delims that do not exist + return; + } MultiSpan::from(vec![lo, hi]) } else { MultiSpan::from(value_span) diff --git a/tests/ui/malformed/issue-107423-unused-delim-only-one-no-pair.rs b/tests/ui/malformed/issue-107423-unused-delim-only-one-no-pair.rs new file mode 100644 index 00000000000..4003ee37ca1 --- /dev/null +++ b/tests/ui/malformed/issue-107423-unused-delim-only-one-no-pair.rs @@ -0,0 +1,7 @@ +// check that we don't generate a span that points beyond EOF + +// error-pattern: unclosed delimiter +// error-pattern: unclosed delimiter +// error-pattern: unclosed delimiter + +fn a(){{{ diff --git a/tests/ui/malformed/issue-107423-unused-delim-only-one-no-pair.stderr b/tests/ui/malformed/issue-107423-unused-delim-only-one-no-pair.stderr new file mode 100644 index 00000000000..0479035171e --- /dev/null +++ b/tests/ui/malformed/issue-107423-unused-delim-only-one-no-pair.stderr @@ -0,0 +1,32 @@ +error: this file contains an unclosed delimiter + --> $DIR/issue-107423-unused-delim-only-one-no-pair.rs:7:11 + | +LL | fn a(){{{ + | --- ^ + | ||| + | ||unclosed delimiter + | |unclosed delimiter + | unclosed delimiter + +error: this file contains an unclosed delimiter + --> $DIR/issue-107423-unused-delim-only-one-no-pair.rs:7:11 + | +LL | fn a(){{{ + | --- ^ + | ||| + | ||unclosed delimiter + | |unclosed delimiter + | unclosed delimiter + +error: this file contains an unclosed delimiter + --> $DIR/issue-107423-unused-delim-only-one-no-pair.rs:7:11 + | +LL | fn a(){{{ + | --- ^ + | ||| + | ||unclosed delimiter + | |unclosed delimiter + | unclosed delimiter + +error: aborting due to 3 previous errors +