@@ -817,22 +817,22 @@ struct Offset {
817
817
}
818
818
819
819
impl Offset {
820
- fn negative ( value : MinifyingSugg < ' static > ) -> Self {
820
+ fn negative ( value : Sugg < ' static > ) -> Self {
821
821
Self {
822
- value,
822
+ value : value . into ( ) ,
823
823
sign : OffsetSign :: Negative ,
824
824
}
825
825
}
826
826
827
- fn positive ( value : MinifyingSugg < ' static > ) -> Self {
827
+ fn positive ( value : Sugg < ' static > ) -> Self {
828
828
Self {
829
- value,
829
+ value : value . into ( ) ,
830
830
sign : OffsetSign :: Positive ,
831
831
}
832
832
}
833
833
834
834
fn empty ( ) -> Self {
835
- Self :: positive ( MinifyingSugg :: non_paren ( "0" ) )
835
+ Self :: positive ( sugg :: ZERO )
836
836
}
837
837
}
838
838
@@ -844,30 +844,22 @@ fn apply_offset(lhs: &MinifyingSugg<'static>, rhs: &Offset) -> MinifyingSugg<'st
844
844
}
845
845
846
846
#[ derive( Clone ) ]
847
- struct MinifyingSugg < ' a > ( sugg:: Sugg < ' a > ) ;
848
-
849
- impl std:: fmt:: Display for MinifyingSugg < ' _ > {
850
- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> Result < ( ) , std:: fmt:: Error > {
851
- std:: fmt:: Display :: fmt ( & self . 0 , f)
852
- }
853
- }
847
+ struct MinifyingSugg < ' a > ( Sugg < ' a > ) ;
854
848
855
849
impl < ' a > MinifyingSugg < ' a > {
856
850
fn as_str ( & self ) -> & str {
857
- let sugg :: Sugg :: NonParen ( s) | sugg :: Sugg :: MaybeParen ( s) | sugg :: Sugg :: BinOp ( _, s) = & self . 0 ;
851
+ let Sugg :: NonParen ( s) | Sugg :: MaybeParen ( s) | Sugg :: BinOp ( _, s) = & self . 0 ;
858
852
s. as_ref ( )
859
853
}
860
854
861
- fn hir ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > , default : & ' a str ) -> Self {
862
- Self ( sugg:: Sugg :: hir ( cx, expr, default) )
863
- }
864
-
865
- fn maybe_par ( self ) -> Self {
866
- Self ( self . 0 . maybe_par ( ) )
855
+ fn into_sugg ( self ) -> Sugg < ' a > {
856
+ self . 0
867
857
}
858
+ }
868
859
869
- fn non_paren ( str : impl Into < std:: borrow:: Cow < ' a , str > > ) -> Self {
870
- Self ( sugg:: Sugg :: NonParen ( str. into ( ) ) )
860
+ impl < ' a > From < Sugg < ' a > > for MinifyingSugg < ' a > {
861
+ fn from ( sugg : Sugg < ' a > ) -> Self {
862
+ Self ( sugg)
871
863
}
872
864
}
873
865
@@ -877,7 +869,7 @@ impl std::ops::Add for &MinifyingSugg<'static> {
877
869
match ( self . as_str ( ) , rhs. as_str ( ) ) {
878
870
( "0" , _) => rhs. clone ( ) ,
879
871
( _, "0" ) => self . clone ( ) ,
880
- ( _, _) => MinifyingSugg ( & self . 0 + & rhs. 0 ) ,
872
+ ( _, _) => ( & self . 0 + & rhs. 0 ) . into ( ) ,
881
873
}
882
874
}
883
875
}
@@ -887,9 +879,9 @@ impl std::ops::Sub for &MinifyingSugg<'static> {
887
879
fn sub ( self , rhs : & MinifyingSugg < ' static > ) -> MinifyingSugg < ' static > {
888
880
match ( self . as_str ( ) , rhs. as_str ( ) ) {
889
881
( _, "0" ) => self . clone ( ) ,
890
- ( "0" , _) => MinifyingSugg ( - ( rhs. 0 . clone ( ) ) ) ,
891
- ( x, y) if x == y => MinifyingSugg :: non_paren ( "0" ) ,
892
- ( _, _) => MinifyingSugg ( & self . 0 - & rhs. 0 ) ,
882
+ ( "0" , _) => ( - rhs. 0 . clone ( ) ) . into ( ) ,
883
+ ( x, y) if x == y => sugg :: ZERO . into ( ) ,
884
+ ( _, _) => ( & self . 0 - & rhs. 0 ) . into ( ) ,
893
885
}
894
886
}
895
887
}
@@ -900,7 +892,7 @@ impl std::ops::Add<&MinifyingSugg<'static>> for MinifyingSugg<'static> {
900
892
match ( self . as_str ( ) , rhs. as_str ( ) ) {
901
893
( "0" , _) => rhs. clone ( ) ,
902
894
( _, "0" ) => self ,
903
- ( _, _) => MinifyingSugg ( self . 0 + & rhs. 0 ) ,
895
+ ( _, _) => ( self . 0 + & rhs. 0 ) . into ( ) ,
904
896
}
905
897
}
906
898
}
@@ -910,9 +902,9 @@ impl std::ops::Sub<&MinifyingSugg<'static>> for MinifyingSugg<'static> {
910
902
fn sub ( self , rhs : & MinifyingSugg < ' static > ) -> MinifyingSugg < ' static > {
911
903
match ( self . as_str ( ) , rhs. as_str ( ) ) {
912
904
( _, "0" ) => self ,
913
- ( "0" , _) => MinifyingSugg ( - ( rhs. 0 . clone ( ) ) ) ,
914
- ( x, y) if x == y => MinifyingSugg :: non_paren ( "0" ) ,
915
- ( _, _) => MinifyingSugg ( self . 0 - & rhs. 0 ) ,
905
+ ( "0" , _) => ( - rhs. 0 . clone ( ) ) . into ( ) ,
906
+ ( x, y) if x == y => sugg :: ZERO . into ( ) ,
907
+ ( _, _) => ( self . 0 - & rhs. 0 ) . into ( ) ,
916
908
}
917
909
}
918
910
}
@@ -969,19 +961,15 @@ fn get_details_from_idx<'tcx>(
969
961
} )
970
962
}
971
963
972
- fn get_offset < ' tcx > (
973
- cx : & LateContext < ' tcx > ,
974
- e : & Expr < ' _ > ,
975
- starts : & [ Start < ' tcx > ] ,
976
- ) -> Option < MinifyingSugg < ' static > > {
964
+ fn get_offset < ' tcx > ( cx : & LateContext < ' tcx > , e : & Expr < ' _ > , starts : & [ Start < ' tcx > ] ) -> Option < Sugg < ' static > > {
977
965
match & e. kind {
978
966
ExprKind :: Lit ( l) => match l. node {
979
- ast:: LitKind :: Int ( x, _ty) => Some ( MinifyingSugg :: non_paren ( x. to_string ( ) ) ) ,
967
+ ast:: LitKind :: Int ( x, _ty) => Some ( Sugg :: NonParen ( x. to_string ( ) . into ( ) ) ) ,
980
968
_ => None ,
981
969
} ,
982
970
ExprKind :: Path ( ..) if get_start ( cx, e, starts) . is_none ( ) => {
983
971
// `e` is always non paren as it's a `Path`
984
- Some ( MinifyingSugg :: non_paren ( snippet ( cx, e. span , "???" ) ) )
972
+ Some ( Sugg :: NonParen ( snippet ( cx, e. span , "???" ) ) )
985
973
} ,
986
974
_ => None ,
987
975
}
@@ -1072,7 +1060,7 @@ fn build_manual_memcpy_suggestion<'tcx>(
1072
1060
) -> String {
1073
1061
fn print_offset ( offset : MinifyingSugg < ' static > ) -> MinifyingSugg < ' static > {
1074
1062
if offset. as_str ( ) == "0" {
1075
- MinifyingSugg :: non_paren ( "" )
1063
+ sugg :: EMPTY . into ( )
1076
1064
} else {
1077
1065
offset
1078
1066
}
@@ -1088,44 +1076,46 @@ fn build_manual_memcpy_suggestion<'tcx>(
1088
1076
if var_def_id( cx, arg) == var_def_id( cx, base) ;
1089
1077
then {
1090
1078
if sugg. as_str( ) == end_str {
1091
- MinifyingSugg :: non_paren ( "" )
1079
+ sugg :: EMPTY . into ( )
1092
1080
} else {
1093
1081
sugg
1094
1082
}
1095
1083
} else {
1096
1084
match limits {
1097
1085
ast:: RangeLimits :: Closed => {
1098
- sugg + & MinifyingSugg :: non_paren ( "1" )
1086
+ sugg + & sugg :: ONE . into ( )
1099
1087
} ,
1100
1088
ast:: RangeLimits :: HalfOpen => sugg,
1101
1089
}
1102
1090
}
1103
1091
}
1104
1092
} ;
1105
1093
1106
- let start_str = MinifyingSugg :: hir ( cx, start, "" ) ;
1107
- let end_str = MinifyingSugg :: hir ( cx, end, "" ) ;
1094
+ let start_str = Sugg :: hir ( cx, start, "" ) . into ( ) ;
1095
+ let end_str: MinifyingSugg < ' _ > = Sugg :: hir ( cx, end, "" ) . into ( ) ;
1108
1096
1109
1097
let print_offset_and_limit = |idx_expr : & IndexExpr < ' _ > | match idx_expr. idx {
1110
1098
StartKind :: Range => (
1111
- print_offset ( apply_offset ( & start_str, & idx_expr. idx_offset ) ) ,
1099
+ print_offset ( apply_offset ( & start_str, & idx_expr. idx_offset ) ) . into_sugg ( ) ,
1112
1100
print_limit (
1113
1101
end,
1114
1102
end_str. as_str ( ) ,
1115
1103
idx_expr. base ,
1116
1104
apply_offset ( & end_str, & idx_expr. idx_offset ) ,
1117
- ) ,
1105
+ )
1106
+ . into_sugg ( ) ,
1118
1107
) ,
1119
1108
StartKind :: Counter { initializer } => {
1120
- let counter_start = MinifyingSugg :: hir ( cx, initializer, "" ) ;
1109
+ let counter_start = Sugg :: hir ( cx, initializer, "" ) . into ( ) ;
1121
1110
(
1122
- print_offset ( apply_offset ( & counter_start, & idx_expr. idx_offset ) ) ,
1111
+ print_offset ( apply_offset ( & counter_start, & idx_expr. idx_offset ) ) . into_sugg ( ) ,
1123
1112
print_limit (
1124
1113
end,
1125
1114
end_str. as_str ( ) ,
1126
1115
idx_expr. base ,
1127
1116
apply_offset ( & end_str, & idx_expr. idx_offset ) + & counter_start - & start_str,
1128
- ) ,
1117
+ )
1118
+ . into_sugg ( ) ,
1129
1119
)
1130
1120
} ,
1131
1121
} ;
@@ -1136,7 +1126,7 @@ fn build_manual_memcpy_suggestion<'tcx>(
1136
1126
let dst_base_str = snippet ( cx, dst. base . span , "???" ) ;
1137
1127
let src_base_str = snippet ( cx, src. base . span , "???" ) ;
1138
1128
1139
- let dst = if dst_offset. as_str ( ) == "" && dst_limit. as_str ( ) == "" {
1129
+ let dst = if dst_offset == sugg :: EMPTY && dst_limit == sugg :: EMPTY {
1140
1130
dst_base_str
1141
1131
} else {
1142
1132
format ! (
0 commit comments