Skip to content

Commit 6785c76

Browse files
committed
Switch proc-macros to default to 2024 edition
This changes the default edition with the intent to reduce more boilerplate, and to use modern Rust for these proc-macro helpers. For the rare case where the edition of the proc-macro matters, it can be set explicitly (which seems good to me to be explicit).
1 parent 2ec8abd commit 6785c76

File tree

152 files changed

+48
-268
lines changed

Some content is hidden

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

152 files changed

+48
-268
lines changed

src/tools/compiletest/src/header.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ pub struct TestProps {
199199
/// Build and use `minicore` as `core` stub for `no_core` tests in cross-compilation scenarios
200200
/// that don't otherwise want/need `-Z build-std`.
201201
pub add_core_stubs: bool,
202+
/// The edition for this test.
203+
pub edition: Option<String>,
202204
}
203205

204206
mod directives {
@@ -247,6 +249,7 @@ mod directives {
247249
pub const ADD_CORE_STUBS: &'static str = "add-core-stubs";
248250
// This isn't a real directive, just one that is probably mistyped often
249251
pub const INCORRECT_COMPILER_FLAGS: &'static str = "compiler-flags";
252+
pub const EDITION: &'static str = "edition";
250253
}
251254

252255
impl TestProps {
@@ -302,6 +305,7 @@ impl TestProps {
302305
no_auto_check_cfg: false,
303306
has_enzyme: false,
304307
add_core_stubs: false,
308+
edition: None,
305309
}
306310
}
307311

@@ -335,7 +339,6 @@ impl TestProps {
335339
/// `//@[foo]`), then the property is ignored unless `test_revision` is
336340
/// `Some("foo")`.
337341
fn load_from(&mut self, testfile: &Path, test_revision: Option<&str>, config: &Config) {
338-
let mut has_edition = false;
339342
if !testfile.is_dir() {
340343
let file = File::open(testfile).unwrap();
341344

@@ -389,10 +392,9 @@ impl TestProps {
389392
panic!("`compiler-flags` directive should be spelled `compile-flags`");
390393
}
391394

392-
if let Some(edition) = config.parse_edition(ln) {
393-
self.compile_flags.push(format!("--edition={}", edition.trim()));
394-
has_edition = true;
395-
}
395+
config.set_name_value_directive(ln, EDITION, &mut self.edition, |r| {
396+
r.trim().to_string()
397+
});
396398

397399
config.parse_and_update_revisions(testfile, ln, &mut self.revisions);
398400

@@ -601,10 +603,6 @@ impl TestProps {
601603
}
602604
}
603605
}
604-
605-
if let (Some(edition), false) = (&config.edition, has_edition) {
606-
self.compile_flags.push(format!("--edition={}", edition));
607-
}
608606
}
609607

610608
fn update_fail_mode(&mut self, ln: &str, config: &Config) {
@@ -1027,10 +1025,6 @@ impl Config {
10271025
None
10281026
}
10291027

1030-
fn parse_edition(&self, line: &str) -> Option<String> {
1031-
self.parse_name_value_directive(line, "edition")
1032-
}
1033-
10341028
fn set_name_directive(&self, line: &str, directive: &str, value: &mut bool) {
10351029
match value {
10361030
true => {

src/tools/compiletest/src/runtest.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,8 @@ impl<'test> TestCx<'test> {
428428
.arg(&aux_dir)
429429
.arg("-A")
430430
.arg("internal_features")
431-
.args(&self.props.compile_flags)
432431
.envs(self.props.rustc_env.clone());
432+
self.add_common_args(&mut rustc);
433433
self.maybe_add_external_args(&mut rustc, &self.config.target_rustcflags);
434434

435435
let src = match read_from {
@@ -534,7 +534,7 @@ impl<'test> TestCx<'test> {
534534
.arg("internal_features");
535535
self.set_revision_flags(&mut rustc);
536536
self.maybe_add_external_args(&mut rustc, &self.config.target_rustcflags);
537-
rustc.args(&self.props.compile_flags);
537+
self.add_common_args(&mut rustc);
538538

539539
self.compose_and_run_compiler(rustc, Some(src), self.testpaths)
540540
}
@@ -937,8 +937,8 @@ impl<'test> TestCx<'test> {
937937
.arg(&self.testpaths.file)
938938
.arg("-A")
939939
.arg("internal_features")
940-
.args(&self.props.compile_flags)
941940
.args(&self.props.doc_flags);
941+
self.add_common_args(&mut rustdoc);
942942

943943
if self.config.mode == RustdocJson {
944944
rustdoc.arg("--output-format").arg("json").arg("-Zunstable-options");
@@ -1242,6 +1242,9 @@ impl<'test> TestCx<'test> {
12421242
self.props.from_aux_file(&aux_testpaths.file, self.revision, self.config);
12431243
if aux_type == Some(AuxType::ProcMacro) {
12441244
aux_props.force_host = true;
1245+
if aux_props.edition.is_none() {
1246+
aux_props.edition = Some("2024".to_string());
1247+
}
12451248
}
12461249
let mut aux_dir = aux_dir.to_path_buf();
12471250
if aux_type == Some(AuxType::Bin) {
@@ -1731,7 +1734,7 @@ impl<'test> TestCx<'test> {
17311734
}
17321735
}
17331736

1734-
rustc.args(&self.props.compile_flags);
1737+
self.add_common_args(&mut rustc);
17351738

17361739
// FIXME(jieyouxu): we should report a fatal error or warning if user wrote `-Cpanic=` with
17371740
// something that's not `abort`, however, by moving this last we should override previous
@@ -1745,6 +1748,13 @@ impl<'test> TestCx<'test> {
17451748
rustc
17461749
}
17471750

1751+
fn add_common_args(&self, cmd: &mut Command) {
1752+
cmd.args(&self.props.compile_flags);
1753+
if let Some(edition) = &self.props.edition {
1754+
cmd.args(&["--edition", edition.as_str()]);
1755+
}
1756+
}
1757+
17481758
fn make_exe_name(&self) -> PathBuf {
17491759
// Using a single letter here to keep the path length down for
17501760
// Windows. Some test names get very long. rustc creates `rcgu`

tests/codegen/debuginfo-proc-macro/auxiliary/macro_def.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
extern crate proc_macro;
21
use proc_macro::*;
32

43
#[proc_macro]

tests/incremental/auxiliary/incremental_proc_macro_aux.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
extern crate proc_macro;
2-
31
use proc_macro::TokenStream;
42

53
// Add a function to shift DefIndex of registrar function

tests/incremental/auxiliary/issue-49482-macro-def.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#![allow(non_snake_case)]
22

3-
extern crate proc_macro;
4-
53
macro_rules! proc_macro_expr_impl {
64
($(
75
$( #[$attr:meta] )*

tests/incremental/auxiliary/issue-49482-reexport.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//@ proc-macro: issue-49482-macro-def.rs
2+
23
#[macro_use]
34
extern crate issue_49482_macro_def;
45

tests/incremental/auxiliary/issue-54059.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
#![allow(non_snake_case)]
44

5-
extern crate proc_macro;
6-
75
macro_rules! proc_macro_tokenstream {
86
() => {
97
::proc_macro::TokenStream
@@ -41,6 +39,6 @@ proc_macro_expr_impl! {
4139
}
4240

4341
#[link(name="rust_test_helpers")]
44-
extern "C" {
42+
unsafe extern "C" {
4543
pub fn rust_dbg_extern_identity_u64(v: u64) -> u64;
4644
}

tests/incremental/issue-110457-same-span-closures/auxiliary/egui_inspect_derive.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
extern crate proc_macro;
2-
31
use proc_macro::{Delimiter, Group, Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree};
42

53
#[proc_macro]

tests/incremental/issue-85197-invalid-span/auxiliary/invalid-span-helper-lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//@ proc-macro: respan.rs
22
//@ revisions: rpass1 rpass2
3+
//@ proc-macro: respan.rs
34

45
extern crate respan;
56

tests/incremental/issue-85197-invalid-span/auxiliary/respan.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
extern crate proc_macro;
21
use proc_macro::TokenStream;
32

4-
53
/// Copies the resolution information (the `SyntaxContext`) of the first
64
/// token to all other tokens in the stream. Does not recurse into groups.
75
#[proc_macro]

0 commit comments

Comments
 (0)