@@ -175,7 +175,7 @@ macro_rules! define_proc_macros {
175175 pub fn $proc_macro_name( derive_input: :: proc_macro:: TokenStream )
176176 -> :: proc_macro:: TokenStream {
177177 let $input = derive_input. to_string( ) ;
178- let $input: & str = & $crate:: _extract_input( & $input) ;
178+ let $input = $crate:: _extract_input( & $input) ;
179179 $body. parse( ) . unwrap( )
180180 }
181181 ) +
@@ -186,21 +186,26 @@ macro_rules! define_proc_macros {
186186///
187187/// **This function is not part of the public API. It can change or be removed between any versions.**
188188#[ doc( hidden) ]
189- pub fn _extract_input ( derive_input : & str ) -> String {
190- let mut normalized = String :: with_capacity ( derive_input. len ( ) ) ;
191- for piece in derive_input. split_whitespace ( ) {
192- normalized. push_str ( piece) ;
193- normalized. push ( ' ' ) ;
189+ pub fn _extract_input ( derive_input : & str ) -> & str {
190+ let mut input = derive_input;
191+
192+ for expected in & [ "#[allow(unused)]" , "enum" , "ProceduralMasqueradeDummyType" , "{" ,
193+ "Input" , "=" , "(0," , "stringify!" , "(" ] {
194+ input = input. trim_left ( ) ;
195+ assert ! ( input. starts_with( expected) ,
196+ "expected prefix {:?} not found in {:?}" , expected, derive_input) ;
197+ input = & input[ expected. len ( ) ..] ;
194198 }
195199
196- let prefix = "#[allow(unused)] enum ProceduralMasqueradeDummyType { Input = (0, stringify!(" ;
197- let suffix = ")).0, } " ;
198- assert ! ( normalized. starts_with( prefix) , "expected prefix not found in {:?}" , derive_input) ;
199- assert ! ( normalized. ends_with( suffix) , "expected suffix not found in {:?}" , derive_input) ;
200+ for expected in [ ")" , ").0," , "}" ] . iter ( ) . rev ( ) {
201+ input = input. trim_right ( ) ;
202+ assert ! ( input. ends_with( expected) ,
203+ "expected suffix {:?} not found in {:?}" , expected, derive_input) ;
204+ let end = input. len ( ) - expected. len ( ) ;
205+ input = & input[ ..end] ;
206+ }
200207
201- let start = prefix. len ( ) ;
202- let end = normalized. len ( ) - suffix. len ( ) ;
203- normalized[ start..end] . to_owned ( )
208+ input
204209}
205210
206211/// This macro expands to the definition of another macro (whose name is given as a parameter).
0 commit comments