Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 9fa0c8e

Browse files
authored
Rollup merge of rust-lang#119184 - Rajveer100:branch-for-issue-118752, r=davidtwco
Switch from using `//~ERROR` annotations with `--error-format` to `error-pattern` Fixes rust-lang#118752 As noticed by ```@jyn514``` while working on a patch, tests failed due to `//~ERROR` annotations used in combination with the older `--error-format` which is now `error-pattern`.
2 parents 08c822f + af44e71 commit 9fa0c8e

22 files changed

+664
-651
lines changed

src/tools/compiletest/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use once_cell::sync::Lazy;
1111
use regex::Regex;
1212
use tracing::*;
1313

14-
#[derive(Clone, Debug, PartialEq)]
14+
#[derive(Copy, Clone, Debug, PartialEq)]
1515
pub enum ErrorKind {
1616
Help,
1717
Error,

src/tools/compiletest/src/runtest.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3977,23 +3977,29 @@ impl<'test> TestCx<'test> {
39773977
proc_res.status,
39783978
self.props.error_patterns
39793979
);
3980-
if !explicit && self.config.compare_mode.is_none() {
3981-
let check_patterns = should_run == WillExecute::No
3982-
&& (!self.props.error_patterns.is_empty()
3983-
|| !self.props.regex_error_patterns.is_empty());
39843980

3981+
let check_patterns = should_run == WillExecute::No
3982+
&& (!self.props.error_patterns.is_empty()
3983+
|| !self.props.regex_error_patterns.is_empty());
3984+
if !explicit && self.config.compare_mode.is_none() {
39853985
let check_annotations = !check_patterns || !expected_errors.is_empty();
39863986

3987-
if check_patterns {
3988-
// "// error-pattern" comments
3989-
let output_to_check = self.get_output(&proc_res);
3990-
self.check_all_error_patterns(&output_to_check, &proc_res, pm);
3991-
}
3992-
39933987
if check_annotations {
39943988
// "//~ERROR comments"
39953989
self.check_expected_errors(expected_errors, &proc_res);
39963990
}
3991+
} else if explicit && !expected_errors.is_empty() {
3992+
let msg = format!(
3993+
"line {}: cannot combine `--error-format` with {} annotations; use `error-pattern` instead",
3994+
expected_errors[0].line_num,
3995+
expected_errors[0].kind.unwrap_or(ErrorKind::Error),
3996+
);
3997+
self.fatal(&msg);
3998+
}
3999+
if check_patterns {
4000+
// "// error-pattern" comments
4001+
let output_to_check = self.get_output(&proc_res);
4002+
self.check_all_error_patterns(&output_to_check, &proc_res, pm);
39974003
}
39984004

39994005
if self.props.run_rustfix && self.config.compare_mode.is_none() {
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// compile-flags:--test --error-format=short
2+
// check-stdout
3+
// error-pattern:cannot find function `foo` in this scope
24
// normalize-stdout-test: "tests/rustdoc-ui/issues" -> "$$DIR"
35
// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
46
// failure-status: 101
57

68
/// ```rust
79
/// foo();
810
/// ```
9-
//~^^ ERROR cannot find function `foo` in this scope
1011
fn foo() {
1112
println!("Hello, world!");
1213
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11

22
running 1 test
3-
test $DIR/issue-81662-shortness.rs - foo (line 6) ... FAILED
3+
test $DIR/issue-81662-shortness.rs - foo (line 8) ... FAILED
44

55
failures:
66

7-
---- $DIR/issue-81662-shortness.rs - foo (line 6) stdout ----
8-
$DIR/issue-81662-shortness.rs:7:1: error[E0425]: cannot find function `foo` in this scope
7+
---- $DIR/issue-81662-shortness.rs - foo (line 8) stdout ----
8+
$DIR/issue-81662-shortness.rs:9:1: error[E0425]: cannot find function `foo` in this scope
99
error: aborting due to 1 previous error
1010
Couldn't compile the test.
1111

1212
failures:
13-
$DIR/issue-81662-shortness.rs - foo (line 6)
13+
$DIR/issue-81662-shortness.rs - foo (line 8)
1414

1515
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
1616

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// compile-flags: --error-format human-annotate-rs -Z unstable-options
2+
// error-pattern:cannot find type `Iter` in this scope
23

34
pub fn main() {
4-
let x: Iter; //~ ERROR cannot find type `Iter` in this scope
5+
let x: Iter;
56
}

tests/ui/annotate-snippet/missing-type.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0412]: cannot find type `Iter` in this scope
2-
--> $DIR/missing-type.rs:4:12
2+
--> $DIR/missing-type.rs:5:12
33
|
44
LL | let x: Iter;
55
| ^^^^ not found in this scope
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// aux-build:multispan.rs
2+
// error-pattern:hello to you, too!
23
// compile-flags: --error-format human-annotate-rs -Z unstable-options
34

45
#![feature(proc_macro_hygiene)]
@@ -12,17 +13,17 @@ fn main() {
1213
hello!();
1314

1415
// Exactly one 'hi'.
15-
hello!(hi); //~ ERROR hello to you, too!
16+
hello!(hi);
1617

1718
// Now two, back to back.
18-
hello!(hi hi); //~ ERROR hello to you, too!
19+
hello!(hi hi);
1920

2021
// Now three, back to back.
21-
hello!(hi hi hi); //~ ERROR hello to you, too!
22+
hello!(hi hi hi);
2223

2324
// Now several, with spacing.
24-
hello!(hi hey hi yo hi beep beep hi hi); //~ ERROR hello to you, too!
25-
hello!(hi there, hi how are you? hi... hi.); //~ ERROR hello to you, too!
26-
hello!(whoah. hi di hi di ho); //~ ERROR hello to you, too!
27-
hello!(hi good hi and good bye); //~ ERROR hello to you, too!
25+
hello!(hi hey hi yo hi beep beep hi hi);
26+
hello!(hi there, hi how are you? hi... hi.);
27+
hello!(whoah. hi di hi di ho);
28+
hello!(hi good hi and good bye);
2829
}

tests/ui/annotate-snippet/multispan.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
error: hello to you, too!
2-
--> $DIR/multispan.rs:15:5
2+
--> $DIR/multispan.rs:16:5
33
|
44
LL | hello!(hi);
55
| ^^^^^^^^^^
66
|
77
error: hello to you, too!
8-
--> $DIR/multispan.rs:18:5
8+
--> $DIR/multispan.rs:19:5
99
|
1010
LL | hello!(hi hi);
1111
| ^^^^^^^^^^^^^
1212
|
1313
error: hello to you, too!
14-
--> $DIR/multispan.rs:21:5
14+
--> $DIR/multispan.rs:22:5
1515
|
1616
LL | hello!(hi hi hi);
1717
| ^^^^^^^^^^^^^^^^
1818
|
1919
error: hello to you, too!
20-
--> $DIR/multispan.rs:24:5
20+
--> $DIR/multispan.rs:25:5
2121
|
2222
LL | hello!(hi hey hi yo hi beep beep hi hi);
2323
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2424
|
2525
error: hello to you, too!
26-
--> $DIR/multispan.rs:25:5
26+
--> $DIR/multispan.rs:26:5
2727
|
2828
LL | hello!(hi there, hi how are you? hi... hi.);
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3030
|
3131
error: hello to you, too!
32-
--> $DIR/multispan.rs:26:5
32+
--> $DIR/multispan.rs:27:5
3333
|
3434
LL | hello!(whoah. hi di hi di ho);
3535
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3636
|
3737
error: hello to you, too!
38-
--> $DIR/multispan.rs:27:5
38+
--> $DIR/multispan.rs:28:5
3939
|
4040
LL | hello!(hi good hi and good bye);
4141
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// compile-flags: --diagnostic-width=20 --error-format=json
2+
// error-pattern:expected `()`, found integer
23

34
// This test checks that `-Z output-width` effects the JSON error output by restricting it to an
45
// arbitrarily low value so that the effect is visible.
56

67
fn main() {
78
let _: () = 42;
8-
//~^ ERROR arguments to this function are incorrect
99
}

tests/ui/diagnostic-width/flag-json.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ This error occurs when an expression was used in a place where the compiler
2424
expected an expression of a different type. It can occur in several cases, the
2525
most common being when calling a function and passing an argument which has a
2626
different type than the matching type in the function declaration.
27-
"},"level":"error","spans":[{"file_name":"$DIR/flag-json.rs","byte_start":243,"byte_end":245,"line_start":7,"line_end":7,"column_start":17,"column_end":19,"is_primary":true,"text":[{"text":" let _: () = 42;","highlight_start":17,"highlight_end":19}],"label":"expected `()`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/flag-json.rs","byte_start":238,"byte_end":240,"line_start":7,"line_end":7,"column_start":12,"column_end":14,"is_primary":false,"text":[{"text":" let _: () = 42;","highlight_start":12,"highlight_end":14}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"error[E0308]: mismatched types
28-
--> $DIR/flag-json.rs:7:17
27+
"},"level":"error","spans":[{"file_name":"$DIR/flag-json.rs","byte_start":289,"byte_end":291,"line_start":8,"line_end":8,"column_start":17,"column_end":19,"is_primary":true,"text":[{"text":" let _: () = 42;","highlight_start":17,"highlight_end":19}],"label":"expected `()`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/flag-json.rs","byte_start":284,"byte_end":286,"line_start":8,"line_end":8,"column_start":12,"column_end":14,"is_primary":false,"text":[{"text":" let _: () = 42;","highlight_start":12,"highlight_end":14}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"error[E0308]: mismatched types
28+
--> $DIR/flag-json.rs:8:17
2929
|
3030
LL | ..._: () = 42;
3131
| -- ^^ expected `()`, found integer

0 commit comments

Comments
 (0)