Skip to content

Commit

Permalink
Switch proc-macros to default to 2024 edition
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
ehuss committed Nov 27, 2024
1 parent f94142b commit ea41925
Show file tree
Hide file tree
Showing 153 changed files with 48 additions and 270 deletions.
20 changes: 7 additions & 13 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ pub struct TestProps {
/// Build and use `minicore` as `core` stub for `no_core` tests in cross-compilation scenarios
/// that don't otherwise want/need `-Z build-std`.
pub add_core_stubs: bool,
/// The edition for this test.
pub edition: Option<String>,
}

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

impl TestProps {
Expand Down Expand Up @@ -302,6 +305,7 @@ impl TestProps {
no_auto_check_cfg: false,
has_enzyme: false,
add_core_stubs: false,
edition: None,
}
}

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

Expand Down Expand Up @@ -389,10 +392,9 @@ impl TestProps {
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()));
has_edition = true;
}
config.set_name_value_directive(ln, EDITION, &mut self.edition, |r| {
r.trim().to_string()
});

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

Expand Down Expand Up @@ -601,10 +603,6 @@ impl TestProps {
}
}
}

if let (Some(edition), false) = (&config.edition, has_edition) {
self.compile_flags.push(format!("--edition={}", edition));
}
}

fn update_fail_mode(&mut self, ln: &str, config: &Config) {
Expand Down Expand Up @@ -1027,10 +1025,6 @@ impl Config {
None
}

fn parse_edition(&self, line: &str) -> Option<String> {
self.parse_name_value_directive(line, "edition")
}

fn set_name_directive(&self, line: &str, directive: &str, value: &mut bool) {
match value {
true => {
Expand Down
18 changes: 14 additions & 4 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,8 @@ impl<'test> TestCx<'test> {
.arg(&aux_dir)
.arg("-A")
.arg("internal_features")
.args(&self.props.compile_flags)
.envs(self.props.rustc_env.clone());
self.add_common_args(&mut rustc);
self.maybe_add_external_args(&mut rustc, &self.config.target_rustcflags);

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

self.compose_and_run_compiler(rustc, Some(src), self.testpaths)
}
Expand Down Expand Up @@ -937,8 +937,8 @@ impl<'test> TestCx<'test> {
.arg(&self.testpaths.file)
.arg("-A")
.arg("internal_features")
.args(&self.props.compile_flags)
.args(&self.props.doc_flags);
self.add_common_args(&mut rustdoc);

if self.config.mode == RustdocJson {
rustdoc.arg("--output-format").arg("json").arg("-Zunstable-options");
Expand Down Expand Up @@ -1242,6 +1242,9 @@ impl<'test> TestCx<'test> {
self.props.from_aux_file(&aux_testpaths.file, self.revision, self.config);
if aux_type == Some(AuxType::ProcMacro) {
aux_props.force_host = true;
if aux_props.edition.is_none() {
aux_props.edition = Some("2024".to_string());
}
}
let mut aux_dir = aux_dir.to_path_buf();
if aux_type == Some(AuxType::Bin) {
Expand Down Expand Up @@ -1731,7 +1734,7 @@ impl<'test> TestCx<'test> {
}
}

rustc.args(&self.props.compile_flags);
self.add_common_args(&mut rustc);

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

fn add_common_args(&self, cmd: &mut Command) {
cmd.args(&self.props.compile_flags);
if let Some(edition) = &self.props.edition {
cmd.args(&["--edition", edition.as_str()]);
}
}

fn make_exe_name(&self) -> PathBuf {
// Using a single letter here to keep the path length down for
// Windows. Some test names get very long. rustc creates `rcgu`
Expand Down
1 change: 0 additions & 1 deletion tests/codegen/debuginfo-proc-macro/auxiliary/macro_def.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate proc_macro;
use proc_macro::*;

#[proc_macro]
Expand Down
2 changes: 0 additions & 2 deletions tests/incremental/auxiliary/incremental_proc_macro_aux.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate proc_macro;

use proc_macro::TokenStream;

// Add a function to shift DefIndex of registrar function
Expand Down
2 changes: 0 additions & 2 deletions tests/incremental/auxiliary/issue-49482-macro-def.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![allow(non_snake_case)]

extern crate proc_macro;

macro_rules! proc_macro_expr_impl {
($(
$( #[$attr:meta] )*
Expand Down
1 change: 1 addition & 0 deletions tests/incremental/auxiliary/issue-49482-reexport.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ proc-macro: issue-49482-macro-def.rs

#[macro_use]
extern crate issue_49482_macro_def;

Expand Down
4 changes: 1 addition & 3 deletions tests/incremental/auxiliary/issue-54059.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#![allow(non_snake_case)]

extern crate proc_macro;

macro_rules! proc_macro_tokenstream {
() => {
::proc_macro::TokenStream
Expand Down Expand Up @@ -41,6 +39,6 @@ proc_macro_expr_impl! {
}

#[link(name="rust_test_helpers")]
extern "C" {
unsafe extern "C" {
pub fn rust_dbg_extern_identity_u64(v: u64) -> u64;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate proc_macro;

use proc_macro::{Delimiter, Group, Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree};

#[proc_macro]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ proc-macro: respan.rs
//@ revisions: rpass1 rpass2
//@ proc-macro: respan.rs

extern crate respan;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
extern crate proc_macro;
use proc_macro::TokenStream;


/// Copies the resolution information (the `SyntaxContext`) of the first
/// token to all other tokens in the stream. Does not recurse into groups.
#[proc_macro]
Expand Down
2 changes: 0 additions & 2 deletions tests/pretty/auxiliary/derive-foo.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate proc_macro;

use proc_macro::TokenStream;

#[proc_macro_derive(Foo, attributes(Bar))]
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/annotate-snippet/auxiliary/multispan.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![feature(proc_macro_diagnostic, proc_macro_span, proc_macro_def_site)]

extern crate proc_macro;

use proc_macro::{TokenStream, TokenTree, Span, Diagnostic};

fn parse(input: TokenStream) -> Result<(), Diagnostic> {
Expand Down
1 change: 0 additions & 1 deletion tests/ui/async-await/issues/auxiliary/issue-60674.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate proc_macro;
use proc_macro::TokenStream;

#[proc_macro_attribute]
Expand Down
1 change: 0 additions & 1 deletion tests/ui/attributes/auxiliary/key-value-expansion.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate proc_macro;
use proc_macro::*;

#[proc_macro_derive(EthabiContract, attributes(ethabi_contract_options))]
Expand Down
1 change: 0 additions & 1 deletion tests/ui/attributes/main-removed-2/auxiliary/tokyo.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate proc_macro;
use proc_macro::TokenStream;

#[proc_macro_attribute]
Expand Down
1 change: 0 additions & 1 deletion tests/ui/autodiff/auxiliary/my_macro.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate proc_macro;
use proc_macro::TokenStream;

#[proc_macro_attribute]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate proc_macro;
use proc_macro::{TokenStream, TokenTree as Tt};
use std::str::FromStr;

Expand Down
1 change: 0 additions & 1 deletion tests/ui/crate-loading/auxiliary/proc-macro.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![crate_name = "reproduction"]

extern crate proc_macro;
use proc_macro::TokenStream;

#[proc_macro]
Expand Down
1 change: 0 additions & 1 deletion tests/ui/derives/auxiliary/derive-marker-tricky.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate proc_macro;
use proc_macro::*;

#[proc_macro_derive(NoMarker)]
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/deriving/auxiliary/another-proc-macro.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![feature(proc_macro_quote)]

extern crate proc_macro;

use proc_macro::{TokenStream, quote};

#[proc_macro_derive(AnotherMacro, attributes(pointee))]
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/diagnostic_namespace/auxiliary/proc-macro-helper.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate proc_macro;

use proc_macro::TokenStream;

#[proc_macro_attribute]
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/fmt/auxiliary/format-string-proc-macro.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate proc_macro;

use proc_macro::{Delimiter, Group, Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree};
use std::iter::FromIterator;

Expand Down
1 change: 0 additions & 1 deletion tests/ui/hygiene/auxiliary/opaque-hygiene.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![feature(proc_macro_quote)]

extern crate proc_macro;
use proc_macro::{TokenStream, quote};

#[proc_macro]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// A proc-macro in 2015 that has an RPIT without `use<>` that would cause a
// problem with 2024 capturing rules.
//@ edition: 2015

extern crate proc_macro;
use proc_macro::TokenStream;
Expand Down
1 change: 0 additions & 1 deletion tests/ui/inherent-impls-overlap-check/auxiliary/repeat.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate proc_macro;
use proc_macro::{Ident, Group, TokenStream, TokenTree as Tt};

// This constant has to be above the ALLOCATING_ALGO_THRESHOLD
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/lifetimes/auxiliary/issue-91763-aux.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//#![feature(proc_macro_diagnostic, proc_macro_span, proc_macro_def_site)]

extern crate proc_macro;

use proc_macro::{Delimiter, Group, Ident, Punct, Spacing, Span, TokenStream, TokenTree};
use std::iter::FromIterator;

Expand Down
2 changes: 0 additions & 2 deletions tests/ui/lint/auxiliary/add-impl.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate proc_macro;

use proc_macro::TokenStream;

#[proc_macro_derive(AddImpl)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![crate_name="redundant_semi_proc_macro"]
extern crate proc_macro;
use proc_macro::TokenStream;

#[proc_macro_attribute]
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/lint/unsafe_code/auxiliary/forge_unsafe_block.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate proc_macro;

use proc_macro::{Delimiter, Group, Ident, Span, TokenStream, TokenTree};

#[proc_macro]
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/macros/auxiliary/hello_macro.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![feature(proc_macro_quote)]

extern crate proc_macro;

use proc_macro::{TokenStream, quote};

// This macro is not very interesting, but it does contain delimited tokens with
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/macros/auxiliary/issue-100199.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![feature(proc_macro_quote)]

extern crate proc_macro;

use proc_macro::{quote, Ident, Span, TokenStream, TokenTree};

#[proc_macro_attribute]
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/macros/auxiliary/proc_macro_def.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![feature(proc_macro_quote)]

extern crate proc_macro;

use proc_macro::*;

#[proc_macro_attribute]
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/macros/auxiliary/proc_macro_sequence.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![feature(proc_macro_span, proc_macro_quote)]

extern crate proc_macro;

use proc_macro::{quote, Span, TokenStream, TokenTree};

// This macro generates a macro with the same macro definition as `manual_foo` in
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/macros/issue-100199.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | #[issue_100199::struct_with_bound]
= note: this error originates in the attribute macro `issue_100199::struct_with_bound` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this trait
|
LL + use traits::MyTrait;
LL + use crate::traits::MyTrait;
|

error: aborting due to 1 previous error
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/macros/same-sequence-span.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ LL | $(= $z:tt)*
error: `$x:expr` may be followed by `$y:tt`, which is not allowed for `expr` fragments
--> $DIR/same-sequence-span.rs:19:1
|
LL | | macro_rules! manual_foo {
LL | | // When ignoring spans, this macro has the same macro definition as `generated_foo` in
| |_________________________________^ not allowed after `expr` fragments
...
LL | proc_macro_sequence::make_foo!();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate proc_macro;

use proc_macro::TokenStream;

#[proc_macro_derive(ICE)]
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/proc-macro/auxiliary/add-impl.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate proc_macro;

use proc_macro::TokenStream;

#[proc_macro_derive(AddImpl)]
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/proc-macro/auxiliary/amputate-span.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate proc_macro;

use proc_macro::TokenStream;

#[proc_macro_attribute]
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/proc-macro/auxiliary/api/proc_macro_api_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#![feature(proc_macro_span)]
#![deny(dead_code)] // catch if a test function is never called

extern crate proc_macro;

mod cmp;
mod literal;

Expand Down
2 changes: 0 additions & 2 deletions tests/ui/proc-macro/auxiliary/append-impl.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate proc_macro;

use proc_macro::TokenStream;

#[proc_macro_derive(Append)]
Expand Down
Loading

0 comments on commit ea41925

Please sign in to comment.