@@ -14,7 +14,6 @@ use rustc_parse::parser;
14
14
use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
15
15
use rustc_span:: symbol:: { kw, Symbol } ;
16
16
use rustc_span:: { sym, BytePos , Span , DUMMY_SP } ;
17
- use smallvec:: SmallVec ;
18
17
19
18
declare_clippy_lint ! {
20
19
/// **What it does:** This lint warns when you use `println!("")` to
@@ -359,8 +358,8 @@ fn newline_span(fmtstr: &StrLit) -> Span {
359
358
/// empty format string.
360
359
#[ derive( Default ) ]
361
360
struct 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 > ) > ,
364
363
}
365
364
impl SimpleFormatArgs {
366
365
fn get_unnamed ( & self ) -> impl Iterator < Item = & [ Span ] > {
@@ -396,11 +395,11 @@ impl SimpleFormatArgs {
396
395
ArgumentIs ( n) | ArgumentImplicitlyIs ( n) => {
397
396
if self . unnamed . len ( ) <= n {
398
397
// 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 ] ) ;
400
399
if arg. format == SIMPLE {
401
- self . unnamed . push ( SmallVec :: from ( [ span] ) ) ;
400
+ self . unnamed . push ( vec ! [ span] ) ;
402
401
} else {
403
- self . unnamed . push ( SmallVec :: new ( ) ) ;
402
+ self . unnamed . push ( Vec :: new ( ) ) ;
404
403
}
405
404
} else {
406
405
let args = & mut self . unnamed [ n] ;
@@ -410,7 +409,7 @@ impl SimpleFormatArgs {
410
409
// Replace the dummy span, if it exists.
411
410
( [ dummy @ DUMMY_SP ] , true ) => * dummy = span,
412
411
( [ _, ..] , true ) => args. push ( span) ,
413
- ( [ _, ..] , false ) => * args = SmallVec :: new ( ) ,
412
+ ( [ _, ..] , false ) => * args = Vec :: new ( ) ,
414
413
}
415
414
}
416
415
} ,
@@ -420,12 +419,12 @@ impl SimpleFormatArgs {
420
419
// A non-empty format string has been seen already.
421
420
[ ] => ( ) ,
422
421
[ _, ..] if arg. format == SIMPLE => x. 1 . push ( span) ,
423
- [ _, ..] => x. 1 = SmallVec :: new ( ) ,
422
+ [ _, ..] => x. 1 = Vec :: new ( ) ,
424
423
}
425
424
} else if arg. format == SIMPLE {
426
- self . named . push ( ( n, SmallVec :: from ( [ span] ) ) ) ;
425
+ self . named . push ( ( n, vec ! [ span] ) ) ;
427
426
} else {
428
- self . named . push ( ( n, SmallVec :: new ( ) ) ) ;
427
+ self . named . push ( ( n, Vec :: new ( ) ) ) ;
429
428
}
430
429
} ,
431
430
} ;
@@ -436,24 +435,27 @@ impl Write {
436
435
/// Parses a format string into a collection of spans for each argument. This only keeps track
437
436
/// of empty format arguments. Will also lint usages of debug format strings outside of debug
438
437
/// 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 > {
440
439
use rustc_parse_format:: { ParseMode , Parser , Piece } ;
441
440
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 {
444
443
StrStyle :: Cooked => None ,
445
444
StrStyle :: Raw ( n) => Some ( n as usize ) ,
446
445
} ;
447
446
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 ) ;
449
448
let mut args = SimpleFormatArgs :: default ( ) ;
450
449
451
450
while let Some ( arg) = parser. next ( ) {
452
451
let arg = match arg {
453
452
Piece :: String ( _) => continue ,
454
453
Piece :: NextArgument ( arg) => arg,
455
454
} ;
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) ) ;
457
459
458
460
if !self . in_debug_impl && arg. format . ty == "?" {
459
461
// FIXME: modify rustc's fmt string parser to give us the current span
0 commit comments