Skip to content

Commit cf451f0

Browse files
committed
compiletest: Support matching diagnostics on lines below
1 parent 928468c commit cf451f0

31 files changed

+62
-48
lines changed

src/doc/rustc-dev-guide/src/tests/ui.md

Lines changed: 15 additions & 0 deletions
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.

src/tools/compiletest/src/errors.rs

Lines changed: 7 additions & 1 deletion
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
};
Lines changed: 1 addition & 1 deletion
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

tests/ui/parser/issues/issue-10636-2.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 2 deletions
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
#[Ѕ

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

Lines changed: 1 addition & 1 deletion
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
| - ^

tests/ui/parser/issues/issue-62524.rs

Lines changed: 2 additions & 1 deletion
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
Ϥ,

tests/ui/parser/issues/issue-62524.stderr

Lines changed: 1 addition & 1 deletion
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

tests/ui/parser/issues/issue-62554.rs

Lines changed: 1 addition & 2 deletions
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 {

tests/ui/parser/issues/issue-62554.stderr

Lines changed: 1 addition & 1 deletion
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
| - - - - -^

0 commit comments

Comments
 (0)