33#![ deny( clippy:: missing_docs_in_private_items) ]
44
55use crate :: { is_expn_of, last_path_segment, match_def_path, paths} ;
6- use bitflags:: bitflags;
76use if_chain:: if_chain;
87use rustc_ast:: ast:: { self , LitKind } ;
98use rustc_hir as hir;
@@ -571,9 +570,10 @@ impl FormatArgsExpn<'tcx> {
571570 }
572571 }
573572
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 ( ) )
577577 }
578578
579579 /// Returns an iterator over `FormatArgsArg`.
@@ -657,16 +657,6 @@ pub struct FormatArgsArg<'tcx> {
657657 fmt : Option < & ' tcx Expr < ' tcx > > ,
658658}
659659
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-
670660impl < ' tcx > FormatArgsArg < ' tcx > {
671661 /// An element of `value_args` according to `position`
672662 pub fn value ( & self ) -> & ' tcx Expr < ' tcx > {
@@ -683,12 +673,10 @@ impl<'tcx> FormatArgsArg<'tcx> {
683673 self . fmt
684674 }
685675
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 `{}`.
690678 #[ allow( clippy:: nonminimal_bool) ]
691- pub fn has_formatting ( & self , formatting : Formatting ) -> bool {
679+ pub fn has_string_formatting ( & self ) -> bool {
692680 self . fmt ( ) . map_or ( false , |fmt| {
693681 // `!` because these conditions check that `self` is unformatted.
694682 !if_chain ! {
@@ -708,27 +696,11 @@ impl<'tcx> FormatArgsArg<'tcx> {
708696 let _ = assert_eq!( precision_field. ident. name, sym:: precision) ;
709697 let _ = assert_eq!( width_field. ident. name, sym:: width) ;
710698
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-
725699 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 ;
728701
729702 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 ;
732704
733705 then { true } else { false }
734706 }
0 commit comments