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

Diff for: src/tools/compiletest/src/header.rs

+7-13
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 => {

Diff for: src/tools/compiletest/src/runtest.rs

+14-4
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`

Diff for: tests/codegen/debuginfo-proc-macro/auxiliary/macro_def.rs

-1
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]

Diff for: tests/incremental/auxiliary/incremental_proc_macro_aux.rs

-2
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

Diff for: tests/incremental/auxiliary/issue-49482-macro-def.rs

-2
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] )*

Diff for: tests/incremental/auxiliary/issue-49482-reexport.rs

+1
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

Diff for: tests/incremental/auxiliary/issue-54059.rs

+1-3
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
}

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

-2
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]

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

+1
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

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

-2
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]

Diff for: tests/pretty/auxiliary/derive-foo.rs

-2
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
#[proc_macro_derive(Foo, attributes(Bar))]

Diff for: tests/ui/annotate-snippet/auxiliary/multispan.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#![feature(proc_macro_diagnostic, proc_macro_span, proc_macro_def_site)]
22

3-
extern crate proc_macro;
4-
53
use proc_macro::{TokenStream, TokenTree, Span, Diagnostic};
64

75
fn parse(input: TokenStream) -> Result<(), Diagnostic> {

Diff for: tests/ui/async-await/issues/auxiliary/issue-60674.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
extern crate proc_macro;
21
use proc_macro::TokenStream;
32

43
#[proc_macro_attribute]

Diff for: tests/ui/attributes/auxiliary/key-value-expansion.rs

-1
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_derive(EthabiContract, attributes(ethabi_contract_options))]

Diff for: tests/ui/attributes/main-removed-2/auxiliary/tokyo.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
extern crate proc_macro;
21
use proc_macro::TokenStream;
32

43
#[proc_macro_attribute]

Diff for: tests/ui/autodiff/auxiliary/my_macro.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
extern crate proc_macro;
21
use proc_macro::TokenStream;
32

43
#[proc_macro_attribute]

Diff for: tests/ui/cfg/assume-incomplete-release/auxiliary/ver-cfg-rel.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
extern crate proc_macro;
21
use proc_macro::{TokenStream, TokenTree as Tt};
32
use std::str::FromStr;
43

Diff for: tests/ui/crate-loading/auxiliary/proc-macro.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![crate_name = "reproduction"]
22

3-
extern crate proc_macro;
43
use proc_macro::TokenStream;
54

65
#[proc_macro]

Diff for: tests/ui/derives/auxiliary/derive-marker-tricky.rs

-1
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_derive(NoMarker)]

Diff for: tests/ui/deriving/auxiliary/another-proc-macro.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#![feature(proc_macro_quote)]
22

3-
extern crate proc_macro;
4-
53
use proc_macro::{TokenStream, quote};
64

75
#[proc_macro_derive(AnotherMacro, attributes(pointee))]

Diff for: tests/ui/diagnostic_namespace/auxiliary/proc-macro-helper.rs

-2
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
#[proc_macro_attribute]

Diff for: tests/ui/fmt/auxiliary/format-string-proc-macro.rs

-2
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
use std::iter::FromIterator;
53

Diff for: tests/ui/hygiene/auxiliary/opaque-hygiene.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![feature(proc_macro_quote)]
22

3-
extern crate proc_macro;
43
use proc_macro::{TokenStream, quote};
54

65
#[proc_macro]

Diff for: tests/ui/impl-trait/precise-capturing/auxiliary/no-use-pm.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// A proc-macro in 2015 that has an RPIT without `use<>` that would cause a
22
// problem with 2024 capturing rules.
3+
//@ edition: 2015
34

45
extern crate proc_macro;
56
use proc_macro::TokenStream;

Diff for: tests/ui/inherent-impls-overlap-check/auxiliary/repeat.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
extern crate proc_macro;
21
use proc_macro::{Ident, Group, TokenStream, TokenTree as Tt};
32

43
// This constant has to be above the ALLOCATING_ALGO_THRESHOLD

Diff for: tests/ui/lifetimes/auxiliary/issue-91763-aux.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//#![feature(proc_macro_diagnostic, proc_macro_span, proc_macro_def_site)]
22

3-
extern crate proc_macro;
4-
53
use proc_macro::{Delimiter, Group, Ident, Punct, Spacing, Span, TokenStream, TokenTree};
64
use std::iter::FromIterator;
75

Diff for: tests/ui/lint/auxiliary/add-impl.rs

-2
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
#[proc_macro_derive(AddImpl)]

Diff for: tests/ui/lint/redundant-semicolon/auxiliary/redundant-semi-proc-macro-def.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![crate_name="redundant_semi_proc_macro"]
2-
extern crate proc_macro;
32
use proc_macro::TokenStream;
43

54
#[proc_macro_attribute]

Diff for: tests/ui/lint/unsafe_code/auxiliary/forge_unsafe_block.rs

-2
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, Span, TokenStream, TokenTree};
42

53
#[proc_macro]

Diff for: tests/ui/macros/auxiliary/hello_macro.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#![feature(proc_macro_quote)]
22

3-
extern crate proc_macro;
4-
53
use proc_macro::{TokenStream, quote};
64

75
// This macro is not very interesting, but it does contain delimited tokens with

Diff for: tests/ui/macros/auxiliary/issue-100199.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#![feature(proc_macro_quote)]
22

3-
extern crate proc_macro;
4-
53
use proc_macro::{quote, Ident, Span, TokenStream, TokenTree};
64

75
#[proc_macro_attribute]

Diff for: tests/ui/macros/auxiliary/proc_macro_def.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#![feature(proc_macro_quote)]
22

3-
extern crate proc_macro;
4-
53
use proc_macro::*;
64

75
#[proc_macro_attribute]

Diff for: tests/ui/macros/auxiliary/proc_macro_sequence.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#![feature(proc_macro_span, proc_macro_quote)]
22

3-
extern crate proc_macro;
4-
53
use proc_macro::{quote, Span, TokenStream, TokenTree};
64

75
// This macro generates a macro with the same macro definition as `manual_foo` in

Diff for: tests/ui/macros/issue-100199.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | #[issue_100199::struct_with_bound]
77
= note: this error originates in the attribute macro `issue_100199::struct_with_bound` (in Nightly builds, run with -Z macro-backtrace for more info)
88
help: consider importing this trait
99
|
10-
LL + use traits::MyTrait;
10+
LL + use crate::traits::MyTrait;
1111
|
1212

1313
error: aborting due to 1 previous error

Diff for: tests/ui/macros/same-sequence-span.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ LL | $(= $z:tt)*
1717
error: `$x:expr` may be followed by `$y:tt`, which is not allowed for `expr` fragments
1818
--> $DIR/same-sequence-span.rs:19:1
1919
|
20-
LL | | macro_rules! manual_foo {
20+
LL | | // When ignoring spans, this macro has the same macro definition as `generated_foo` in
2121
| |_________________________________^ not allowed after `expr` fragments
2222
...
2323
LL | proc_macro_sequence::make_foo!();

Diff for: tests/ui/parser/issues/auxiliary/issue-89971-outer-attr-following-inner-attr-ice.rs

-2
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
#[proc_macro_derive(ICE)]

Diff for: tests/ui/proc-macro/auxiliary/add-impl.rs

-2
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
#[proc_macro_derive(AddImpl)]

Diff for: tests/ui/proc-macro/auxiliary/amputate-span.rs

-2
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
#[proc_macro_attribute]

Diff for: tests/ui/proc-macro/auxiliary/api/proc_macro_api_tests.rs

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
#![feature(proc_macro_span)]
44
#![deny(dead_code)] // catch if a test function is never called
55

6-
extern crate proc_macro;
7-
86
mod cmp;
97
mod literal;
108

Diff for: tests/ui/proc-macro/auxiliary/append-impl.rs

-2
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
#[proc_macro_derive(Append)]

0 commit comments

Comments
 (0)