@@ -198,18 +198,35 @@ macro_rules! define_proc_macros {
198198pub fn _extract_input ( derive_input : & str ) -> & str {
199199 let mut input = derive_input;
200200
201- for expected in & [ "#[allow(unused)]" , "enum" , "ProceduralMasqueradeDummyType" , "{" ,
202- "Input" , "=" , "(0," , "stringify!" , "(" ] {
201+ for expected in & [
202+ "#[allow(unused)]" ,
203+ "enum" ,
204+ "ProceduralMasqueradeDummyType" ,
205+ "{" ,
206+ "Input" ,
207+ "=" ,
208+ "(0," ,
209+ "stringify!" ,
210+ "(" ,
211+ ] {
203212 input = input. trim_start ( ) ;
204- assert ! ( input. starts_with( expected) ,
205- "expected prefix {:?} not found in {:?}" , expected, derive_input) ;
213+ assert ! (
214+ input. starts_with( expected) ,
215+ "expected prefix {:?} not found in {:?}" ,
216+ expected,
217+ derive_input
218+ ) ;
206219 input = & input[ expected. len ( ) ..] ;
207220 }
208221
209222 for expected in [ ")" , ").0," , "}" ] . iter ( ) . rev ( ) {
210223 input = input. trim_end ( ) ;
211- assert ! ( input. ends_with( expected) ,
212- "expected suffix {:?} not found in {:?}" , expected, derive_input) ;
224+ assert ! (
225+ input. ends_with( expected) ,
226+ "expected suffix {:?} not found in {:?}" ,
227+ expected,
228+ derive_input
229+ ) ;
213230 let end = input. len ( ) - expected. len ( ) ;
214231 input = & input[ ..end] ;
215232 }
@@ -227,33 +244,33 @@ macro_rules! define_invoke_proc_macro {
227244 #[ doc( hidden) ]
228245 #[ macro_export]
229246 macro_rules! $macro_name {
230- ( $proc_macro_name: ident ! $paren: tt) => {
231- #[ derive( $proc_macro_name) ]
232- #[ allow( unused) ]
233- enum ProceduralMasqueradeDummyType {
234- // The magic happens here.
235- //
236- // We use an `enum` with an explicit discriminant
237- // because that is the only case where a type definition
238- // can contain a (const) expression.
239- //
240- // `(0, "foo").0` evalutes to 0, with the `"foo"` part ignored.
241- //
242- // By the time the `#[proc_macro_derive]` function
243- // implementing `#[derive($proc_macro_name)]` is called,
244- // `$paren` has already been replaced with the input of this inner macro,
245- // but `stringify!` has not been expanded yet.
246- //
247- // This how arbitrary tokens can be inserted
248- // in the input to the `#[proc_macro_derive]` function.
249- //
250- // Later, `stringify!(...)` is expanded into a string literal
251- // which is then ignored.
252- // Using `stringify!` enables passing arbitrary tokens
253- // rather than only what can be parsed as a const expression.
254- Input = ( 0 , stringify! $paren ) . 0
255- }
256- }
257- }
258- }
247+ ( $proc_macro_name: ident ! $paren: tt) => {
248+ #[ derive( $proc_macro_name) ]
249+ #[ allow( unused) ]
250+ enum ProceduralMasqueradeDummyType {
251+ // The magic happens here.
252+ //
253+ // We use an `enum` with an explicit discriminant
254+ // because that is the only case where a type definition
255+ // can contain a (const) expression.
256+ //
257+ // `(0, "foo").0` evalutes to 0, with the `"foo"` part ignored.
258+ //
259+ // By the time the `#[proc_macro_derive]` function
260+ // implementing `#[derive($proc_macro_name)]` is called,
261+ // `$paren` has already been replaced with the input of this inner macro,
262+ // but `stringify!` has not been expanded yet.
263+ //
264+ // This how arbitrary tokens can be inserted
265+ // in the input to the `#[proc_macro_derive]` function.
266+ //
267+ // Later, `stringify!(...)` is expanded into a string literal
268+ // which is then ignored.
269+ // Using `stringify!` enables passing arbitrary tokens
270+ // rather than only what can be parsed as a const expression.
271+ Input = ( 0 , stringify! $paren ) . 0
272+ }
273+ }
274+ }
275+ } ;
259276}
0 commit comments