Skip to content

[WIP] Normalize rust version string centrally in compiletest #142940

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

Closed
wants to merge 5 commits into from
Closed
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
2 changes: 2 additions & 0 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1639,6 +1639,8 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the

let mut cmd = builder.tool_cmd(Tool::Compiletest);

cmd.arg("--rust-version").arg(builder.rust_version());

if suite == "mir-opt" {
builder.ensure(compile::Std::new(compiler, target).is_for_mir_opt_tests(true));
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/doc/rustc-dev-guide/src/tests/ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ platforms, mainly about filenames.

Compiletest makes the following replacements on the compiler output:

- The rust version string (e.g. `1.89.0-beta.1 (88b80702e 2025-06-23)`) is
replaced with `$RUST_VERSION`.
- The directory where the test is defined is replaced with `$DIR`. Example:
`/path/to/rust/tests/ui/error-codes`
- The directory to the standard library source is replaced with `$SRC_DIR`.
Expand Down
3 changes: 3 additions & 0 deletions src/tools/compiletest/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ pub struct Config {
/// May run a few more tests before stopping, due to threading.
pub fail_fast: bool,

/// E.g. `1.89.0-beta.1 (88b80702e 2025-06-23)`, used for UI normalizations.
pub rust_version: String,

/// The library paths required for running the compiler.
pub compile_lib_path: Utf8PathBuf,

Expand Down
1 change: 1 addition & 0 deletions src/tools/compiletest/src/header/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ impl ConfigBuilder {
"--mode",
self.mode.as_deref().unwrap_or("ui"),
"--suite=ui",
"--rust-version=DUMMY_VERSION_STRING",
"--compile-lib-path=",
"--run-lib-path=",
"--python=",
Expand Down
285 changes: 138 additions & 147 deletions src/tools/compiletest/src/lib.rs

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2485,6 +2485,10 @@ impl<'test> TestCx<'test> {
.into_owned();
}

// Normalize out rustc version info strings that may be present in the output (usually for
// deprecated since diagnostics).
normalized = normalized.replace(&self.config.rust_version, "$RUST_VERSION");

// Custom normalization rules
for rule in custom_rules {
let re = Regex::new(&rule.0).expect("bad regex in custom normalization rule");
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/deprecation/deprecated_no_stack_check.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//@ normalize-stderr: "you are using [0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?( \([^)]*\))?" -> "you are using $$RUSTC_VERSION"

#![deny(warnings)]
#![feature(no_stack_check)]
//~^ ERROR: feature has been removed [E0557]
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/deprecation/deprecated_no_stack_check.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error[E0557]: feature has been removed
--> $DIR/deprecated_no_stack_check.rs:4:12
--> $DIR/deprecated_no_stack_check.rs:2:12
|
LL | #![feature(no_stack_check)]
| ^^^^^^^^^^^^^^ feature has been removed
|
= note: removed in 1.0.0 (you are using $RUSTC_VERSION); see <https://github.com/rust-lang/rust/pull/40110> for more information
= note: removed in 1.0.0 (you are using $RUST_VERSION); see <https://github.com/rust-lang/rust/pull/40110> for more information

error: aborting due to 1 previous error

Expand Down
2 changes: 0 additions & 2 deletions tests/ui/feature-gates/feature-gate-coverage-attribute.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//@ normalize-stderr: "you are using [0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?( \([^)]*\))?" -> "you are using $$RUSTC_VERSION"

#![crate_type = "lib"]
#![feature(no_coverage)] //~ ERROR feature has been removed [E0557]

Expand Down
6 changes: 3 additions & 3 deletions tests/ui/feature-gates/feature-gate-coverage-attribute.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
error[E0557]: feature has been removed
--> $DIR/feature-gate-coverage-attribute.rs:4:12
--> $DIR/feature-gate-coverage-attribute.rs:2:12
|
LL | #![feature(no_coverage)]
| ^^^^^^^^^^^ feature has been removed
|
= note: removed in 1.74.0 (you are using $RUSTC_VERSION); see <https://github.com/rust-lang/rust/pull/114656> for more information
= note: removed in 1.74.0 (you are using $RUST_VERSION); see <https://github.com/rust-lang/rust/pull/114656> for more information
= note: renamed to `coverage_attribute`

error[E0658]: the `#[coverage]` attribute is an experimental feature
--> $DIR/feature-gate-coverage-attribute.rs:12:1
--> $DIR/feature-gate-coverage-attribute.rs:10:1
|
LL | #[coverage(off)]
| ^^^^^^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/ui/feature-gates/gated-bad-feature.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//@ normalize-stderr: "you are using [0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?( \([^)]*\))?" -> "you are using $$RUSTC_VERSION"
#![feature(foo_bar_baz, foo(bar), foo = "baz", foo)]
//~^ ERROR malformed `feature`
//~| ERROR malformed `feature`
Expand Down
16 changes: 8 additions & 8 deletions tests/ui/feature-gates/gated-bad-feature.stderr
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
error[E0556]: malformed `feature` attribute input
--> $DIR/gated-bad-feature.rs:2:25
--> $DIR/gated-bad-feature.rs:1:25
|
LL | #![feature(foo_bar_baz, foo(bar), foo = "baz", foo)]
| ^^^^^^^^ help: expected just one word: `foo`

error[E0556]: malformed `feature` attribute input
--> $DIR/gated-bad-feature.rs:2:35
--> $DIR/gated-bad-feature.rs:1:35
|
LL | #![feature(foo_bar_baz, foo(bar), foo = "baz", foo)]
| ^^^^^^^^^^^ help: expected just one word: `foo`

error[E0557]: feature has been removed
--> $DIR/gated-bad-feature.rs:9:12
--> $DIR/gated-bad-feature.rs:8:12
|
LL | #![feature(test_removed_feature)]
| ^^^^^^^^^^^^^^^^^^^^ feature has been removed
|
= note: removed in 1.0.0 (you are using $RUSTC_VERSION)
= note: removed in 1.0.0 (you are using $RUST_VERSION)

error: malformed `feature` attribute input
--> $DIR/gated-bad-feature.rs:7:1
--> $DIR/gated-bad-feature.rs:6:1
|
LL | #![feature]
| ^^^^^^^^^^^ help: must be of the form: `#![feature(name1, name2, ...)]`

error: malformed `feature` attribute input
--> $DIR/gated-bad-feature.rs:8:1
--> $DIR/gated-bad-feature.rs:7:1
|
LL | #![feature = "foo"]
| ^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#![feature(name1, name2, ...)]`

error[E0635]: unknown feature `foo_bar_baz`
--> $DIR/gated-bad-feature.rs:2:12
--> $DIR/gated-bad-feature.rs:1:12
|
LL | #![feature(foo_bar_baz, foo(bar), foo = "baz", foo)]
| ^^^^^^^^^^^

error[E0635]: unknown feature `foo`
--> $DIR/gated-bad-feature.rs:2:48
--> $DIR/gated-bad-feature.rs:1:48
|
LL | #![feature(foo_bar_baz, foo(bar), foo = "baz", foo)]
| ^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//@ normalize-stderr: "you are using [0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?( \([^)]*\))?" -> "you are using $$RUSTC_VERSION"

#![feature(external_doc)] //~ ERROR feature has been removed
#![doc(include("README.md"))] //~ ERROR unknown `doc` attribute `include`

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
error[E0557]: feature has been removed
--> $DIR/removed-features-note-version-and-pr-issue-141619.rs:3:12
--> $DIR/removed-features-note-version-and-pr-issue-141619.rs:1:12
|
LL | #![feature(external_doc)]
| ^^^^^^^^^^^^ feature has been removed
|
= note: removed in 1.54.0 (you are using $RUSTC_VERSION); see <https://github.com/rust-lang/rust/pull/85457> for more information
= note: removed in 1.54.0 (you are using $RUST_VERSION); see <https://github.com/rust-lang/rust/pull/85457> for more information
= note: use #[doc = include_str!("filename")] instead, which handles macro invocations

error: unknown `doc` attribute `include`
--> $DIR/removed-features-note-version-and-pr-issue-141619.rs:4:8
--> $DIR/removed-features-note-version-and-pr-issue-141619.rs:2:8
|
LL | #![doc(include("README.md"))]
| ^^^^^^^^^^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/ui/macros/macro-reexport-removed.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@ aux-build:two_macros.rs
//@ normalize-stderr: "you are using [0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?( \([^)]*\))?" -> "you are using $$RUSTC_VERSION"

#![feature(macro_reexport)] //~ ERROR feature has been removed

Expand Down
6 changes: 3 additions & 3 deletions tests/ui/macros/macro-reexport-removed.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
error[E0557]: feature has been removed
--> $DIR/macro-reexport-removed.rs:4:12
--> $DIR/macro-reexport-removed.rs:3:12
|
LL | #![feature(macro_reexport)]
| ^^^^^^^^^^^^^^ feature has been removed
|
= note: removed in 1.0.0 (you are using $RUSTC_VERSION); see <https://github.com/rust-lang/rust/pull/49982> for more information
= note: removed in 1.0.0 (you are using $RUST_VERSION); see <https://github.com/rust-lang/rust/pull/49982> for more information
= note: subsumed by `pub use`

error: cannot find attribute `macro_reexport` in this scope
--> $DIR/macro-reexport-removed.rs:6:3
--> $DIR/macro-reexport-removed.rs:5:3
|
LL | #[macro_reexport(macro_one)]
| ^^^^^^^^^^^^^^ help: a built-in attribute with a similar name exists: `macro_export`
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/rustdoc/renamed-features-rustdoc_internals.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//@ normalize-stderr: "you are using [0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?( \([^)]*\))?" -> "you are using $$RUSTC_VERSION"

#![feature(doc_keyword)] //~ ERROR
#![feature(doc_primitive)] //~ ERROR
#![crate_type = "lib"]
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/rustdoc/renamed-features-rustdoc_internals.stderr
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
error[E0557]: feature has been removed
--> $DIR/renamed-features-rustdoc_internals.rs:3:12
--> $DIR/renamed-features-rustdoc_internals.rs:1:12
|
LL | #![feature(doc_keyword)]
| ^^^^^^^^^^^ feature has been removed
|
= note: removed in 1.58.0 (you are using $RUSTC_VERSION); see <https://github.com/rust-lang/rust/pull/90420> for more information
= note: removed in 1.58.0 (you are using $RUST_VERSION); see <https://github.com/rust-lang/rust/pull/90420> for more information
= note: merged into `#![feature(rustdoc_internals)]`

error[E0557]: feature has been removed
--> $DIR/renamed-features-rustdoc_internals.rs:4:12
--> $DIR/renamed-features-rustdoc_internals.rs:2:12
|
LL | #![feature(doc_primitive)]
| ^^^^^^^^^^^^^ feature has been removed
|
= note: removed in 1.58.0 (you are using $RUSTC_VERSION); see <https://github.com/rust-lang/rust/pull/90420> for more information
= note: removed in 1.58.0 (you are using $RUST_VERSION); see <https://github.com/rust-lang/rust/pull/90420> for more information
= note: merged into `#![feature(rustdoc_internals)]`

error: aborting due to 2 previous errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// Regression test for issue #125877.

//@ compile-flags: -Znext-solver
//@ normalize-stderr: "you are using [0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?( \([^)]*\))?" -> "you are using $$RUSTC_VERSION"

#![feature(const_trait_impl, effects)]
//~^ ERROR feature has been removed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
error[E0557]: feature has been removed
--> $DIR/const-trait-impl-parameter-mismatch.rs:11:30
--> $DIR/const-trait-impl-parameter-mismatch.rs:10:30
|
LL | #![feature(const_trait_impl, effects)]
| ^^^^^^^ feature has been removed
|
= note: removed in 1.84.0 (you are using $RUSTC_VERSION); see <https://github.com/rust-lang/rust/pull/132479> for more information
= note: removed in 1.84.0 (you are using $RUST_VERSION); see <https://github.com/rust-lang/rust/pull/132479> for more information
= note: removed, redundant with `#![feature(const_trait_impl)]`

error[E0049]: associated function `compute` has 0 type parameters but its trait declaration has 1 type parameter
--> $DIR/const-trait-impl-parameter-mismatch.rs:20:16
--> $DIR/const-trait-impl-parameter-mismatch.rs:19:16
|
LL | fn compute<T: ~const Aux>() -> u32;
| - expected 1 type parameter
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/unsized-locals/yote.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
//@ normalize-stderr: "you are using [0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?( \([^)]*\))?" -> "you are using $$RUSTC_VERSION"

#![feature(unsized_locals)] //~ERROR feature has been removed
#![crate_type = "lib"]
4 changes: 2 additions & 2 deletions tests/ui/unsized-locals/yote.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error[E0557]: feature has been removed
--> $DIR/yote.rs:3:12
--> $DIR/yote.rs:1:12
|
LL | #![feature(unsized_locals)]
| ^^^^^^^^^^^^^^ feature has been removed
|
= note: removed in CURRENT_RUSTC_VERSION (you are using $RUSTC_VERSION)
= note: removed in CURRENT_RUSTC_VERSION (you are using $RUST_VERSION)
= note: removed due to implementation concerns; see https://github.com/rust-lang/rust/issues/111942

error: aborting due to 1 previous error
Expand Down
Loading