Skip to content

Commit d8c54d4

Browse files
committed
Auto merge of rust-lang#139137 - petrochenkov:errwhere2, r=jieyouxu
compiletest: Require `//~` annotations even if `error-pattern` is specified This is continuation of rust-lang#138865 with some help from rust-lang#139100. `error-pattern` annotations that duplicate the newly added `//~` annotations are removed, other `error-pattern`s are not touched yet. In exceptional cases `//@ compile-flags: --error-format=human` can be used to opt out of these checks. In this PR I only had to use the opt out 3 times: - `tests/ui/parser/utf16-{be,le}-without-bom.rs` - there are too many errors that are nearly identical (modulo location), because an error is reported on every second symbol - `tests/ui-fulldeps/missing-rustc-driver-error.rs` - the errors list various rustc crate dependencies and may unexpectedly invalidate on random rustc changes
2 parents 4f0de4c + 5ca4dfc commit d8c54d4

File tree

315 files changed

+673
-530
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

315 files changed

+673
-530
lines changed

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

+3

src/tools/compiletest/src/runtest/ui.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,9 @@ impl TestCx<'_> {
169169
self.props.error_patterns
170170
);
171171

172-
let check_patterns = should_run == WillExecute::No
173-
&& (!self.props.error_patterns.is_empty()
174-
|| !self.props.regex_error_patterns.is_empty());
175172
if !explicit && self.config.compare_mode.is_none() {
176-
let check_annotations = !check_patterns || !expected_errors.is_empty();
177-
178-
if check_annotations {
179-
// "//~ERROR comments"
180-
self.check_expected_errors(expected_errors, &proc_res);
181-
}
173+
// "//~ERROR comments"
174+
self.check_expected_errors(expected_errors, &proc_res);
182175
} else if explicit && !expected_errors.is_empty() {
183176
let msg = format!(
184177
"line {}: cannot combine `--error-format` with {} annotations; use `error-pattern` instead",
@@ -188,7 +181,10 @@ impl TestCx<'_> {
188181
self.fatal(&msg);
189182
}
190183
let output_to_check = self.get_output(&proc_res);
191-
if check_patterns {
184+
if should_run == WillExecute::No
185+
&& (!self.props.error_patterns.is_empty()
186+
|| !self.props.regex_error_patterns.is_empty())
187+
{
192188
// "// error-pattern" comments
193189
self.check_all_error_patterns(&output_to_check, &proc_res, pm);
194190
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// test the behavior of the --no-run flag without the --test flag
22

33
//@ compile-flags:-Z unstable-options --no-run --test-args=--test-threads=1
4-
//@ error-pattern: the `--test` flag must be passed
54

65
pub fn f() {}
6+
7+
//~? ERROR the `--test` flag must be passed to enable `--no-run`
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
//@ compile-flags:--theme {{src-base}}/invalid-theme-name.rs
2-
//@ error-pattern: invalid argument
32
//@ error-pattern: must have a .css extension
3+
4+
//~? ERROR invalid argument: "$DIR/invalid-theme-name.rs"
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
//@ check-pass
22
//@ compile-flags: --passes list
3-
//@ error-pattern: the `passes` flag no longer functions
3+
4+
//~? WARN the `passes` flag no longer functions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
//@ error-pattern: no documentation found
21
//@ normalize-stderr: "nightly|beta|1\.[0-9][0-9]\.[0-9]" -> "$$CHANNEL"
32
#![deny(rustdoc::missing_crate_level_docs)]
43
//^~ NOTE defined here
54

65
pub fn foo() {}
6+
7+
//~? ERROR no documentation found for this crate's top-level module

tests/rustdoc-ui/lints/no-crate-level-doc-lint.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ error: no documentation found for this crate's top-level module
33
= help: The following guide may be of use:
44
https://doc.rust-lang.org/$CHANNEL/rustdoc/how-to-write-documentation.html
55
note: the lint level is defined here
6-
--> $DIR/no-crate-level-doc-lint.rs:3:9
6+
--> $DIR/no-crate-level-doc-lint.rs:2:9
77
|
88
LL | #![deny(rustdoc::missing_crate_level_docs)]
99
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/rustdoc-ui/track-diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
struct A;
99
struct B;
1010

11-
pub const S: A = B;
11+
pub const S: A = B; //~ ERROR mismatched types

tests/ui-fulldeps/missing-rustc-driver-error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Test that we get the following hint when trying to use a compiler crate without rustc_driver.
22
//@ error-pattern: try adding `extern crate rustc_driver;` at the top level of this crate
3-
//@ compile-flags: --emit link
3+
//@ compile-flags: --emit link --error-format=human
44
//@ normalize-stderr: ".*crate .* required.*\n\n" -> ""
55
//@ normalize-stderr: "aborting due to [0-9]+" -> "aborting due to NUMBER"
66

tests/ui/abi/fixed_x18.rs

+2
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@
2323

2424
#[lang = "sized"]
2525
trait Sized {}
26+
27+
//~? ERROR the `-Zfixed-x18` flag is not supported on the `

tests/ui/abi/shadow-call-stack-without-fixed-x18.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@ compile-flags: --target aarch64-unknown-none -Zsanitizer=shadow-call-stack
2-
//@ error-pattern: shadow-call-stack sanitizer is not supported for this target
32
//@ dont-check-compiler-stderr
43
//@ needs-llvm-components: aarch64
54

@@ -13,3 +12,5 @@ trait Sized {}
1312

1413
#[no_mangle]
1514
pub fn foo() {}
15+
16+
//~? ERROR shadow-call-stack sanitizer is not supported for this target

tests/ui/allocator/two-allocators2.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//@ aux-build:system-allocator.rs
22
//@ no-prefer-dynamic
3-
//@ error-pattern: the `#[global_allocator]` in
43

54
extern crate system_allocator;
65

@@ -10,3 +9,5 @@ use std::alloc::System;
109
static A: System = System;
1110

1211
fn main() {}
12+
13+
//~? ERROR the `#[global_allocator]` in this crate conflicts with global allocator in: system_allocator

tests/ui/allocator/two-allocators3.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//@ aux-build:system-allocator.rs
22
//@ aux-build:system-allocator2.rs
33
//@ no-prefer-dynamic
4-
//@ error-pattern: the `#[global_allocator]` in
5-
64

75
extern crate system_allocator;
86
extern crate system_allocator2;
97

108
fn main() {}
9+
10+
//~? ERROR the `#[global_allocator]` in system_allocator conflicts with global allocator in: system_allocator2

tests/ui/amdgpu-require-explicit-cpu.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//@ compile-flags: --crate-type=cdylib --target=amdgcn-amd-amdhsa
44
//@ needs-llvm-components: amdgpu
55
//@ needs-rust-lld
6-
//@[nocpu] error-pattern: target requires explicitly specifying a cpu
76
//@[nocpu] build-fail
87
//@[cpu] compile-flags: -Ctarget-cpu=gfx900
98
//@[cpu] build-pass
@@ -15,3 +14,5 @@
1514
trait Sized {}
1615

1716
pub fn foo() {}
17+
18+
//[nocpu]~? ERROR target requires explicitly specifying a cpu with `-C target-cpu`
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ error-pattern: aborting due to 1 previous error
22

33
fn main() {
4-
2 + +2;
4+
2 + +2; //~ ERROR leading `+` is not supported
55
}

tests/ui/attributes/attr-bad-crate-attr.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//!
44
//! See <https://doc.rust-lang.org/reference/attributes.html>.
55
6-
//@ error-pattern: expected item
7-
86
#![attr = "val"]
97
#[attr = "val"] // Unterminated
8+
//~^ ERROR expected item after attributes

tests/ui/attributes/attr-bad-crate-attr.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: expected item after attributes
2-
--> $DIR/attr-bad-crate-attr.rs:9:1
2+
--> $DIR/attr-bad-crate-attr.rs:7:1
33
|
44
LL | #[attr = "val"] // Unterminated
55
| ^^^^^^^^^^^^^^^
+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
// Show diagnostics for invalid tokens
22
//@ compile-flags: -Zcrate-attr=`%~@$#
3-
//@ error-pattern:unknown start of token
3+
44
fn main() {}
5+
6+
//~? ERROR unknown start of token: `
7+
//~? ERROR expected identifier, found `%`
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
//@ compile-flags: '-Zcrate-attr=feature(yeet_expr)]fn main(){}#[inline'
2-
//@ error-pattern:unexpected closing delimiter
2+
33
fn foo() {}
4+
5+
//~? ERROR unexpected closing delimiter: `]`
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//@ compile-flags: -Zcrate-attr=#![feature(foo)]
2-
//@ error-pattern:expected identifier
32

43
fn main() {}
4+
5+
//~? ERROR expected identifier, found `#`
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
//@ compile-flags: -Zcrate-attr=feature(foo),feature(bar)
2-
//@ error-pattern:invalid crate attr
2+
33
fn main() {}
4+
5+
//~? ERROR invalid crate attribute
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// Show diagnostics for unbalanced parens.
22
//@ compile-flags: -Zcrate-attr=(
3-
//@ error-pattern:unclosed delimiter
3+
44
fn main() {}
5+
6+
//~? ERROR this file contains an unclosed delimiter

tests/ui/binop/binop-bitxor-str.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
//@ error-pattern:no implementation for `String ^ String`
2-
31
fn main() { let x = "a".to_string() ^ "b".to_string(); }
2+
//~^ ERROR no implementation for `String ^ String`

tests/ui/binop/binop-bitxor-str.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0369]: no implementation for `String ^ String`
2-
--> $DIR/binop-bitxor-str.rs:3:37
2+
--> $DIR/binop-bitxor-str.rs:1:37
33
|
44
LL | fn main() { let x = "a".to_string() ^ "b".to_string(); }
55
| --------------- ^ --------------- String

tests/ui/binop/binop-mul-bool.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
//@ error-pattern:cannot multiply `bool` by `bool`
2-
3-
fn main() { let x = true * false; }
1+
fn main() { let x = true * false; } //~ ERROR cannot multiply `bool` by `bool`

tests/ui/binop/binop-mul-bool.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0369]: cannot multiply `bool` by `bool`
2-
--> $DIR/binop-mul-bool.rs:3:26
2+
--> $DIR/binop-mul-bool.rs:1:26
33
|
44
LL | fn main() { let x = true * false; }
55
| ---- ^ ----- bool

tests/ui/c-variadic/issue-86053-1.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
// Regression test for the ICE described in issue #86053.
2-
//@ error-pattern:unexpected `self` parameter in function
3-
//@ error-pattern:`...` must be the last argument of a C-variadic function
4-
//@ error-pattern:cannot find type `F` in this scope
5-
62

73
#![feature(c_variadic)]
84
#![crate_type="lib"]
95

106
fn ordering4 < 'a , 'b > ( a : , self , self , self ,
7+
//~^ ERROR expected type, found `,`
8+
//~| ERROR unexpected `self` parameter in function
9+
//~| ERROR unexpected `self` parameter in function
10+
//~| ERROR unexpected `self` parameter in function
1111
self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) {
12+
//~^ ERROR unexpected `self` parameter in function
13+
//~| ERROR unexpected `self` parameter in function
14+
//~| ERROR unexpected `self` parameter in function
15+
//~| ERROR `...` must be the last argument of a C-variadic function
16+
//~| ERROR only foreign, `unsafe extern "C"`, or `unsafe extern "C-unwind"` functions may have a C-variadic arg
17+
//~| ERROR cannot find type `F` in this scope
1218
}

tests/ui/c-variadic/issue-86053-1.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
error: expected type, found `,`
2-
--> $DIR/issue-86053-1.rs:10:47
2+
--> $DIR/issue-86053-1.rs:6:47
33
|
44
LL | fn ordering4 < 'a , 'b > ( a : , self , self , self ,
55
| ^ expected type
66

77
error: unexpected `self` parameter in function
8-
--> $DIR/issue-86053-1.rs:10:51
8+
--> $DIR/issue-86053-1.rs:6:51
99
|
1010
LL | fn ordering4 < 'a , 'b > ( a : , self , self , self ,
1111
| ^^^^ must be the first parameter of an associated function
1212

1313
error: unexpected `self` parameter in function
14-
--> $DIR/issue-86053-1.rs:10:58
14+
--> $DIR/issue-86053-1.rs:6:58
1515
|
1616
LL | fn ordering4 < 'a , 'b > ( a : , self , self , self ,
1717
| ^^^^ must be the first parameter of an associated function
1818

1919
error: unexpected `self` parameter in function
20-
--> $DIR/issue-86053-1.rs:10:67
20+
--> $DIR/issue-86053-1.rs:6:67
2121
|
2222
LL | fn ordering4 < 'a , 'b > ( a : , self , self , self ,
2323
| ^^^^ must be the first parameter of an associated function

tests/ui/capture1.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
//@ error-pattern: can't capture dynamic environment in a fn item
2-
31
fn main() {
42
let bar: isize = 5;
5-
fn foo() -> isize { return bar; }
3+
fn foo() -> isize { return bar; } //~ ERROR can't capture dynamic environment in a fn item
64
}

tests/ui/capture1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0434]: can't capture dynamic environment in a fn item
2-
--> $DIR/capture1.rs:5:32
2+
--> $DIR/capture1.rs:3:32
33
|
44
LL | fn foo() -> isize { return bar; }
55
| ^^^

tests/ui/cast/cast-from-nil.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
//@ error-pattern: non-primitive cast: `()` as `u32`
2-
fn main() { let u = (assert!(true) as u32); }
1+
fn main() { let u = (assert!(true) as u32); } //~ ERROR non-primitive cast: `()` as `u32`

tests/ui/cast/cast-from-nil.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0605]: non-primitive cast: `()` as `u32`
2-
--> $DIR/cast-from-nil.rs:2:21
2+
--> $DIR/cast-from-nil.rs:1:21
33
|
44
LL | fn main() { let u = (assert!(true) as u32); }
55
| ^^^^^^^^^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object

tests/ui/cast/cast-to-nil.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
//@ error-pattern: non-primitive cast: `u32` as `()`
2-
fn main() { let u = 0u32 as (); }
1+
fn main() { let u = 0u32 as (); } //~ ERROR non-primitive cast: `u32` as `()`

tests/ui/cast/cast-to-nil.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0605]: non-primitive cast: `u32` as `()`
2-
--> $DIR/cast-to-nil.rs:2:21
2+
--> $DIR/cast-to-nil.rs:1:21
33
|
44
LL | fn main() { let u = 0u32 as (); }
55
| ^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object

tests/ui/cfg/cfg_false_no_std-2.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
// Error, the linked empty library is `no_std` and doesn't provide a panic handler.
22

3-
//@ dont-check-compiler-stderr
3+
//@ compile-flags: --error-format=human
44
//@ error-pattern: `#[panic_handler]` function required, but not found
5+
//@ dont-check-compiler-stderr
56
//@ aux-build: cfg_false_lib_no_std_before.rs
67

78
#![no_std]
89

910
extern crate cfg_false_lib_no_std_before as _;
1011

1112
fn main() {}
13+
14+
// FIXME: The second error is target-dependent.
15+
//FIXME~? ERROR `#[panic_handler]` function required, but not found
16+
//FIXME~? ERROR unwinding panics are not supported without std

tests/ui/codegen/mismatched-data-layouts.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//@ build-fail
44
//@ needs-llvm-components: x86
55
//@ compile-flags: --crate-type=lib --target={{src-base}}/codegen/mismatched-data-layout.json -Z unstable-options
6-
//@ error-pattern: differs from LLVM target's
76
//@ normalize-stderr: "`, `[A-Za-z0-9-:]*`" -> "`, `normalized data layout`"
87
//@ normalize-stderr: "layout, `[A-Za-z0-9-:]*`" -> "layout, `normalized data layout`"
98

@@ -12,3 +11,5 @@
1211

1312
#[lang = "sized"]
1413
trait Sized {}
14+
15+
//~? ERROR differs from LLVM target's
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
//@ compile-flags: --cfg a::b
2-
//@ error-pattern: invalid `--cfg` argument: `a::b` (argument key must be an identifier)
2+
33
fn main() {}
4+
5+
//~? ERROR invalid `--cfg` argument: `a::b` (argument key must be an identifier)
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
//@ compile-flags: --cfg a=10
2-
//@ error-pattern: invalid `--cfg` argument: `a=10` (argument value must be a string)
2+
33
fn main() {}
4+
5+
//~? ERROR invalid `--cfg` argument: `a=10` (argument value must be a string)
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
//@ error-pattern: `main` function not found
21
//@ compile-flags: --cfg foo --check-cfg=cfg(foo,bar)
32

43
// main is conditionally compiled, but the conditional compilation
54
// is conditional too!
65

76
#[cfg_attr(foo, cfg(bar))]
8-
fn main() { }
7+
fn main() { } //~ ERROR `main` function not found in crate `cfg_attr_cfg_2`

tests/ui/conditional-compilation/cfg-attr-cfg-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0601]: `main` function not found in crate `cfg_attr_cfg_2`
2-
--> $DIR/cfg-attr-cfg-2.rs:8:14
2+
--> $DIR/cfg-attr-cfg-2.rs:7:14
33
|
44
LL | fn main() { }
55
| ^ consider adding a `main` function to `$DIR/cfg-attr-cfg-2.rs`
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
//@ error-pattern: `main` function not found
2-
3-
#![cfg(FALSE)]
1+
#![cfg(FALSE)] //~ ERROR `main` function not found in crate `cfg_in_crate_1`

tests/ui/conditional-compilation/cfg-in-crate-1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0601]: `main` function not found in crate `cfg_in_crate_1`
2-
--> $DIR/cfg-in-crate-1.rs:3:15
2+
--> $DIR/cfg-in-crate-1.rs:1:15
33
|
44
LL | #![cfg(FALSE)]
55
| ^ consider adding a `main` function to `$DIR/cfg-in-crate-1.rs`

0 commit comments

Comments
 (0)