@@ -14,7 +14,6 @@ use rustc_parse::parser;
1414use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
1515use rustc_span:: symbol:: { kw, Symbol } ;
1616use rustc_span:: { sym, BytePos , Span , DUMMY_SP } ;
17- use smallvec:: SmallVec ;
1817
1918declare_clippy_lint ! {
2019 /// **What it does:** This lint warns when you use `println!("")` to
@@ -359,8 +358,8 @@ fn newline_span(fmtstr: &StrLit) -> Span {
359358/// empty format string.
360359#[ derive( Default ) ]
361360struct SimpleFormatArgs {
362- unnamed : Vec < SmallVec < [ Span ; 1 ] > > ,
363- named : Vec < ( Symbol , SmallVec < [ Span ; 1 ] > ) > ,
361+ unnamed : Vec < Vec < Span > > ,
362+ named : Vec < ( Symbol , Vec < Span > ) > ,
364363}
365364impl SimpleFormatArgs {
366365 fn get_unnamed ( & self ) -> impl Iterator < Item = & [ Span ] > {
@@ -396,11 +395,11 @@ impl SimpleFormatArgs {
396395 ArgumentIs ( n) | ArgumentImplicitlyIs ( n) => {
397396 if self . unnamed . len ( ) <= n {
398397 // Use a dummy span to mark all unseen arguments.
399- self . unnamed . resize_with ( n, || SmallVec :: from ( [ DUMMY_SP ] ) ) ;
398+ self . unnamed . resize_with ( n, || vec ! [ DUMMY_SP ] ) ;
400399 if arg. format == SIMPLE {
401- self . unnamed . push ( SmallVec :: from ( [ span] ) ) ;
400+ self . unnamed . push ( vec ! [ span] ) ;
402401 } else {
403- self . unnamed . push ( SmallVec :: new ( ) ) ;
402+ self . unnamed . push ( Vec :: new ( ) ) ;
404403 }
405404 } else {
406405 let args = & mut self . unnamed [ n] ;
@@ -410,7 +409,7 @@ impl SimpleFormatArgs {
410409 // Replace the dummy span, if it exists.
411410 ( [ dummy @ DUMMY_SP ] , true ) => * dummy = span,
412411 ( [ _, ..] , true ) => args. push ( span) ,
413- ( [ _, ..] , false ) => * args = SmallVec :: new ( ) ,
412+ ( [ _, ..] , false ) => * args = Vec :: new ( ) ,
414413 }
415414 }
416415 } ,
@@ -420,12 +419,12 @@ impl SimpleFormatArgs {
420419 // A non-empty format string has been seen already.
421420 [ ] => ( ) ,
422421 [ _, ..] if arg. format == SIMPLE => x. 1 . push ( span) ,
423- [ _, ..] => x. 1 = SmallVec :: new ( ) ,
422+ [ _, ..] => x. 1 = Vec :: new ( ) ,
424423 }
425424 } else if arg. format == SIMPLE {
426- self . named . push ( ( n, SmallVec :: from ( [ span] ) ) ) ;
425+ self . named . push ( ( n, vec ! [ span] ) ) ;
427426 } else {
428- self . named . push ( ( n, SmallVec :: new ( ) ) ) ;
427+ self . named . push ( ( n, Vec :: new ( ) ) ) ;
429428 }
430429 } ,
431430 } ;
@@ -436,24 +435,27 @@ impl Write {
436435 /// Parses a format string into a collection of spans for each argument. This only keeps track
437436 /// of empty format arguments. Will also lint usages of debug format strings outside of debug
438437 /// impls.
439- fn parse_fmt_string ( & self , cx : & EarlyContext < ' _ > , str : & StrLit ) -> Option < SimpleFormatArgs > {
438+ fn parse_fmt_string ( & self , cx : & EarlyContext < ' _ > , str_lit : & StrLit ) -> Option < SimpleFormatArgs > {
440439 use rustc_parse_format:: { ParseMode , Parser , Piece } ;
441440
442- let str_sym = str . symbol_unescaped . as_str ( ) ;
443- let style = match str . style {
441+ let str_sym = str_lit . symbol_unescaped . as_str ( ) ;
442+ let style = match str_lit . style {
444443 StrStyle :: Cooked => None ,
445444 StrStyle :: Raw ( n) => Some ( n as usize ) ,
446445 } ;
447446
448- let mut parser = Parser :: new ( & str_sym, style, snippet_opt ( cx, str . span ) , false , ParseMode :: Format ) ;
447+ let mut parser = Parser :: new ( & str_sym, style, snippet_opt ( cx, str_lit . span ) , false , ParseMode :: Format ) ;
449448 let mut args = SimpleFormatArgs :: default ( ) ;
450449
451450 while let Some ( arg) = parser. next ( ) {
452451 let arg = match arg {
453452 Piece :: String ( _) => continue ,
454453 Piece :: NextArgument ( arg) => arg,
455454 } ;
456- let span = parser. arg_places . last ( ) . map_or ( DUMMY_SP , |& x| str. span . from_inner ( x) ) ;
455+ let span = parser
456+ . arg_places
457+ . last ( )
458+ . map_or ( DUMMY_SP , |& x| str_lit. span . from_inner ( x) ) ;
457459
458460 if !self . in_debug_impl && arg. format . ty == "?" {
459461 // FIXME: modify rustc's fmt string parser to give us the current span
@@ -489,7 +491,11 @@ impl Write {
489491 fn check_tts < ' a > ( & self , cx : & EarlyContext < ' a > , tts : TokenStream , is_write : bool ) -> ( Option < StrLit > , Option < Expr > ) {
490492 let mut parser = parser:: Parser :: new ( & cx. sess . parse_sess , tts, false , None ) ;
491493 let expr = if is_write {
492- match parser. parse_expr ( ) . map ( |e| e. into_inner ( ) ) . map_err ( |mut e| e. cancel ( ) ) {
494+ match parser
495+ . parse_expr ( )
496+ . map ( rustc_ast:: ptr:: P :: into_inner)
497+ . map_err ( |mut e| e. cancel ( ) )
498+ {
493499 // write!(e, ...)
494500 Ok ( p) if parser. eat ( & token:: Comma ) => Some ( p) ,
495501 // write!(e) or error
@@ -543,14 +549,14 @@ impl Write {
543549 lit. token . symbol . as_str ( ) . replace ( "{" , "{{" ) . replace ( "}" , "}}" )
544550 } ,
545551 LitKind :: StrRaw ( _) | LitKind :: Str | LitKind :: ByteStrRaw ( _) | LitKind :: ByteStr => continue ,
546- LitKind :: Byte | LitKind :: Char => match lit. token . symbol . as_str ( ) . deref ( ) {
552+ LitKind :: Byte | LitKind :: Char => match & * lit. token . symbol . as_str ( ) {
547553 "\" " if matches ! ( fmtstr. style, StrStyle :: Cooked ) => "\\ \" " ,
548554 "\" " if matches ! ( fmtstr. style, StrStyle :: Raw ( 0 ) ) => continue ,
549555 "\\ \\ " if matches ! ( fmtstr. style, StrStyle :: Raw ( _) ) => "\\ " ,
550556 "\\ '" => "'" ,
551557 "{" => "{{" ,
552558 "}" => "}}" ,
553- x if matches ! ( fmtstr. style, StrStyle :: Raw ( _) ) && x. starts_with ( " \\ " ) => continue ,
559+ x if matches ! ( fmtstr. style, StrStyle :: Raw ( _) ) && x. starts_with ( '\\' ) => continue ,
554560 x => x,
555561 }
556562 . into ( ) ,
0 commit comments