Skip to content

Commit 71b68da

Browse files
committedApr 11, 2025
Auto merge of #139578 - ferrocene:pa-compiletest-edition, r=jieyouxu
Fix breakage when running compiletest with `--test-args=--edition=2015` Compiletest has an `--edition` flag to change the default edition tests are run with. Unfortunately no test suite successfully executes when that flag is passed. If the edition is set to something greater than 2015 the breakage is expected, since the test suite currently supports only edition 2015 (Ferrous Systems will open an MCP about fixing that soonish). Surprisingly, the test suite is also broken if `--edition=2015` is passed to compiletest. This PR focuses on fixing the latter. This PR fixes the two categories of failures happening when `--edition=2015` is passed: * Some edition-specific tests set their edition through `//@ compile-flags` instead of `//@ edition`. Compiletest doesn't parse the compile flags, so it would see no `//@ edition` and add another `--edition` flag, leading to a rustc error. * Compiletest would add the edition after `//@ compile-flags`, while some tests depend on flags passed to `//@ compile-flags` being the last flags in the rustc invocation. Note that for the first category, I opted to manually go and replace all `//@ compile-flags` setting an edition with an explicit `//@ edition`. We could've changed compiletest to instead check whether an edition was set in `//@ compile-flags`, but I thought it was better to enforce a consistent way to set the edition in tests. I also added the edition to the stamp, so that changing `--edition` results in tests being re-executed. r? `@jieyouxu`
2 parents 81d8c74 + 3ebf1c2 commit 71b68da

File tree

111 files changed

+208
-151
lines changed

Some content is hidden

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

111 files changed

+208
-151
lines changed
 

‎src/doc/rustc-dev-guide/src/tests/directives.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,14 @@ ignoring debuggers.
234234

235235
### Affecting how tests are built
236236

237-
| Directive | Explanation | Supported test suites | Possible values |
238-
|---------------------|----------------------------------------------------------------------------------------------|---------------------------|------------------------------------------------------------------------------|
239-
| `compile-flags` | Flags passed to `rustc` when building the test or aux file | All except for `run-make` | Any valid `rustc` flags, e.g. `-Awarnings -Dfoo`. Cannot be `-Cincremental`. |
240-
| `edition` | Alias for `compile-flags: --edition=xxx` | All except for `run-make` | Any valid `--edition` value |
241-
| `rustc-env` | Env var to set when running `rustc` | All except for `run-make` | `<KEY>=<VALUE>` |
242-
| `unset-rustc-env` | Env var to unset when running `rustc` | All except for `run-make` | Any env var name |
243-
| `incremental` | Proper incremental support for tests outside of incremental test suite | `ui`, `crashes` | N/A |
244-
| `no-prefer-dynamic` | Don't use `-C prefer-dynamic`, don't build as a dylib via a `--crate-type=dylib` preset flag | `ui`, `crashes` | N/A |
237+
| Directive | Explanation | Supported test suites | Possible values |
238+
|---------------------|----------------------------------------------------------------------------------------------|---------------------------|--------------------------------------------------------------------------------------------|
239+
| `compile-flags` | Flags passed to `rustc` when building the test or aux file | All except for `run-make` | Any valid `rustc` flags, e.g. `-Awarnings -Dfoo`. Cannot be `-Cincremental` or `--edition` |
240+
| `edition` | The edition used to build the test | All except for `run-make` | Any valid `--edition` value |
241+
| `rustc-env` | Env var to set when running `rustc` | All except for `run-make` | `<KEY>=<VALUE>` |
242+
| `unset-rustc-env` | Env var to unset when running `rustc` | All except for `run-make` | Any env var name |
243+
| `incremental` | Proper incremental support for tests outside of incremental test suite | `ui`, `crashes` | N/A |
244+
| `no-prefer-dynamic` | Don't use `-C prefer-dynamic`, don't build as a dylib via a `--crate-type=dylib` preset flag | `ui`, `crashes` | N/A |
245245

246246
<div class="warning">
247247
Tests (outside of `run-make`) that want to use incremental tests not in the

‎src/tools/compiletest/src/header.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,14 +389,22 @@ impl TestProps {
389389
}
390390

391391
if let Some(flags) = config.parse_name_value_directive(ln, COMPILE_FLAGS) {
392-
self.compile_flags.extend(split_flags(&flags));
392+
let flags = split_flags(&flags);
393+
for flag in &flags {
394+
if flag == "--edition" || flag.starts_with("--edition=") {
395+
panic!("you must use `//@ edition` to configure the edition");
396+
}
397+
}
398+
self.compile_flags.extend(flags);
393399
}
394400
if config.parse_name_value_directive(ln, INCORRECT_COMPILER_FLAGS).is_some() {
395401
panic!("`compiler-flags` directive should be spelled `compile-flags`");
396402
}
397403

398404
if let Some(edition) = config.parse_edition(ln) {
399-
self.compile_flags.push(format!("--edition={}", edition.trim()));
405+
// The edition is added at the start, since flags from //@compile-flags must
406+
// be passed to rustc last.
407+
self.compile_flags.insert(0, format!("--edition={}", edition.trim()));
400408
has_edition = true;
401409
}
402410

@@ -624,7 +632,9 @@ impl TestProps {
624632
}
625633

626634
if let (Some(edition), false) = (&config.edition, has_edition) {
627-
self.compile_flags.push(format!("--edition={}", edition));
635+
// The edition is added at the start, since flags from //@compile-flags must be passed
636+
// to rustc last.
637+
self.compile_flags.insert(0, format!("--edition={}", edition));
628638
}
629639
}
630640

0 commit comments

Comments
 (0)