Skip to content

Commit af44e71

Browse files
committed
Switch from using //~ERROR annotations with --error-format to error-pattern
Resolves Issue #118752
1 parent be69926 commit af44e71

22 files changed

+664
-651
lines changed

src/tools/compiletest/src/errors.rs

+1-1
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

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

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

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

39984004
if self.props.run_rustfix && self.config.compare_mode.is_none() {
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
}
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

+2-1
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

+1-1
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
+8-7
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

+7-7
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
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+1-1
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

+2-2
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

tests/ui/lint/unused_parens_json_suggestion.fixed

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// compile-flags: --error-format json
2+
// error-pattern:unnecessary parentheses
23
// run-rustfix
34

45
// The output for humans should just highlight the whole span without showing
@@ -13,7 +14,7 @@
1314
fn main() {
1415
// We want to suggest the properly-balanced expression `1 / (2 + 3)`, not
1516
// the malformed `1 / (2 + 3`
16-
let _a = 1 / (2 + 3); //~ERROR unnecessary parentheses
17+
let _a = 1 / (2 + 3);
1718
f();
1819
}
1920

tests/ui/lint/unused_parens_json_suggestion.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// compile-flags: --error-format json
2+
// error-pattern:unnecessary parentheses
23
// run-rustfix
34

45
// The output for humans should just highlight the whole span without showing
@@ -13,7 +14,7 @@
1314
fn main() {
1415
// We want to suggest the properly-balanced expression `1 / (2 + 3)`, not
1516
// the malformed `1 / (2 + 3`
16-
let _a = (1 / (2 + 3)); //~ERROR unnecessary parentheses
17+
let _a = (1 / (2 + 3));
1718
f();
1819
}
1920

tests/ui/lint/unused_parens_json_suggestion.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
{"$message_type":"diagnostic","message":"unnecessary parentheses around assigned value","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":577,"byte_end":578,"line_start":16,"line_end":16,"column_start":14,"column_end":15,"is_primary":true,"text":[{"text":" let _a = (1 / (2 + 3));
2-
--> $DIR/unused_parens_json_suggestion.rs:16:14
1+
{"$message_type":"diagnostic","message":"unnecessary parentheses around assigned value","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":618,"byte_end":619,"line_start":17,"line_end":17,"column_start":14,"column_end":15,"is_primary":true,"text":[{"text":" let _a = (1 / (2 + 3));","highlight_start":14,"highlight_end":15}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":630,"byte_end":631,"line_start":17,"line_end":17,"column_start":26,"column_end":27,"is_primary":true,"text":[{"text":" let _a = (1 / (2 + 3));","highlight_start":26,"highlight_end":27}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"the lint level is defined here","code":null,"level":"note","spans":[{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":436,"byte_end":449,"line_start":11,"line_end":11,"column_start":9,"column_end":22,"is_primary":true,"text":[{"text":"#![deny(unused_parens)]","highlight_start":9,"highlight_end":22}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":null},{"message":"remove these parentheses","code":null,"level":"help","spans":[{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":618,"byte_end":619,"line_start":17,"line_end":17,"column_start":14,"column_end":15,"is_primary":true,"text":[{"text":" let _a = (1 / (2 + 3));","highlight_start":14,"highlight_end":15}],"label":null,"suggested_replacement":"","suggestion_applicability":"MachineApplicable","expansion":null},{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":630,"byte_end":631,"line_start":17,"line_end":17,"column_start":26,"column_end":27,"is_primary":true,"text":[{"text":" let _a = (1 / (2 + 3));","highlight_start":26,"highlight_end":27}],"label":null,"suggested_replacement":"","suggestion_applicability":"MachineApplicable","expansion":null}],"children":[],"rendered":null}],"rendered":"error: unnecessary parentheses around assigned value
2+
--> $DIR/unused_parens_json_suggestion.rs:17:14
33
|
44
LL | let _a = (1 / (2 + 3));
55
| ^ ^
66
|
77
note: the lint level is defined here
8-
--> $DIR/unused_parens_json_suggestion.rs:10:9
8+
--> $DIR/unused_parens_json_suggestion.rs:11:9
99
|
1010
LL | #![deny(unused_parens)]
1111
| ^^^^^^^^^^^^^

tests/ui/lint/unused_parens_remove_json_suggestion.fixed

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// compile-flags: --error-format json
2+
// error-pattern:unnecessary parentheses
23
// run-rustfix
34

45
// The output for humans should just highlight the whole span without showing
@@ -14,7 +15,7 @@ fn main() {
1415

1516
let _b = false;
1617

17-
if _b { //~ ERROR unnecessary parentheses
18+
if _b {
1819
println!("hello");
1920
}
2021

@@ -25,29 +26,29 @@ fn main() {
2526
fn f() -> bool {
2627
let c = false;
2728

28-
if c { //~ ERROR unnecessary parentheses
29+
if c {
2930
println!("next");
3031
}
3132

32-
if c { //~ ERROR unnecessary parentheses
33+
if c {
3334
println!("prev");
3435
}
3536

3637
while false && true {
37-
if c { //~ ERROR unnecessary parentheses
38+
if c {
3839
println!("norm");
3940
}
4041

4142
}
4243

43-
while true && false { //~ ERROR unnecessary parentheses
44-
for _ in 0 .. 3 { //~ ERROR unnecessary parentheses
44+
while true && false {
45+
for _ in 0 .. 3 {
4546
println!("e~")
4647
}
4748
}
4849

49-
for _ in 0 .. 3 { //~ ERROR unnecessary parentheses
50-
while true && false { //~ ERROR unnecessary parentheses
50+
for _ in 0 .. 3 {
51+
while true && false {
5152
println!("e~")
5253
}
5354
}

tests/ui/lint/unused_parens_remove_json_suggestion.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// compile-flags: --error-format json
2+
// error-pattern:unnecessary parentheses
23
// run-rustfix
34

45
// The output for humans should just highlight the whole span without showing
@@ -14,7 +15,7 @@ fn main() {
1415

1516
let _b = false;
1617

17-
if (_b) { //~ ERROR unnecessary parentheses
18+
if (_b) {
1819
println!("hello");
1920
}
2021

@@ -25,29 +26,29 @@ fn main() {
2526
fn f() -> bool {
2627
let c = false;
2728

28-
if(c) { //~ ERROR unnecessary parentheses
29+
if(c) {
2930
println!("next");
3031
}
3132

32-
if (c){ //~ ERROR unnecessary parentheses
33+
if (c){
3334
println!("prev");
3435
}
3536

3637
while (false && true){
37-
if (c) { //~ ERROR unnecessary parentheses
38+
if (c) {
3839
println!("norm");
3940
}
4041

4142
}
4243

43-
while(true && false) { //~ ERROR unnecessary parentheses
44-
for _ in (0 .. 3){ //~ ERROR unnecessary parentheses
44+
while(true && false) {
45+
for _ in (0 .. 3){
4546
println!("e~")
4647
}
4748
}
4849

49-
for _ in (0 .. 3) { //~ ERROR unnecessary parentheses
50-
while (true && false) { //~ ERROR unnecessary parentheses
50+
for _ in (0 .. 3) {
51+
while (true && false) {
5152
println!("e~")
5253
}
5354
}

0 commit comments

Comments
 (0)