Skip to content

Commit f089301

Browse files
Rollup merge of #153600 - cyrgani:any-panic-pm, r=davidtwco
add test for proc-macros with custom panic payloads This was not tested anywhere so far.
2 parents 9b706a7 + 94acbeb commit f089301

3 files changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//! Make sure that proc-macros which panic with a payload other than
2+
//! `String` or `&'static str` do not ICE.
3+
//@ proc-macro: any-panic-payload.rs
4+
5+
extern crate any_panic_payload;
6+
7+
use any_panic_payload::*;
8+
9+
cause_panic!(); //~ ERROR proc macro panicked
10+
11+
#[cause_panic_attr] //~ ERROR custom attribute panicked
12+
struct A;
13+
14+
#[derive(CausePanic)] //~ ERROR proc-macro derive panicked
15+
struct B;
16+
17+
fn main() {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: proc macro panicked
2+
--> $DIR/any-panic-payload.rs:9:1
3+
|
4+
LL | cause_panic!();
5+
| ^^^^^^^^^^^^^^
6+
7+
error: custom attribute panicked
8+
--> $DIR/any-panic-payload.rs:11:1
9+
|
10+
LL | #[cause_panic_attr]
11+
| ^^^^^^^^^^^^^^^^^^^
12+
13+
error: proc-macro derive panicked
14+
--> $DIR/any-panic-payload.rs:14:10
15+
|
16+
LL | #[derive(CausePanic)]
17+
| ^^^^^^^^^^
18+
19+
error: aborting due to 3 previous errors
20+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
extern crate proc_macro;
2+
3+
use proc_macro::TokenStream;
4+
5+
fn boom() -> TokenStream {
6+
std::panic::panic_any(42)
7+
}
8+
9+
#[proc_macro]
10+
pub fn cause_panic(_: TokenStream) -> TokenStream {
11+
boom()
12+
}
13+
14+
#[proc_macro_attribute]
15+
pub fn cause_panic_attr(_: TokenStream, _: TokenStream) -> TokenStream {
16+
boom()
17+
}
18+
19+
#[proc_macro_derive(CausePanic)]
20+
pub fn cause_panic_derive(_: TokenStream) -> TokenStream {
21+
boom()
22+
}

0 commit comments

Comments
 (0)