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