Skip to content

Commit a676496

Browse files
committed
Auto merge of #107663 - matthiaskrgr:107423-point-at-EOF-code, r=compiler-errors
don't point at nonexisting code beyond EOF when warning about delims Previously we would show this: ``` warning: unnecessary braces around block return value --> /tmp/bad.rs:1:8 | 1 | fn a(){{{ | ^ ^ | = note: `#[warn(unused_braces)]` on by default help: remove these braces | 1 - fn a(){{{ 1 + fn a(){{ | ``` which is now hidden in this case. We would create a span spanning between the pair of redundant {}s but there is only EOF instead of the `}` so we would previously point at nothing. This would cause the debug assertion ice to trigger. I would have loved to just only point at the second delim and say "you can remove that" but I'm not sure how to do that without refactoring the entire diagnostic which seems tricky. :( But given that this does not seem to regress any other tests we have, I think this edge-casey enough be acceptable. Fixes #107423 r? `@compiler-errors`
2 parents 319b88c + ed58c01 commit a676496

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

compiler/rustc_lint/src/unused.rs

+4
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,10 @@ trait UnusedDelimLint {
663663
keep_space: (bool, bool),
664664
) {
665665
let primary_span = if let Some((lo, hi)) = spans {
666+
if hi.is_empty() {
667+
// do not point at delims that do not exist
668+
return;
669+
}
666670
MultiSpan::from(vec![lo, hi])
667671
} else {
668672
MultiSpan::from(value_span)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// check that we don't generate a span that points beyond EOF
2+
3+
// error-pattern: unclosed delimiter
4+
// error-pattern: unclosed delimiter
5+
// error-pattern: unclosed delimiter
6+
7+
fn a(){{{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error: this file contains an unclosed delimiter
2+
--> $DIR/issue-107423-unused-delim-only-one-no-pair.rs:7:11
3+
|
4+
LL | fn a(){{{
5+
| --- ^
6+
| |||
7+
| ||unclosed delimiter
8+
| |unclosed delimiter
9+
| unclosed delimiter
10+
11+
error: this file contains an unclosed delimiter
12+
--> $DIR/issue-107423-unused-delim-only-one-no-pair.rs:7:11
13+
|
14+
LL | fn a(){{{
15+
| --- ^
16+
| |||
17+
| ||unclosed delimiter
18+
| |unclosed delimiter
19+
| unclosed delimiter
20+
21+
error: this file contains an unclosed delimiter
22+
--> $DIR/issue-107423-unused-delim-only-one-no-pair.rs:7:11
23+
|
24+
LL | fn a(){{{
25+
| --- ^
26+
| |||
27+
| ||unclosed delimiter
28+
| |unclosed delimiter
29+
| unclosed delimiter
30+
31+
error: aborting due to 3 previous errors
32+

0 commit comments

Comments
 (0)