Skip to content

UI tests: migrate remaining compile time error-patterns to line annotations when possible #139760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion tests/incremental/const-generic-type-cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//
//@ compile-flags: -Zincremental-ignore-spans
//@ revisions: cpass cfail
//@ error-pattern: cycle detected when computing type of `Bar::N`

#![feature(trait_alias)]
#![crate_type="lib"]
Expand All @@ -13,5 +12,9 @@ trait Bar<const N: usize> {}

#[cfg(cfail)]
trait Bar<const N: dyn BB> {}
//[cfail]~^ ERROR cycle detected when computing type of `Bar::N`
//[cfail]~| ERROR cycle detected when computing type of `Bar::N`
//[cfail]~| ERROR cycle detected when computing type of `Bar::N`
//[cfail]~| ERROR `(dyn Bar<{ 2 + 1 }> + 'static)` is forbidden as the type of a const generic parameter

trait BB = Bar<{ 2 + 1 }>;
3 changes: 1 addition & 2 deletions tests/incremental/delayed_span_bug.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//@ revisions: cfail1 cfail2
//@ should-ice
//@ error-pattern: delayed bug triggered by #[rustc_delayed_bug_from_inside_query]

#![feature(rustc_attrs)]

#[rustc_delayed_bug_from_inside_query]
fn main() {}
fn main() {} //~ ERROR delayed bug triggered by #[rustc_delayed_bug_from_inside_query]
3 changes: 2 additions & 1 deletion tests/incremental/link_order/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@ aux-build:my_lib.rs
//@ error-pattern: error: linking with
//@ revisions:cfail1 cfail2
//@ compile-flags:-Z query-dep-graph

Expand All @@ -10,3 +9,5 @@
extern crate my_lib;

fn main() {}

//~? ERROR linking with
1 change: 0 additions & 1 deletion tests/rustdoc-ui/deprecated-attrs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@ compile-flags: --passes unknown-pass
//@ error-pattern: the `passes` flag no longer functions

#![doc(no_default_passes)]
//~^ ERROR unknown `doc` attribute `no_default_passes`
Expand Down
6 changes: 3 additions & 3 deletions tests/rustdoc-ui/deprecated-attrs.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ warning: the `passes` flag no longer functions
= help: you may want to use --document-private-items

error: unknown `doc` attribute `no_default_passes`
--> $DIR/deprecated-attrs.rs:4:8
--> $DIR/deprecated-attrs.rs:3:8
|
LL | #![doc(no_default_passes)]
| ^^^^^^^^^^^^^^^^^ no longer functions
Expand All @@ -15,7 +15,7 @@ LL | #![doc(no_default_passes)]
= note: `#[deny(invalid_doc_attributes)]` on by default

error: unknown `doc` attribute `passes`
--> $DIR/deprecated-attrs.rs:11:8
--> $DIR/deprecated-attrs.rs:10:8
|
LL | #![doc(passes = "collapse-docs unindent-comments")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no longer functions
Expand All @@ -25,7 +25,7 @@ LL | #![doc(passes = "collapse-docs unindent-comments")]
= note: `doc(passes)` is now a no-op

error: unknown `doc` attribute `plugins`
--> $DIR/deprecated-attrs.rs:17:8
--> $DIR/deprecated-attrs.rs:16:8
|
LL | #![doc(plugins = "xxx")]
| ^^^^^^^^^^^^^^^ no longer functions
Expand Down
2 changes: 1 addition & 1 deletion tests/rustdoc-ui/invalid-theme-name.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags:--theme {{src-base}}/invalid-theme-name.rs
//@ error-pattern: must have a .css extension

//~? ERROR invalid argument: "$DIR/invalid-theme-name.rs"
//~? HELP must have a .css extension
8 changes: 6 additions & 2 deletions tests/ui-fulldeps/missing-rustc-driver-error.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// Test that we get the following hint when trying to use a compiler crate without rustc_driver.
//@ error-pattern: try adding `extern crate rustc_driver;` at the top level of this crate
//@ compile-flags: --emit link --error-format=human
//@ compile-flags: --emit link
//@ normalize-stderr: ".*crate .* required.*\n\n" -> ""
//@ normalize-stderr: "aborting due to [0-9]+" -> "aborting due to NUMBER"
//@ dont-require-annotations: ERROR

#![feature(rustc_private)]

extern crate rustc_serialize;

fn main() {}

//~? HELP try adding `extern crate rustc_driver;` at the top level of this crate
//~? HELP try adding `extern crate rustc_driver;` at the top level of this crate
//~? HELP try adding `extern crate rustc_driver;` at the top level of this crate
1 change: 0 additions & 1 deletion tests/ui/abi/fixed_x18.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Behavior on aarch64 is tested by tests/codegen/fixed-x18.rs.
//
//@ revisions: x64 i686 arm riscv32 riscv64
//@ error-pattern: the `-Zfixed-x18` flag is not supported
//@ dont-check-compiler-stderr
//
//@ compile-flags: -Zfixed-x18
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/associated-types/issue-36499.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//@ error-pattern: aborting due to 1 previous error

fn main() {
2 + +2; //~ ERROR leading `+` is not supported
}
2 changes: 1 addition & 1 deletion tests/ui/associated-types/issue-36499.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: leading `+` is not supported
--> $DIR/issue-36499.rs:4:9
--> $DIR/issue-36499.rs:2:9
|
LL | 2 + +2;
| ^ unexpected `+`
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/check-cfg/cargo-feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//@ [none]compile-flags: --check-cfg=cfg(feature,values())
//@ [some]compile-flags: --check-cfg=cfg(feature,values("bitcode"))
//@ [some]compile-flags: --check-cfg=cfg(CONFIG_NVME,values("y"))
//@ [none]error-pattern:Cargo.toml
//@ dont-require-annotations: HELP

#[cfg(feature = "serde")]
//~^ WARNING unexpected `cfg` condition value
Expand All @@ -27,6 +27,7 @@ fn tokio() {}
#[cfg(CONFIG_NVME = "m")]
//[none]~^ WARNING unexpected `cfg` condition name
//[some]~^^ WARNING unexpected `cfg` condition value
//[none]~| HELP Cargo.toml
fn tokio() {}

fn main() {}
4 changes: 3 additions & 1 deletion tests/ui/codegen/empty-static-libs-issue-108825.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

//@ compile-flags: -Cpanic=abort --print=native-static-libs
//@ build-pass
//@ error-pattern: note: native-static-libs:
//@ dont-check-compiler-stderr (libcore links `/defaultlib:msvcrt` or `/defaultlib:libcmt` on MSVC)
//@ ignore-pass (the note is emitted later in the compilation pipeline, needs build)

Expand All @@ -14,3 +13,6 @@
fn panic(_info: &core::panic::PanicInfo) -> ! {
loop {}
}

//~? NOTE native-static-libs:
//~? NOTE Link against the following native artifacts when linking against this static library
6 changes: 4 additions & 2 deletions tests/ui/conditional-compilation/cfg-arg-invalid-1.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//@ compile-flags: --error-format=human --cfg a(b=c)
//@ error-pattern: invalid `--cfg` argument: `a(b=c)` (expected `key` or `key="value"`, ensure escaping is appropriate for your shell, try 'key="value"' or key=\"value\")
//@ compile-flags: --cfg a(b=c)

fn main() {}

//~? ERROR invalid `--cfg` argument: `a(b=c)` (expected `key` or `key="value"`, ensure escaping is appropriate for your shell, try 'key="value"' or key=\"value\")
6 changes: 4 additions & 2 deletions tests/ui/conditional-compilation/cfg-arg-invalid-2.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//@ compile-flags: --error-format=human --cfg a{b}
//@ error-pattern: invalid `--cfg` argument: `a{b}` (expected `key` or `key="value"`)
//@ compile-flags: --cfg a{b}

fn main() {}

//~? ERROR invalid `--cfg` argument: `a{b}` (expected `key` or `key="value"`)
6 changes: 4 additions & 2 deletions tests/ui/conditional-compilation/cfg-arg-invalid-4.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//@ compile-flags: --error-format=human --cfg a(b)
//@ error-pattern: invalid `--cfg` argument: `a(b)` (expected `key` or `key="value"`)
//@ compile-flags: --cfg a(b)

fn main() {}

//~? ERROR invalid `--cfg` argument: `a(b)` (expected `key` or `key="value"`)
6 changes: 4 additions & 2 deletions tests/ui/conditional-compilation/cfg-arg-invalid-6.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//@ compile-flags: --error-format=human --cfg a{
//@ error-pattern: invalid `--cfg` argument: `a{` (expected `key` or `key="value"`)
//@ compile-flags: --cfg a{

fn main() {}

//~? ERROR invalid `--cfg` argument: `a{` (expected `key` or `key="value"`)
6 changes: 4 additions & 2 deletions tests/ui/conditional-compilation/cfg-arg-invalid-8.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//@ compile-flags: --error-format=human --cfg )
//@ error-pattern: invalid `--cfg` argument: `)` (expected `key` or `key="value"`)
//@ compile-flags: --cfg )

fn main() {}

//~? ERROR invalid `--cfg` argument: `)` (expected `key` or `key="value"`)
6 changes: 4 additions & 2 deletions tests/ui/conditional-compilation/cfg-arg-invalid-9.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Test for missing quotes around value, issue #66450.
//@ compile-flags: --error-format=human --cfg key=value
//@ error-pattern: invalid `--cfg` argument: `key=value` (expected `key` or `key="value"`, ensure escaping is appropriate for your shell, try 'key="value"' or key=\"value\")
//@ compile-flags: --cfg key=value

fn main() {}

//~? ERROR invalid `--cfg` argument: `key=value` (expected `key` or `key="value"`, ensure escaping is appropriate for your shell, try 'key="value"' or key=\"value\")
6 changes: 3 additions & 3 deletions tests/ui/conditional-compilation/cfg-empty-codemap.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Tests that empty source_maps don't ICE (#23301)

//@ compile-flags: --error-format=human --cfg ""

//@ error-pattern: invalid `--cfg` argument: `""` (expected `key` or `key="value"`)
//@ compile-flags: --cfg ""

pub fn main() {
}

//~? ERROR invalid `--cfg` argument: `""` (expected `key` or `key="value"`)
3 changes: 2 additions & 1 deletion tests/ui/consts/miri_unleashed/drop.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@ compile-flags: -Zunleash-the-miri-inside-of-you
//@ error-pattern: calling non-const function `<Vec<i32> as Drop>::drop`

use std::mem::ManuallyDrop;

Expand All @@ -15,5 +14,7 @@ static TEST_OK: () = {
static TEST_BAD: () = {
let _v: Vec<i32> = Vec::new();
}; //~ ERROR could not evaluate static initializer
//~| NOTE calling non-const function `<Vec<i32> as Drop>::drop`
//~| NOTE inside `std::ptr::drop_in_place::<Vec<i32>> - shim(Some(Vec<i32>))`

//~? WARN skipping const checks
4 changes: 2 additions & 2 deletions tests/ui/consts/miri_unleashed/drop.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0080]: could not evaluate static initializer
--> $DIR/drop.rs:17:1
--> $DIR/drop.rs:16:1
|
LL | };
| ^ calling non-const function `<Vec<i32> as Drop>::drop`
Expand All @@ -10,7 +10,7 @@ note: inside `std::ptr::drop_in_place::<Vec<i32>> - shim(Some(Vec<i32>))`
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
--> $DIR/drop.rs:16:9
--> $DIR/drop.rs:15:9
|
LL | let _v: Vec<i32> = Vec::new();
| ^^
Expand Down
1 change: 0 additions & 1 deletion tests/ui/debuginfo/dwarf-versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//@[zero] compile-flags: -Zdwarf-version=0

//@[one] compile-flags: -Zdwarf-version=1
//@[one] error-pattern: requested DWARF version 1 is not supported

//@[two] compile-flags: -Zdwarf-version=2
//@[two] check-pass
Expand Down
4 changes: 3 additions & 1 deletion tests/ui/error-codes/E0152-duplicate-lang-items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
//!
//! Issue: <https://github.com/rust-lang/rust/issues/31788>

//@ error-pattern: first defined in crate `std`
//@ normalize-stderr: "loaded from .*libstd-.*.rlib" -> "loaded from SYSROOT/libstd-*.rlib"
//@ dont-require-annotations: NOTE

#![feature(lang_items)]

extern crate core;
Expand All @@ -14,6 +15,7 @@ use core::panic::PanicInfo;
#[lang = "panic_impl"]
fn panic_impl(info: &PanicInfo) -> ! {
//~^ ERROR: found duplicate lang item `panic_impl`
//~| NOTE first defined in crate `std`
loop {}
}

Expand Down
3 changes: 2 additions & 1 deletion tests/ui/error-codes/E0152-duplicate-lang-items.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
error[E0152]: found duplicate lang item `panic_impl`
--> $DIR/E0152-duplicate-lang-items.rs:15:1
--> $DIR/E0152-duplicate-lang-items.rs:16:1
|
LL | / fn panic_impl(info: &PanicInfo) -> ! {
LL | |
LL | |
LL | | loop {}
LL | | }
| |_^
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/error-codes/E0602.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//@ compile-flags:-D bogus
//@ check-pass

//@ error-pattern:requested on the command line with `-D bogus`
//@ error-pattern:`#[warn(unknown_lints)]` on by default
//@ dont-require-annotations: NOTE

fn main() {}

//~? WARN unknown lint: `bogus`
//~? WARN unknown lint: `bogus`
//~? WARN unknown lint: `bogus`
//~? NOTE requested on the command line with `-D bogus`
//~? NOTE `#[warn(unknown_lints)]` on by default
2 changes: 1 addition & 1 deletion tests/ui/extern-flag/invalid-crate-name-dashed.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@ compile-flags: --extern=my-awesome-library=libawesome.rlib
//@ error-pattern: consider replacing the dashes with underscores: `my_awesome_library`

// In a sense, this is a regression test for issue #113035. We no longer suggest
// `pub use my-awesome-library::*;` (sic!) as we outright ban this crate name.
Expand All @@ -9,3 +8,4 @@ pub use my_awesome_library::*;
fn main() {}

//~? ERROR crate name `my-awesome-library` passed to `--extern` is not a valid ASCII identifier
//~? HELP consider replacing the dashes with underscores: `my_awesome_library`
3 changes: 2 additions & 1 deletion tests/ui/issues/issue-37131.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//~ ERROR can't find crate for `std`
//~| NOTE target may not be installed
//~| NOTE can't find crate
// Tests that compiling for a target which is not installed will result in a helpful
// error message.

//@ compile-flags: --target=thumbv6m-none-eabi
//@ ignore-arm
//@ needs-llvm-components: arm

//@ error-pattern:target may not be installed
fn main() { }
4 changes: 2 additions & 2 deletions tests/ui/layout/unknown-when-no-type-parameter.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#![feature(trivial_bounds)]

//@ error-pattern: the type `<() as Project>::Assoc` has an unknown layout

trait Project {
type Assoc;
}

fn foo() where (): Project {
[(); size_of::<<() as Project>::Assoc>()]; //~ ERROR evaluation of constant value failed
//~| NOTE the type `<() as Project>::Assoc` has an unknown layout
//~| NOTE inside `std::mem::size_of::<<() as Project>::Assoc>`
}

fn main() {}
2 changes: 1 addition & 1 deletion tests/ui/layout/unknown-when-no-type-parameter.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0080]: evaluation of constant value failed
--> $DIR/unknown-when-no-type-parameter.rs:10:10
--> $DIR/unknown-when-no-type-parameter.rs:8:10
|
LL | [(); size_of::<<() as Project>::Assoc>()];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the type `<() as Project>::Assoc` has an unknown layout
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/link-native-libs/suggest-libname-only-1.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//@ build-fail
//@ compile-flags: --crate-type rlib
//@ error-pattern: only provide the library name `foo`, not the full filename

#[link(name = "libfoo.a", kind = "static")]
extern { } //~ WARN extern declarations without an explicit ABI are deprecated
//~| HELP explicitly specify the "C" ABI

pub fn main() { }

//~? ERROR could not find native static library `libfoo.a`
//~? HELP only provide the library name `foo`, not the full filename
2 changes: 1 addition & 1 deletion tests/ui/link-native-libs/suggest-libname-only-1.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: extern declarations without an explicit ABI are deprecated
--> $DIR/suggest-libname-only-1.rs:6:1
--> $DIR/suggest-libname-only-1.rs:5:1
|
LL | extern { }
| ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"`
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/link-native-libs/suggest-libname-only-2.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//@ build-fail
//@ compile-flags: --crate-type rlib
//@ error-pattern: only provide the library name `bar`, not the full filename

#[link(name = "bar.lib", kind = "static")]
extern { } //~ WARN extern declarations without an explicit ABI are deprecated
//~| HELP explicitly specify the "C" ABI

pub fn main() { }

//~? ERROR could not find native static library `bar.lib`
//~? HELP only provide the library name `bar`, not the full filename
2 changes: 1 addition & 1 deletion tests/ui/link-native-libs/suggest-libname-only-2.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: extern declarations without an explicit ABI are deprecated
--> $DIR/suggest-libname-only-2.rs:6:1
--> $DIR/suggest-libname-only-2.rs:5:1
|
LL | extern { }
| ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"`
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/lint/cli-unknown-force-warn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

//@ check-pass
//@ compile-flags: --force-warn foo-qux

//@ error-pattern: requested on the command line with `--force-warn foo_qux`
//@ error-pattern: `#[warn(unknown_lints)]` on by default
//@ dont-require-annotations: NOTE

fn main() {}

//~? WARN unknown lint: `foo_qux`
//~? WARN unknown lint: `foo_qux`
//~? WARN unknown lint: `foo_qux`
//~? NOTE requested on the command line with `--force-warn foo_qux`
//~? NOTE `#[warn(unknown_lints)]` on by default
Loading
Loading