|
| 1 | +//@ check-pass |
| 2 | +// |
| 3 | +// During development of #124141 at one point expression on attributes were |
| 4 | +// being duplicated and `m1` caused an exponential blowup that caused OOM. |
| 5 | +// The number of recursive calls depends on the number of doc comments on the |
| 6 | +// expr block. On each recursive call, the `#[allow(deprecated)]` attribute(s) on |
| 7 | +// the `0` somehow get duplicated, resulting in 1, 2, 4, 8, ... identical |
| 8 | +// attributes. |
| 9 | +// |
| 10 | +// After the fix, the code compiles quickly and normally. |
| 11 | + |
| 12 | +macro_rules! m1 { |
| 13 | + ($(#[$meta:meta])* { $e:expr }) => { |
| 14 | + m1! { expr: { $e }, unprocessed: [$(#[$meta])*] } |
| 15 | + }; |
| 16 | + |
| 17 | + (expr: { $e:expr }, unprocessed: [ #[$meta:meta] $($metas:tt)* ]) => { |
| 18 | + m1! { expr: { $e }, unprocessed: [ $($metas)* ] } |
| 19 | + }; |
| 20 | + |
| 21 | + (expr: { $e:expr }, unprocessed: []) => { |
| 22 | + { $e } |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +macro_rules! m2 { |
| 27 | + ($(#[$meta:meta])* { $e:stmt }) => { |
| 28 | + m2! { stmt: { $e }, unprocessed: [$(#[$meta])*] } |
| 29 | + }; |
| 30 | + |
| 31 | + (stmt: { $e:stmt }, unprocessed: [ #[$meta:meta] $($metas:tt)* ]) => { |
| 32 | + m2! { stmt: { $e }, unprocessed: [ $($metas)* ] } |
| 33 | + }; |
| 34 | + |
| 35 | + (stmt: { $e:stmt }, unprocessed: []) => { |
| 36 | + { $e } |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +macro_rules! m3 { |
| 41 | + ($(#[$meta:meta])* { $e:item }) => { |
| 42 | + m3! { item: { $e }, unprocessed: [$(#[$meta])*] } |
| 43 | + }; |
| 44 | + |
| 45 | + (item: { $e:item }, unprocessed: [ #[$meta:meta] $($metas:tt)* ]) => { |
| 46 | + m3! { item: { $e }, unprocessed: [ $($metas)* ] } |
| 47 | + }; |
| 48 | + |
| 49 | + (item: { $e:item }, unprocessed: []) => { |
| 50 | + { $e } |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +fn main() { |
| 55 | + // Each additional doc comment line doubles the compile time. |
| 56 | + m1!( |
| 57 | + /// a1 |
| 58 | + /// a2 |
| 59 | + /// a3 |
| 60 | + /// a4 |
| 61 | + /// a5 |
| 62 | + /// a6 |
| 63 | + /// a7 |
| 64 | + /// a8 |
| 65 | + /// a9 |
| 66 | + /// a10 |
| 67 | + /// a11 |
| 68 | + /// a12 |
| 69 | + /// a13 |
| 70 | + /// a14 |
| 71 | + /// a15 |
| 72 | + /// a16 |
| 73 | + /// a17 |
| 74 | + /// a18 |
| 75 | + /// a19 |
| 76 | + /// a20 |
| 77 | + { |
| 78 | + #[allow(deprecated)] 0 |
| 79 | + } |
| 80 | + ); |
| 81 | + |
| 82 | + m2!( |
| 83 | + /// a1 |
| 84 | + /// a2 |
| 85 | + /// a3 |
| 86 | + /// a4 |
| 87 | + /// a5 |
| 88 | + /// a6 |
| 89 | + /// a7 |
| 90 | + /// a8 |
| 91 | + /// a9 |
| 92 | + /// a10 |
| 93 | + /// a11 |
| 94 | + /// a12 |
| 95 | + /// a13 |
| 96 | + /// a14 |
| 97 | + /// a15 |
| 98 | + /// a16 |
| 99 | + /// a17 |
| 100 | + /// a18 |
| 101 | + /// a19 |
| 102 | + /// a20 |
| 103 | + { |
| 104 | + #[allow(deprecated)] let x = 5 |
| 105 | + } |
| 106 | + ); |
| 107 | + |
| 108 | + m3!( |
| 109 | + /// a1 |
| 110 | + /// a2 |
| 111 | + /// a3 |
| 112 | + /// a4 |
| 113 | + /// a5 |
| 114 | + /// a6 |
| 115 | + /// a7 |
| 116 | + /// a8 |
| 117 | + /// a9 |
| 118 | + /// a10 |
| 119 | + /// a11 |
| 120 | + /// a12 |
| 121 | + /// a13 |
| 122 | + /// a14 |
| 123 | + /// a15 |
| 124 | + /// a16 |
| 125 | + /// a17 |
| 126 | + /// a18 |
| 127 | + /// a19 |
| 128 | + /// a20 |
| 129 | + { |
| 130 | + #[allow(deprecated)] struct S; |
| 131 | + } |
| 132 | + ); |
| 133 | +} |
0 commit comments