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