1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
//@ check-pass
//@ compile-flags: -Zmacro-stats
#[test]
fn test_foo() {
let what = "this";
let how = "completely";
let when = "immediately";
println!("{what} disappears {how} and {when}");
}
#[rustfmt::skip] // non-macro attr, ignored by `-Zmacro-stats`
fn rustfmt_skip() {
// Nothing to see here.
}
#[derive(Default, Clone, Copy, Hash)]
enum E1 {
#[default] // non-macro attr, ignored by `-Zmacro-stats`
A,
B,
}
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
struct E2 {
a: u32,
b: String,
c: Vec<bool>,
}
#[derive(Clone)] struct S0;
#[derive(Clone)] struct S1(u32);
#[derive(Clone)] struct S2(u32, u32);
#[derive(Clone)] struct S3(u32, u32, u32);
#[derive(Clone)] struct S4(u32, u32, u32, u32);
#[derive(Clone)] struct S5(u32, u32, u32, u32, u32);
macro_rules! u32 {
() => { u32 }
}
macro_rules! none {
() => { None }
}
fn opt(x: Option<u32>) {
match x {
Some(_) => {}
none!() => {} // AstFragmentKind::Pat
}
}
macro_rules! long_name_that_fits_on_one_line { () => {} }
long_name_that_fits_on_one_line!();
long_name_that_fits_on_one_line!();
long_name_that_fits_on_one_line!();
long_name_that_fits_on_one_line!();
long_name_that_fits_on_one_line!();
long_name_that_fits_on_one_line!();
long_name_that_fits_on_one_line!();
long_name_that_fits_on_one_line!();
long_name_that_fits_on_one_line!();
long_name_that_fits_on_one_line!();
macro_rules! long_name_that_fits_on_one_line_ { () => {} }
long_name_that_fits_on_one_line_!();
macro_rules! long_name_that_fits_on_one_line__ { () => {} }
long_name_that_fits_on_one_line__!();
macro_rules! long_name_that_fits_on_one_line___ { () => {} }
long_name_that_fits_on_one_line___!();
macro_rules! long_name_that_fits_on_one_line____ { () => {} }
long_name_that_fits_on_one_line____!();
macro_rules! long_name_that_fits_on_one_line_____ { () => {} }
long_name_that_fits_on_one_line_____!();
macro_rules! long_name_that_doesnt_fit_on_one_line {
($t:ty) => {
fn f(_: $t) {}
}
}
long_name_that_doesnt_fit_on_one_line!(u32!()); // AstFragmentKind::{Items,Ty}
macro_rules! trait_tys {
() => {
type A;
type B;
}
}
trait Tr {
trait_tys!(); // AstFragmentKind::TraitItems
}
macro_rules! impl_const { () => { const X: u32 = 0; } }
struct U;
impl U {
impl_const!(); // AstFragmentKind::ImplItems
}
macro_rules! trait_impl_tys {
() => {
type A = u32;
type B = bool;
}
}
struct Tr1;
impl Tr for Tr1 {
trait_impl_tys!(); // AstFragment::TraitImplItems
}
macro_rules! foreign_item {
() => { fn fc(a: u32) -> u32; }
}
extern "C" {
foreign_item!(); // AstFragment::ForeignItems
}
// Include macros are ignored by `-Zmacro-stats`.
mod includes {
mod z1 {
include!("auxiliary/include.rs");
}
mod z2 {
std::include!("auxiliary/include.rs");
}
const B1: &[u8] = include_bytes!("auxiliary/include.rs");
const B2: &[u8] = std::include_bytes!("auxiliary/include.rs");
const S1: &str = include_str!("auxiliary/include.rs");
const S2: &str = std::include_str!("auxiliary/include.rs");
}
fn main() {
macro_rules! n99 {
() => { 99 }
}
let x = n99!() + n99!(); // AstFragmentKind::Expr
macro_rules! p {
() => {
// blah
let x = 1;
let y = x;
let _ = y;
}
}
p!(); // AstFragmentKind::Stmts
macro_rules! q {
() => {};
($($x:ident),*) => { $( let $x: u32 = 12345; )* };
}
q!(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z);
}
|