Skip to content

Fix breakage when running compiletest with --test-args=--edition=2015 #139578

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 6 commits into from
Apr 11, 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
16 changes: 8 additions & 8 deletions src/doc/rustc-dev-guide/src/tests/directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,14 @@ ignoring debuggers.

### Affecting how tests are built

| Directive | Explanation | Supported test suites | Possible values |
|---------------------|----------------------------------------------------------------------------------------------|---------------------------|------------------------------------------------------------------------------|
| `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`. |
| `edition` | Alias for `compile-flags: --edition=xxx` | All except for `run-make` | Any valid `--edition` value |
| `rustc-env` | Env var to set when running `rustc` | All except for `run-make` | `<KEY>=<VALUE>` |
| `unset-rustc-env` | Env var to unset when running `rustc` | All except for `run-make` | Any env var name |
| `incremental` | Proper incremental support for tests outside of incremental test suite | `ui`, `crashes` | N/A |
| `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 |
| Directive | Explanation | Supported test suites | Possible values |
|---------------------|----------------------------------------------------------------------------------------------|---------------------------|--------------------------------------------------------------------------------------------|
| `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` |
| `edition` | The edition used to build the test | All except for `run-make` | Any valid `--edition` value |
| `rustc-env` | Env var to set when running `rustc` | All except for `run-make` | `<KEY>=<VALUE>` |
| `unset-rustc-env` | Env var to unset when running `rustc` | All except for `run-make` | Any env var name |
| `incremental` | Proper incremental support for tests outside of incremental test suite | `ui`, `crashes` | N/A |
| `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 |

<div class="warning">
Tests (outside of `run-make`) that want to use incremental tests not in the
Expand Down
16 changes: 13 additions & 3 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,22 @@ impl TestProps {
}

if let Some(flags) = config.parse_name_value_directive(ln, COMPILE_FLAGS) {
self.compile_flags.extend(split_flags(&flags));
let flags = split_flags(&flags);
for flag in &flags {
if flag == "--edition" || flag.starts_with("--edition=") {
panic!("you must use `//@ edition` to configure the edition");
}
}
self.compile_flags.extend(flags);
}
if config.parse_name_value_directive(ln, INCORRECT_COMPILER_FLAGS).is_some() {
panic!("`compiler-flags` directive should be spelled `compile-flags`");
}

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

Expand Down Expand Up @@ -606,7 +614,9 @@ impl TestProps {
}

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

Expand Down
1 change: 1 addition & 0 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ pub fn compute_stamp_hash(config: &Config) -> String {
let mut hash = DefaultHasher::new();
config.stage_id.hash(&mut hash);
config.run.hash(&mut hash);
config.edition.hash(&mut hash);

match config.debugger {
Some(Debugger::Cdb) => {
Expand Down
3 changes: 2 additions & 1 deletion tests/assembly/cstring-merging.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//@ only-linux
//@ assembly-output: emit-asm
//@ compile-flags: --crate-type=lib -Copt-level=3 --edition 2024
//@ compile-flags: --crate-type=lib -Copt-level=3
//@ edition: 2024

use std::ffi::CStr;

Expand Down
3 changes: 2 additions & 1 deletion tests/codegen/async-closure-debug.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Just make sure that async closures don't ICE.
//
//@ compile-flags: -C debuginfo=2 --edition=2018
//@ compile-flags: -C debuginfo=2
//@ edition: 2018
//@ ignore-msvc

// CHECK-DAG: [[GEN_FN:!.*]] = !DINamespace(name: "async_closure_test"
Expand Down
3 changes: 2 additions & 1 deletion tests/codegen/async-fn-debug-awaitee-field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
//@[MSVC] only-msvc
//@[NONMSVC] ignore-msvc

//@ compile-flags: -C debuginfo=2 --edition=2018 -Copt-level=0
//@ compile-flags: -C debuginfo=2 -Copt-level=0
//@ edition: 2018

#![crate_type = "lib"]

Expand Down
13 changes: 7 additions & 6 deletions tests/codegen/async-fn-debug-msvc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
// - Other fields are not marked artificial
//
//
//@ compile-flags: -C debuginfo=2 --edition=2018
//@ compile-flags: -C debuginfo=2
//@ edition: 2018
//@ only-msvc

async fn foo() {}
Expand All @@ -19,23 +20,23 @@ async fn async_fn_test() {
// CHECK-DAG: [[GEN:!.*]] = !DICompositeType(tag: DW_TAG_union_type, name: "enum2$<async_fn_debug_msvc::async_fn_test::async_fn_env$0>",
// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "variant0", scope: [[GEN]],
// For brevity, we only check the struct name and members of the last variant.
// CHECK-SAME: file: [[FILE:![0-9]*]], line: 11,
// CHECK-SAME: file: [[FILE:![0-9]*]], line: 12,
// CHECK-NOT: flags: DIFlagArtificial
// CHECK-SAME: )
// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "variant1", scope: [[GEN]],
// CHECK-SAME: file: [[FILE]], line: 15,
// CHECK-SAME: file: [[FILE]], line: 16,
// CHECK-NOT: flags: DIFlagArtificial
// CHECK-SAME: )
// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "variant2", scope: [[GEN]],
// CHECK-SAME: file: [[FILE]], line: 15,
// CHECK-SAME: file: [[FILE]], line: 16,
// CHECK-NOT: flags: DIFlagArtificial
// CHECK-SAME: )
// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "variant3", scope: [[GEN]],
// CHECK-SAME: file: [[FILE]], line: 12,
// CHECK-SAME: file: [[FILE]], line: 13,
// CHECK-NOT: flags: DIFlagArtificial
// CHECK-SAME: )
// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "variant4", scope: [[GEN]],
// CHECK-SAME: file: [[FILE]], line: 14,
// CHECK-SAME: file: [[FILE]], line: 15,
// CHECK-SAME: baseType: [[VARIANT_WRAPPER:![0-9]*]]
// CHECK-NOT: flags: DIFlagArtificial
// CHECK-SAME: )
Expand Down
13 changes: 7 additions & 6 deletions tests/codegen/async-fn-debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
// - Other fields are not marked artificial
//
//
//@ compile-flags: -C debuginfo=2 --edition=2018
//@ compile-flags: -C debuginfo=2
//@ edition: 2018
//@ ignore-msvc

async fn foo() {}
Expand All @@ -22,26 +23,26 @@ async fn async_fn_test() {
// CHECK-NOT: flags: DIFlagArtificial
// CHECK-SAME: discriminator: [[DISC:![0-9]*]]
// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "0", scope: [[VARIANT]],
// CHECK-SAME: file: [[FILE:![0-9]*]], line: 11,
// CHECK-SAME: file: [[FILE:![0-9]*]], line: 12,
// CHECK-NOT: flags: DIFlagArtificial
// CHECK-SAME: )
// CHECK: {{!.*}} = !DICompositeType(tag: DW_TAG_structure_type, name: "Unresumed", scope: [[GEN]],
// CHECK-NOT: flags: DIFlagArtificial
// CHECK-SAME: )
// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "1", scope: [[VARIANT]],
// CHECK-SAME: file: [[FILE]], line: 15,
// CHECK-SAME: file: [[FILE]], line: 16,
// CHECK-NOT: flags: DIFlagArtificial
// CHECK-SAME: )
// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "2", scope: [[VARIANT]],
// CHECK-SAME: file: [[FILE]], line: 15,
// CHECK-SAME: file: [[FILE]], line: 16,
// CHECK-NOT: flags: DIFlagArtificial
// CHECK-SAME: )
// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "3", scope: [[VARIANT]],
// CHECK-SAME: file: [[FILE]], line: 12,
// CHECK-SAME: file: [[FILE]], line: 13,
// CHECK-NOT: flags: DIFlagArtificial
// CHECK-SAME: )
// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "4", scope: [[VARIANT]],
// CHECK-SAME: file: [[FILE]], line: 14,
// CHECK-SAME: file: [[FILE]], line: 15,
// CHECK-NOT: flags: DIFlagArtificial
// CHECK-SAME: )
// CHECK: [[S1:!.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Suspend1", scope: [[GEN]],
Expand Down
13 changes: 7 additions & 6 deletions tests/codegen/coroutine-debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
// - Other fields are not marked artificial
//
//
//@ compile-flags: -C debuginfo=2 --edition=2018
//@ compile-flags: -C debuginfo=2
//@ edition: 2018
//@ ignore-msvc

#![feature(coroutines, coroutine_trait)]
Expand All @@ -27,26 +28,26 @@ fn coroutine_test() -> impl Coroutine<Yield = i32, Return = ()> {
// CHECK-NOT: flags: DIFlagArtificial
// CHECK-SAME: discriminator: [[DISC:![0-9]*]]
// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "0", scope: [[VARIANT]],
// CHECK-SAME: file: [[FILE:![0-9]*]], line: 15,
// CHECK-SAME: file: [[FILE:![0-9]*]], line: 16,
// CHECK-NOT: flags: DIFlagArtificial
// CHECK-SAME: )
// CHECK: {{!.*}} = !DICompositeType(tag: DW_TAG_structure_type, name: "Unresumed", scope: [[GEN]],
// CHECK-NOT: flags: DIFlagArtificial
// CHECK-SAME: )
// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "1", scope: [[VARIANT]],
// CHECK-SAME: file: [[FILE]], line: 19,
// CHECK-SAME: file: [[FILE]], line: 20,
// CHECK-NOT: flags: DIFlagArtificial
// CHECK-SAME: )
// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "2", scope: [[VARIANT]],
// CHECK-SAME: file: [[FILE]], line: 19,
// CHECK-SAME: file: [[FILE]], line: 20,
// CHECK-NOT: flags: DIFlagArtificial
// CHECK-SAME: )
// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "3", scope: [[VARIANT]],
// CHECK-SAME: file: [[FILE]], line: 16,
// CHECK-SAME: file: [[FILE]], line: 17,
// CHECK-NOT: flags: DIFlagArtificial
// CHECK-SAME: )
// CHECK: {{!.*}} = !DIDerivedType(tag: DW_TAG_member, name: "4", scope: [[VARIANT]],
// CHECK-SAME: file: [[FILE]], line: 18,
// CHECK-SAME: file: [[FILE]], line: 19,
// CHECK-NOT: flags: DIFlagArtificial
// CHECK-SAME: )
// CHECK: [[S1:!.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Suspend1", scope: [[GEN]],
Expand Down
3 changes: 2 additions & 1 deletion tests/codegen/debuginfo-generic-closure-env-names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
// legacy mangling scheme rustc version and generic parameters are both hashed into a single part
// of the name, thus randomizing item order with respect to rustc version.

//@ compile-flags: -Cdebuginfo=2 --edition 2021 -Copt-level=0 -Csymbol-mangling-version=v0
//@ compile-flags: -Cdebuginfo=2 -Copt-level=0 -Csymbol-mangling-version=v0
//@ edition: 2021

// non_generic_closure()
// NONMSVC: !DICompositeType(tag: DW_TAG_structure_type, name: "{closure_env#0}", scope: ![[non_generic_closure_NAMESPACE:[0-9]+]],
Expand Down
3 changes: 2 additions & 1 deletion tests/codegen/infallible-unwrap-in-opt-z.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ compile-flags: -C opt-level=z --edition=2021
//@ compile-flags: -C opt-level=z
//@ edition: 2021

#![crate_type = "lib"]

Expand Down
7 changes: 4 additions & 3 deletions tests/codegen/inline-function-args-debug-info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// gets inlined by MIR inlining. Without function argument indexes, `info args` in gdb won't show
// arguments and their values for the current function.

//@ compile-flags: -Zinline-mir=yes -Cdebuginfo=2 --edition=2021
//@ compile-flags: -Zinline-mir=yes -Cdebuginfo=2
//@ edition: 2021

#![crate_type = "lib"]

Expand All @@ -14,9 +15,9 @@ pub fn outer_function(x: usize, y: usize) -> usize {
#[inline]
fn inner_function(aaaa: usize, bbbb: usize) -> usize {
// CHECK: !DILocalVariable(name: "aaaa", arg: 1
// CHECK-SAME: line: 15
// CHECK-SAME: line: 16
// CHECK-NOT: !DILexicalBlock(
// CHECK: !DILocalVariable(name: "bbbb", arg: 2
// CHECK-SAME: line: 15
// CHECK-SAME: line: 16
aaaa + bbbb
}
3 changes: 2 additions & 1 deletion tests/codegen/issues/issue-119422.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! This test checks that compiler don't generate useless compares to zeros
//! for `NonZero` integer types.
//!
//@ compile-flags: -Copt-level=3 --edition=2021 -Zmerge-functions=disabled
//@ compile-flags: -Copt-level=3 -Zmerge-functions=disabled
//@ edition: 2021
//@ only-64bit (because the LLVM type of i64 for usize shows up)
#![crate_type = "lib"]

Expand Down
3 changes: 2 additions & 1 deletion tests/codegen/simd/simd-wide-sum.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ revisions: llvm mir-opt3
//@ compile-flags: -C opt-level=3 -Z merge-functions=disabled --edition=2021
//@ compile-flags: -C opt-level=3 -Z merge-functions=disabled
//@ edition: 2021
//@ only-x86_64
//@ [mir-opt3]compile-flags: -Zmir-opt-level=3
//@ [mir-opt3]build-pass
Expand Down
3 changes: 2 additions & 1 deletion tests/codegen/try_question_mark_nop.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ compile-flags: -Copt-level=3 -Z merge-functions=disabled --edition=2021
//@ compile-flags: -Copt-level=3 -Z merge-functions=disabled
//@ edition: 2021
//@ only-x86_64
//@ revisions: NINETEEN TWENTY
//@[NINETEEN] exact-llvm-major-version: 19
Expand Down
2 changes: 1 addition & 1 deletion tests/crashes/119095.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ known-bug: #119095
//@ compile-flags: --edition=2021
//@ edition: 2021

fn any<T>() -> T {
loop {}
Expand Down
3 changes: 2 additions & 1 deletion tests/crashes/120016.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ known-bug: #120016
//@ compile-flags: -Zcrate-attr=feature(const_async_blocks) --edition=2021
//@ compile-flags: -Zcrate-attr=feature(const_async_blocks)
//@ edition: 2021

#![feature(type_alias_impl_trait, const_async_blocks)]

Expand Down
2 changes: 1 addition & 1 deletion tests/crashes/127033.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ known-bug: #127033
//@ compile-flags: --edition=2021
//@ edition: 2021

pub trait RaftLogStorage {
fn save_vote(vote: ()) -> impl std::future::Future + Send;
Expand Down
3 changes: 2 additions & 1 deletion tests/crashes/128094.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ known-bug: rust-lang/rust#128094
//@ compile-flags: -Zmir-enable-passes=+GVN --edition=2018
//@ compile-flags: -Zmir-enable-passes=+GVN
//@ edition: 2018

pub enum Request {
TestSome(T),
Expand Down
3 changes: 2 additions & 1 deletion tests/crashes/132103.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ known-bug: #132103
//@compile-flags: -Zvalidate-mir --edition=2018 -Zinline-mir=yes
//@ compile-flags: -Zvalidate-mir -Zinline-mir=yes
//@ edition: 2018
use core::future::{async_drop_in_place, Future};
use core::mem::{self};
use core::pin::pin;
Expand Down
3 changes: 2 additions & 1 deletion tests/crashes/132430.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//@ known-bug: #132430

//@compile-flags: --edition=2018 --crate-type=lib
//@ compile-flags: --crate-type=lib
//@ edition: 2018
#![feature(cmse_nonsecure_entry)]
struct Test;

Expand Down
3 changes: 2 additions & 1 deletion tests/crashes/135128.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ known-bug: #135128
//@ compile-flags: -Copt-level=1 --edition=2021
//@ compile-flags: -Copt-level=1
//@ edition: 2021

#![feature(trivial_bounds)]

Expand Down
3 changes: 2 additions & 1 deletion tests/crashes/135470.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ known-bug: #135470
//@ compile-flags: --edition=2021 -Copt-level=0
//@ compile-flags: -Copt-level=0
//@ edition: 2021

use std::future::Future;
trait Access {
Expand Down
4 changes: 3 additions & 1 deletion tests/crashes/135646.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//@ known-bug: #135646
//@ compile-flags: --edition=2024 -Zpolonius=next
//@ compile-flags: -Zpolonius=next
//@ edition: 2024

fn main() {
&{ [1, 2, 3][4] };
}
2 changes: 1 addition & 1 deletion tests/crashes/135668.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ known-bug: #135668
//@ compile-flags: --edition=2021
//@ edition: 2021
use std::future::Future;

pub async fn foo() {
Expand Down
2 changes: 1 addition & 1 deletion tests/crashes/137467-1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ known-bug: #137467
//@ compile-flags: --edition=2021
//@ edition: 2021
enum Camera {
Normal { base_transform: i32 },
Volume { transform: i32 },
Expand Down
2 changes: 1 addition & 1 deletion tests/crashes/137467-2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ known-bug: #137467
//@ compile-flags: --edition=2021
//@ edition: 2021

enum Camera {
Normal { base_transform: i32 },
Expand Down
2 changes: 1 addition & 1 deletion tests/crashes/137467-3.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ known-bug: #137467
//@ compile-flags: --edition=2021
//@ edition: 2021

fn meow(x: (u32, u32, u32)) {
let f = || {
Expand Down
2 changes: 1 addition & 1 deletion tests/crashes/137916.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ known-bug: #137916
//@ compile-flags: --edition=2021
//@ edition: 2021
use std::ptr::null;

async fn a() -> Box<dyn Send> {
Expand Down
3 changes: 2 additions & 1 deletion tests/debuginfo/coroutine-closure.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![feature(async_closure)]
//@ only-cdb
//@ compile-flags:-g --edition=2021
//@ compile-flags: -g
//@ edition: 2021

// === CDB TESTS ==================================================================================

Expand Down
Loading
Loading