11use crate :: parser:: { ParseArg , Parser } ;
2- use proc_macro2:: { token_stream, Delimiter , Ident , Literal , Span , TokenStream , TokenTree } ;
32use proc_macro_error2:: abort;
3+ use proc_macro2:: { Delimiter , Ident , Literal , Span , TokenStream , TokenTree , token_stream} ;
44use quote:: quote;
55use std:: iter:: Peekable ;
66use std:: str:: Chars ;
@@ -65,7 +65,7 @@ pub fn scan_str_lit(lit: &Literal) -> TokenStream {
6565 // If it's braced, we might have a format specifier or it might just be empty braces.
6666 if chars. peek ( ) == Some ( & ':' ) {
6767 chars. next ( ) ; // Consume ':'
68- // Read the format specifier until '}'
68+ // Read the format specifier until '}'
6969 while let Some ( & c) = chars. peek ( ) {
7070 if c == '}' {
7171 break ;
@@ -290,14 +290,13 @@ impl Lexer {
290290 self . extend_last_arg ( quote ! ( #ss. into_os_string( ) ) ) ;
291291 } else {
292292 let mut is_redirect = false ;
293- if s == "1" || s == "2" {
294- if let Some ( TokenTree :: Punct ( p) ) = self . iter . peek_no_gap ( ) {
295- if p. as_char ( ) == '>' {
296- self . iter . next ( ) ;
297- self . scan_redirect_out ( if s == "1" { 1 } else { 2 } ) ;
298- is_redirect = true ;
299- }
300- }
293+ if ( s == "1" || s == "2" )
294+ && let Some ( TokenTree :: Punct ( p) ) = self . iter . peek_no_gap ( )
295+ && p. as_char ( ) == '>'
296+ {
297+ self . iter . next ( ) ;
298+ self . scan_redirect_out ( if s == "1" { 1 } else { 2 } ) ;
299+ is_redirect = true ;
301300 }
302301 if !is_redirect {
303302 self . extend_last_arg ( quote ! ( #s) ) ;
@@ -306,15 +305,15 @@ impl Lexer {
306305 }
307306
308307 fn scan_pipe ( & mut self ) {
309- if let Some ( TokenTree :: Punct ( p) ) = self . iter . peek_no_gap ( ) {
310- if p. as_char ( ) == '&' {
311- if let Some ( ref redirect) = self . last_redirect {
312- abort ! ( redirect. 1 , "invalid '&': found previous redirect" ) ;
313- }
314- Self :: check_set_redirect ( & mut self . seen_redirect . 2 , "stderr" , p. span ( ) ) ;
315- self . args . push ( ParseArg :: RedirectFd ( 2 , 1 ) ) ;
316- self . iter . next ( ) ;
308+ if let Some ( TokenTree :: Punct ( p) ) = self . iter . peek_no_gap ( )
309+ && p. as_char ( ) == '&'
310+ {
311+ if let Some ( ref redirect) = self . last_redirect {
312+ abort ! ( redirect. 1 , "invalid '&': found previous redirect" ) ;
317313 }
314+ Self :: check_set_redirect ( & mut self . seen_redirect . 2 , "stderr" , p. span ( ) ) ;
315+ self . args . push ( ParseArg :: RedirectFd ( 2 , 1 ) ) ;
316+ self . iter . next ( ) ;
318317 }
319318
320319 // expect new command
@@ -342,29 +341,29 @@ impl Lexer {
342341 RedirectFd :: Stderr { append }
343342 } ,
344343 ) ;
345- if let Some ( TokenTree :: Punct ( p) ) = self . iter . peek_no_gap ( ) {
346- if p. as_char ( ) == '&' {
347- if append {
348- abort ! ( p. span( ) , "raw fd not allowed for append redirection" ) ;
344+ if let Some ( TokenTree :: Punct ( p) ) = self . iter . peek_no_gap ( )
345+ && p. as_char ( ) == '&'
346+ {
347+ if append {
348+ abort ! ( p. span( ) , "raw fd not allowed for append redirection" ) ;
349+ }
350+ self . iter . next ( ) ;
351+ if let Some ( TokenTree :: Literal ( lit) ) = self . iter . peek_no_gap ( ) {
352+ let s = lit. to_string ( ) ;
353+ if s. starts_with ( '\"' ) || s. starts_with ( 'r' ) {
354+ abort ! ( lit. span( ) , "invalid literal string after &" ) ;
349355 }
350- self . iter . next ( ) ;
351- if let Some ( TokenTree :: Literal ( lit) ) = self . iter . peek_no_gap ( ) {
352- let s = lit. to_string ( ) ;
353- if s. starts_with ( '\"' ) || s. starts_with ( 'r' ) {
354- abort ! ( lit. span( ) , "invalid literal string after &" ) ;
355- }
356- if & s == "1" {
357- self . args . push ( ParseArg :: RedirectFd ( fd, 1 ) ) ;
358- } else if & s == "2" {
359- self . args . push ( ParseArg :: RedirectFd ( fd, 2 ) ) ;
360- } else {
361- abort ! ( lit. span( ) , "Only &1 or &2 is supported" ) ;
362- }
363- self . last_redirect = None ;
364- self . iter . next ( ) ;
356+ if & s == "1" {
357+ self . args . push ( ParseArg :: RedirectFd ( fd, 1 ) ) ;
358+ } else if & s == "2" {
359+ self . args . push ( ParseArg :: RedirectFd ( fd, 2 ) ) ;
365360 } else {
366- abort ! ( self . iter . span( ) , "expect &1 or &2" ) ;
361+ abort ! ( lit . span( ) , "Only &1 or &2 is supported " ) ;
367362 }
363+ self . last_redirect = None ;
364+ self . iter . next ( ) ;
365+ } else {
366+ abort ! ( self . iter. span( ) , "expect &1 or &2" ) ;
368367 }
369368 }
370369 }
@@ -436,11 +435,11 @@ impl Lexer {
436435
437436 fn check_append ( & mut self ) -> bool {
438437 let mut append = false ;
439- if let Some ( TokenTree :: Punct ( p) ) = self . iter . peek_no_gap ( ) {
440- if p. as_char ( ) == '>' {
441- append = true ;
442- self . iter . next ( ) ;
443- }
438+ if let Some ( TokenTree :: Punct ( p) ) = self . iter . peek_no_gap ( )
439+ && p. as_char ( ) == '>'
440+ {
441+ append = true ;
442+ self . iter . next ( ) ;
444443 }
445444 append
446445 }
0 commit comments