Skip to content

Commit a584cc7

Browse files
authored
Rollup merge of rust-lang#139100 - petrochenkov:errbelow, r=jieyouxu
compiletest: Support matching diagnostics on lines below Using `//~vvv ERROR`. This is not needed often, but it's easy to support, and it allows to eliminate a class of `error-pattern`s that cannot be eliminated in any other way. See the diff for the examples of such patterns coming from parser. Some of them can be matched by `//~ ERROR` or `//~^ ERROR` as well (when the final newline is allowed), but it changes the shape of reported spans, so I chose to keep the spans by using `//~v ERROR`.
2 parents 821e0fe + cf451f0 commit a584cc7

31 files changed

+62
-48
lines changed

Diff for: src/doc/rustc-dev-guide/src/tests/ui.md

+15
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ several ways to match the message with the line (see the examples below):
202202
* `~|`: Associates the error level and message with the *same* line as the
203203
*previous comment*. This is more convenient than using multiple carets when
204204
there are multiple messages associated with the same line.
205+
* `~v`: Associates the error level and message with the *next* error
206+
annotation line. Each symbol (`v`) that you add adds a line to this, so `~vvv`
207+
is three lines below the error annotation line.
205208
* `~?`: Used to match error levels and messages with errors not having line
206209
information. These can be placed on any line in the test file, but are
207210
conventionally placed at the end.
@@ -273,6 +276,18 @@ fn main() {
273276
//~| ERROR this pattern has 1 field, but the corresponding tuple struct has 3 fields [E0023]
274277
```
275278

279+
#### Positioned above error line
280+
281+
Use the `//~v` idiom with number of v's in the string to indicate the number
282+
of lines below. This is typically used in lexer or parser tests matching on errors like unclosed
283+
delimiter or unclosed literal happening at the end of file.
284+
285+
```rust,ignore
286+
// ignore-tidy-trailing-newlines
287+
//~v ERROR this file contains an unclosed delimiter
288+
fn main((ؼ
289+
```
290+
276291
#### Error without line information
277292

278293
Use `//~?` to match an error without line information.

Diff for: src/tools/compiletest/src/errors.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,17 @@ fn parse_expected(
122122
// //~|
123123
// //~^
124124
// //~^^^^^
125+
// //~v
126+
// //~vvvvv
125127
// //~?
126128
// //[rev1]~
127129
// //[rev1,rev2]~^^
128130
static RE: OnceLock<Regex> = OnceLock::new();
129131

130132
let captures = RE
131-
.get_or_init(|| Regex::new(r"//(?:\[(?P<revs>[\w\-,]+)])?~(?P<adjust>\?|\||\^*)").unwrap())
133+
.get_or_init(|| {
134+
Regex::new(r"//(?:\[(?P<revs>[\w\-,]+)])?~(?P<adjust>\?|\||[v\^]*)").unwrap()
135+
})
132136
.captures(line)?;
133137

134138
match (test_revision, captures.name("revs")) {
@@ -164,6 +168,8 @@ fn parse_expected(
164168
(true, Some(last_nonfollow_error.expect("encountered //~| without preceding //~^ line")))
165169
} else if line_num_adjust == "?" {
166170
(false, None)
171+
} else if line_num_adjust.starts_with('v') {
172+
(false, Some(line_num + line_num_adjust.len()))
167173
} else {
168174
(false, Some(line_num - line_num_adjust.len()))
169175
};

Diff for: tests/ui/parser/issues/issue-103451.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ error-pattern: this file contains an unclosed delimiter
21
struct R { }
2+
//~vv ERROR this file contains an unclosed delimiter
33
struct S {
44
x: [u8; R

Diff for: tests/ui/parser/issues/issue-10636-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
//@ error-pattern: mismatched closing delimiter: `}`
21
// FIXME(31528) we emit a bunch of silly errors here due to continuing past the
32
// first one. This would be easy-ish to address by better recovery in tokenisation.
43

4+
//~vvvvv ERROR mismatched closing delimiter: `}`
55
pub fn trace_option(option: Option<isize>) {
66
option.map(|some| 42;
77

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// Fixed in #66054.
22
// ignore-tidy-trailing-newlines
3-
//@ error-pattern: this file contains an unclosed delimiter
4-
//@ error-pattern: aborting due to 1 previous error
3+
//~v ERROR this file contains an unclosed delimiter
54
#[Ѕ

Diff for: tests/ui/parser/issues/issue-58094-missing-right-square-bracket.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this file contains an unclosed delimiter
2-
--> $DIR/issue-58094-missing-right-square-bracket.rs:5:4
2+
--> $DIR/issue-58094-missing-right-square-bracket.rs:4:4
33
|
44
LL | #[Ѕ
55
| - ^

Diff for: tests/ui/parser/issues/issue-62524.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// ignore-tidy-trailing-newlines
2-
//@ error-pattern: aborting due to 1 previous error
2+
33
#![allow(uncommon_codepoints)]
44

5+
//~vv ERROR this file contains an unclosed delimiter
56
y![
67
Ϥ,

Diff for: tests/ui/parser/issues/issue-62524.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this file contains an unclosed delimiter
2-
--> $DIR/issue-62524.rs:6:3
2+
--> $DIR/issue-62524.rs:7:3
33
|
44
LL | y![
55
| - unclosed delimiter

Diff for: tests/ui/parser/issues/issue-62554.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
//@ error-pattern:this file contains an unclosed delimiter
2-
31
fn main() {}
42

3+
//~v ERROR this file contains an unclosed delimiter
54
fn foo(u: u8) { if u8 macro_rules! u8 { (u6) => { fn uuuuuuuuuuu() { use s loo mod u8 {

Diff for: tests/ui/parser/issues/issue-62554.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this file contains an unclosed delimiter
2-
--> $DIR/issue-62554.rs:5:89
2+
--> $DIR/issue-62554.rs:4:89
33
|
44
LL | fn foo(u: u8) { if u8 macro_rules! u8 { (u6) => { fn uuuuuuuuuuu() { use s loo mod u8 {
55
| - - - - -^

Diff for: tests/ui/parser/issues/issue-62894.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Regression test for #62894, shouldn't crash.
2-
//@ error-pattern: this file contains an unclosed delimiter
32

3+
//~vvv ERROR this file contains an unclosed delimiter
44
fn f() { assert_eq!(f(), (), assert_eq!(assert_eq!
55

66
fn main() {}

Diff for: tests/ui/parser/issues/issue-62973.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// ignore-tidy-trailing-newlines
2-
//@ error-pattern: aborting due to 3 previous errors
32

43
fn main() {}
54

5+
//~vvv ERROR mismatched closing delimiter: `)`
6+
//~vv ERROR mismatched closing delimiter: `)`
7+
//~vvv ERROR this file contains an unclosed delimiter
68
fn p() { match s { v, E { [) {) }
79

810

Diff for: tests/ui/parser/issues/issue-62973.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
error: mismatched closing delimiter: `)`
2-
--> $DIR/issue-62973.rs:6:27
2+
--> $DIR/issue-62973.rs:8:27
33
|
44
LL | fn p() { match s { v, E { [) {) }
55
| ^^ mismatched closing delimiter
66
| |
77
| unclosed delimiter
88

99
error: mismatched closing delimiter: `)`
10-
--> $DIR/issue-62973.rs:6:30
10+
--> $DIR/issue-62973.rs:8:30
1111
|
1212
LL | fn p() { match s { v, E { [) {) }
1313
| ^^ mismatched closing delimiter
1414
| |
1515
| unclosed delimiter
1616

1717
error: this file contains an unclosed delimiter
18-
--> $DIR/issue-62973.rs:8:2
18+
--> $DIR/issue-62973.rs:10:2
1919
|
2020
LL | fn p() { match s { v, E { [) {) }
2121
| - - - - missing open `(` for this delimiter

Diff for: tests/ui/parser/issues/issue-63116.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
// fixed by #66361
2-
//@ error-pattern: aborting due to 2 previous errors
2+
//~vv ERROR mismatched closing delimiter: `]`
3+
//~v ERROR this file contains an unclosed delimiter
34
impl W <s(f;Y(;]

Diff for: tests/ui/parser/issues/issue-63116.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error: mismatched closing delimiter: `]`
2-
--> $DIR/issue-63116.rs:3:14
2+
--> $DIR/issue-63116.rs:4:14
33
|
44
LL | impl W <s(f;Y(;]
55
| ^ ^ mismatched closing delimiter
66
| |
77
| unclosed delimiter
88

99
error: this file contains an unclosed delimiter
10-
--> $DIR/issue-63116.rs:3:18
10+
--> $DIR/issue-63116.rs:4:18
1111
|
1212
LL | impl W <s(f;Y(;]
1313
| - -^

Diff for: tests/ui/parser/issues/issue-63135.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
//@ error-pattern: this file contains an unclosed delimiter
2-
//@ error-pattern: aborting due to 1 previous error
1+
//~v ERROR this file contains an unclosed delimiter
32
fn i(n{...,f #

Diff for: tests/ui/parser/issues/issue-63135.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this file contains an unclosed delimiter
2-
--> $DIR/issue-63135.rs:3:16
2+
--> $DIR/issue-63135.rs:2:16
33
|
44
LL | fn i(n{...,f #
55
| - - ^

Diff for: tests/ui/parser/issues/issue-81804.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
//@ error-pattern: this file contains an unclosed delimiter
2-
//@ error-pattern: this file contains an unclosed delimiter
3-
41
fn main() {}
52

3+
//~vv ERROR mismatched closing delimiter: `}`
4+
//~v ERROR this file contains an unclosed delimiter
65
fn p([=(}

Diff for: tests/ui/parser/issues/issue-81804.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error: mismatched closing delimiter: `}`
2-
--> $DIR/issue-81804.rs:6:8
2+
--> $DIR/issue-81804.rs:5:8
33
|
44
LL | fn p([=(}
55
| ^^ mismatched closing delimiter
66
| |
77
| unclosed delimiter
88

99
error: this file contains an unclosed delimiter
10-
--> $DIR/issue-81804.rs:6:11
10+
--> $DIR/issue-81804.rs:5:11
1111
|
1212
LL | fn p([=(}
1313
| -- ^

Diff for: tests/ui/parser/issues/issue-81827.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
//@ error-pattern: this file contains an unclosed delimiter
2-
//@ error-pattern: mismatched closing delimiter: `]`
3-
41
#![crate_name="0"]
52

6-
7-
83
fn main() {}
94

5+
//~vv ERROR mismatched closing delimiter: `]`
6+
//~v ERROR this file contains an unclosed delimiter
107
fn r()->i{0|{#[cfg(r(0{]0

Diff for: tests/ui/parser/issues/issue-81827.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: mismatched closing delimiter: `]`
2-
--> $DIR/issue-81827.rs:10:23
2+
--> $DIR/issue-81827.rs:7:23
33
|
44
LL | fn r()->i{0|{#[cfg(r(0{]0
55
| - ^^ mismatched closing delimiter
@@ -8,7 +8,7 @@ LL | fn r()->i{0|{#[cfg(r(0{]0
88
| closing delimiter possibly meant for this
99

1010
error: this file contains an unclosed delimiter
11-
--> $DIR/issue-81827.rs:10:27
11+
--> $DIR/issue-81827.rs:7:27
1212
|
1313
LL | fn r()->i{0|{#[cfg(r(0{]0
1414
| - - - ^

Diff for: tests/ui/parser/issues/issue-84104.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
//@ error-pattern: this file contains an unclosed delimiter
1+
//~v ERROR this file contains an unclosed delimiter
22
#[i=i::<ښܖ<

Diff for: tests/ui/parser/issues/issue-84148-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
//@ error-pattern: this file contains an unclosed delimiter
1+
//~v ERROR this file contains an unclosed delimiter
22
fn f(t:for<>t?

Diff for: tests/ui/parser/issues/issue-88770.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Regression test for the ICE described in #88770.
22

3-
//@ error-pattern:this file contains an unclosed delimiter
4-
3+
//~vvvv ERROR this file contains an unclosed delimiter
54
fn m(){print!("",(c for&g
65
u
76
e

Diff for: tests/ui/parser/issues/issue-88770.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this file contains an unclosed delimiter
2-
--> $DIR/issue-88770.rs:8:3
2+
--> $DIR/issue-88770.rs:7:3
33
|
44
LL | fn m(){print!("",(c for&g
55
| - - - unclosed delimiter

Diff for: tests/ui/parser/mbe_missing_right_paren.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// ignore-tidy-trailing-newlines
2-
//@ error-pattern: this file contains an unclosed delimiter
2+
//~v ERROR this file contains an unclosed delimiter
33
macro_rules! abc(ؼ

Diff for: tests/ui/parser/missing_right_paren.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
// ignore-tidy-trailing-newlines
2-
//@ error-pattern: this file contains an unclosed delimiter
3-
//@ error-pattern: aborting due to 1 previous error
2+
//~v ERROR this file contains an unclosed delimiter
43
fn main((ؼ

Diff for: tests/ui/parser/missing_right_paren.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this file contains an unclosed delimiter
2-
--> $DIR/missing_right_paren.rs:4:11
2+
--> $DIR/missing_right_paren.rs:3:11
33
|
44
LL | fn main((ؼ
55
| -- ^

Diff for: tests/ui/parser/unbalanced-doublequote.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
//@ error-pattern: unterminated double quote string
2-
3-
1+
//~vv ERROR unterminated double quote string
42
fn main() {
53
"
64
}

Diff for: tests/ui/parser/unbalanced-doublequote.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0765]: unterminated double quote string
2-
--> $DIR/unbalanced-doublequote.rs:5:5
2+
--> $DIR/unbalanced-doublequote.rs:3:5
33
|
44
LL | / "
55
LL | | }

Diff for: tests/ui/parser/use-unclosed-brace.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@ error-pattern: this file contains an unclosed delimiter
21
use foo::{bar, baz;
32

43
use std::fmt::Display;
@@ -7,4 +6,5 @@ mod bar { }
76

87
mod baz { }
98

9+
//~v ERROR this file contains an unclosed delimiter
1010
fn main() {}

0 commit comments

Comments
 (0)