3
3
#![ deny( clippy:: missing_docs_in_private_items) ]
4
4
5
5
use crate :: { is_expn_of, last_path_segment, match_def_path, paths} ;
6
- use bitflags:: bitflags;
7
6
use if_chain:: if_chain;
8
7
use rustc_ast:: ast:: { self , LitKind } ;
9
8
use rustc_hir as hir;
@@ -571,9 +570,10 @@ impl FormatArgsExpn<'tcx> {
571
570
}
572
571
}
573
572
574
- /// Returns true if any argument has the given formatting types.
575
- pub fn has_formatting ( & self , formatting : Formatting ) -> bool {
576
- self . args ( ) . any ( |arg| arg. has_formatting ( formatting) )
573
+ /// Returns true if any argument uses formatting parameters that would have an effect on
574
+ /// strings.
575
+ pub fn has_string_formatting ( & self ) -> bool {
576
+ self . args ( ) . any ( |arg| arg. has_string_formatting ( ) )
577
577
}
578
578
579
579
/// Returns an iterator over `FormatArgsArg`.
@@ -657,16 +657,6 @@ pub struct FormatArgsArg<'tcx> {
657
657
fmt : Option < & ' tcx Expr < ' tcx > > ,
658
658
}
659
659
660
- bitflags ! {
661
- pub struct Formatting : u32 {
662
- const FILL = 0b0000_0001 ;
663
- const ALIGN = 0b0000_0010 ;
664
- const FLAGS = 0b0000_0100 ;
665
- const PRECISION = 0b0000_1000 ;
666
- const WIDTH = 0b0001_0000 ;
667
- }
668
- }
669
-
670
660
impl < ' tcx > FormatArgsArg < ' tcx > {
671
661
/// An element of `value_args` according to `position`
672
662
pub fn value ( & self ) -> & ' tcx Expr < ' tcx > {
@@ -683,12 +673,10 @@ impl<'tcx> FormatArgsArg<'tcx> {
683
673
self . fmt
684
674
}
685
675
686
- /// Returns true if any formatting parameters are used like `{:+2}` instead of just `{}`. Note
687
- /// that the check is performed using the logical OR of the flags. So, for example,
688
- /// `has_formatting(Formatting:all())` checks whether any (not all) formatting types are
689
- /// used.
676
+ /// Returns true if any formatting parameters are used that would have an effect on strings,
677
+ /// like `{:+2}` instead of just `{}`.
690
678
#[ allow( clippy:: nonminimal_bool) ]
691
- pub fn has_formatting ( & self , formatting : Formatting ) -> bool {
679
+ pub fn has_string_formatting ( & self ) -> bool {
692
680
self . fmt ( ) . map_or ( false , |fmt| {
693
681
// `!` because these conditions check that `self` is unformatted.
694
682
!if_chain ! {
@@ -708,27 +696,11 @@ impl<'tcx> FormatArgsArg<'tcx> {
708
696
let _ = assert_eq!( precision_field. ident. name, sym:: precision) ;
709
697
let _ = assert_eq!( width_field. ident. name, sym:: width) ;
710
698
711
- if let ExprKind :: Lit ( lit) = & fill_field. expr. kind;
712
- if let LitKind :: Char ( char ) = lit. node;
713
- if !formatting. contains( Formatting :: FILL )
714
- || char == ' ' ;
715
-
716
- if let ExprKind :: Path ( ref align_path) = align_field. expr. kind;
717
- if !formatting. contains( Formatting :: ALIGN )
718
- || last_path_segment( align_path) . ident. name == sym:: Unknown ;
719
-
720
- if let ExprKind :: Lit ( lit) = & flags_field. expr. kind;
721
- if let LitKind :: Int ( u128 , _) = lit. node;
722
- if !formatting. contains( Formatting :: FLAGS )
723
- || u128 == 0 ;
724
-
725
699
if let ExprKind :: Path ( ref precision_path) = precision_field. expr. kind;
726
- if !formatting. contains( Formatting :: PRECISION )
727
- || last_path_segment( precision_path) . ident. name == sym:: Implied ;
700
+ if last_path_segment( precision_path) . ident. name == sym:: Implied ;
728
701
729
702
if let ExprKind :: Path ( ref width_qpath) = width_field. expr. kind;
730
- if !formatting. contains( Formatting :: WIDTH )
731
- || last_path_segment( width_qpath) . ident. name == sym:: Implied ;
703
+ if last_path_segment( width_qpath) . ident. name == sym:: Implied ;
732
704
733
705
then { true } else { false }
734
706
}
0 commit comments