-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for the edition of macro_rules from a proc-macro
- Loading branch information
Showing
7 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//@ force-host | ||
//@ no-prefer-dynamic | ||
|
||
#![crate_type = "proc-macro"] | ||
|
||
extern crate proc_macro; | ||
|
||
use proc_macro::TokenStream; | ||
|
||
#[proc_macro] | ||
pub fn make_edition_macro(_input: TokenStream) -> TokenStream { | ||
"macro_rules! edition { | ||
($_:expr) => { | ||
2024 | ||
}; | ||
(const {}) => { | ||
2021 | ||
}; | ||
} | ||
" | ||
.parse() | ||
.unwrap() | ||
} | ||
|
||
#[proc_macro] | ||
pub fn make_nested_edition_macro(_input: TokenStream) -> TokenStream { | ||
"macro_rules! make_inner { | ||
() => { | ||
macro_rules! edition_inner { | ||
($_:expr) => { | ||
2024 | ||
}; | ||
(const {}) => { | ||
2021 | ||
}; | ||
} | ||
}; | ||
} | ||
" | ||
.parse() | ||
.unwrap() | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/ui/proc-macro/macro_rules_edition_from_pm.edition2021.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error[E0080]: evaluation of constant value failed | ||
--> $DIR/macro_rules_edition_from_pm.rs:24:5 | ||
| | ||
LL | assert!(edition_inner!(const {}) == 2024); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'assertion failed: edition_inner!(const {}) == 2024', $DIR/macro_rules_edition_from_pm.rs:24:5 | ||
| | ||
= note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Tests how edition hygiene works for macro_rules macros generated from a | ||
// proc-macro. | ||
// See https://github.com/rust-lang/rust/issues/132906 | ||
|
||
//@ aux-crate: macro_rules_edition_pm=macro_rules_edition_pm.rs | ||
//@ revisions: edition2021 edition2024 | ||
//@[edition2021] edition:2021 | ||
//@[edition2024] edition:2024 | ||
//@[edition2024] compile-flags: -Zunstable-options | ||
//@[edition2024] check-pass | ||
|
||
// This checks how the expr fragment specifier works. | ||
macro_rules_edition_pm::make_edition_macro!{} | ||
|
||
const _: () = { | ||
assert!(edition!(const {}) == 2021); | ||
}; | ||
|
||
// This checks how the expr fragment specifier from a nested macro. | ||
macro_rules_edition_pm::make_nested_edition_macro!{} | ||
make_inner!{} | ||
|
||
const _: () = { | ||
assert!(edition_inner!(const {}) == 2024); | ||
//[edition2021]~^ ERROR evaluation of constant value failed | ||
}; | ||
|
||
fn main() {} |
22 changes: 22 additions & 0 deletions
22
tests/ui/rust-2024/unsafe-attributes/auxiliary/unsafe-attributes-pm.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//@ force-host | ||
//@ no-prefer-dynamic | ||
|
||
#![crate_type = "proc-macro"] | ||
|
||
extern crate proc_macro; | ||
|
||
use proc_macro::TokenStream; | ||
|
||
#[proc_macro] | ||
pub fn missing_unsafe(_input: TokenStream) -> TokenStream { | ||
"#[no_mangle] pub fn abc() {}".parse().unwrap() | ||
} | ||
|
||
#[proc_macro] | ||
pub fn macro_rules_missing_unsafe(_input: TokenStream) -> TokenStream { | ||
"macro_rules! make_fn { | ||
() => { #[no_mangle] pub fn foo() { } }; | ||
}" | ||
.parse() | ||
.unwrap() | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/ui/rust-2024/unsafe-attributes/unsafe-attributes-from-pm.edition2024.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
error: unsafe attribute used without unsafe | ||
--> $DIR/unsafe-attributes-from-pm.rs:13:1 | ||
| | ||
LL | unsafe_attributes_pm::macro_rules_missing_unsafe!(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ usage of unsafe attribute | ||
... | ||
LL | make_fn!(); | ||
| ---------- in this macro invocation | ||
| | ||
= note: this error originates in the macro `make_fn` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
help: wrap the attribute in `unsafe(...)` | ||
| | ||
LL | ununsafe(safe_attributes_pm::macro_rules_missing_unsafe!()); | ||
| +++++++ + | ||
|
||
error: aborting due to 1 previous error | ||
|
18 changes: 18 additions & 0 deletions
18
tests/ui/rust-2024/unsafe-attributes/unsafe-attributes-from-pm.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Test for unsafe attributes generated by a proc-macro. | ||
// See https://github.com/rust-lang/rust/issues/132906 | ||
|
||
//@ revisions: edition2021 edition2024 | ||
//@[edition2021] check-pass | ||
//@[edition2021] edition:2021 | ||
//@[edition2024] edition:2024 | ||
//@[edition2024] compile-flags: -Zunstable-options | ||
//@ aux-crate: unsafe_attributes_pm=unsafe-attributes-pm.rs | ||
|
||
unsafe_attributes_pm::missing_unsafe!(); | ||
|
||
unsafe_attributes_pm::macro_rules_missing_unsafe!(); | ||
//[edition2024]~^ ERROR unsafe attribute used without unsafe | ||
|
||
make_fn!(); | ||
|
||
fn main() {} |