@@ -12,6 +12,7 @@ use rustc_hir::{BinOpKind, Block, Expr, ExprKind, HirId, Pat, PatKind, StmtKind}
12
12
use rustc_lint:: LateContext ;
13
13
use rustc_middle:: ty:: { self , Ty } ;
14
14
use rustc_span:: symbol:: sym;
15
+ use std:: fmt:: Display ;
15
16
use std:: iter:: Iterator ;
16
17
17
18
/// Checks for for loops that sequentially copy items from one slice-like
@@ -108,7 +109,7 @@ fn build_manual_memcpy_suggestion<'tcx>(
108
109
src : & IndexExpr < ' _ > ,
109
110
) -> String {
110
111
fn print_offset ( offset : MinifyingSugg < ' static > ) -> MinifyingSugg < ' static > {
111
- if offset. as_str ( ) == "0" {
112
+ if offset. to_string ( ) == "0" {
112
113
sugg:: EMPTY . into ( )
113
114
} else {
114
115
offset
@@ -123,7 +124,7 @@ fn build_manual_memcpy_suggestion<'tcx>(
123
124
if let Some ( arg) = len_args. get( 0 ) ;
124
125
if path_to_local( arg) == path_to_local( base) ;
125
126
then {
126
- if sugg. as_str ( ) == end_str {
127
+ if sugg. to_string ( ) == end_str {
127
128
sugg:: EMPTY . into( )
128
129
} else {
129
130
sugg
@@ -147,7 +148,7 @@ fn build_manual_memcpy_suggestion<'tcx>(
147
148
print_offset ( apply_offset ( & start_str, & idx_expr. idx_offset ) ) . into_sugg ( ) ,
148
149
print_limit (
149
150
end,
150
- end_str. as_str ( ) ,
151
+ end_str. to_string ( ) . as_str ( ) ,
151
152
idx_expr. base ,
152
153
apply_offset ( & end_str, & idx_expr. idx_offset ) ,
153
154
)
@@ -159,7 +160,7 @@ fn build_manual_memcpy_suggestion<'tcx>(
159
160
print_offset ( apply_offset ( & counter_start, & idx_expr. idx_offset ) ) . into_sugg ( ) ,
160
161
print_limit (
161
162
end,
162
- end_str. as_str ( ) ,
163
+ end_str. to_string ( ) . as_str ( ) ,
163
164
idx_expr. base ,
164
165
apply_offset ( & end_str, & idx_expr. idx_offset ) + & counter_start - & start_str,
165
166
)
@@ -202,12 +203,13 @@ fn build_manual_memcpy_suggestion<'tcx>(
202
203
#[ derive( Clone ) ]
203
204
struct MinifyingSugg < ' a > ( Sugg < ' a > ) ;
204
205
205
- impl < ' a > MinifyingSugg < ' a > {
206
- fn as_str ( & self ) -> & str {
207
- let ( Sugg :: NonParen ( s) | Sugg :: MaybeParen ( s) | Sugg :: BinOp ( _, s) ) = & self . 0 ;
208
- s. as_ref ( )
206
+ impl Display for MinifyingSugg < ' a > {
207
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
208
+ self . 0 . fmt ( f)
209
209
}
210
+ }
210
211
212
+ impl < ' a > MinifyingSugg < ' a > {
211
213
fn into_sugg ( self ) -> Sugg < ' a > {
212
214
self . 0
213
215
}
@@ -222,7 +224,7 @@ impl<'a> From<Sugg<'a>> for MinifyingSugg<'a> {
222
224
impl std:: ops:: Add for & MinifyingSugg < ' static > {
223
225
type Output = MinifyingSugg < ' static > ;
224
226
fn add ( self , rhs : & MinifyingSugg < ' static > ) -> MinifyingSugg < ' static > {
225
- match ( self . as_str ( ) , rhs. as_str ( ) ) {
227
+ match ( self . to_string ( ) . as_str ( ) , rhs. to_string ( ) . as_str ( ) ) {
226
228
( "0" , _) => rhs. clone ( ) ,
227
229
( _, "0" ) => self . clone ( ) ,
228
230
( _, _) => ( & self . 0 + & rhs. 0 ) . into ( ) ,
@@ -233,7 +235,7 @@ impl std::ops::Add for &MinifyingSugg<'static> {
233
235
impl std:: ops:: Sub for & MinifyingSugg < ' static > {
234
236
type Output = MinifyingSugg < ' static > ;
235
237
fn sub ( self , rhs : & MinifyingSugg < ' static > ) -> MinifyingSugg < ' static > {
236
- match ( self . as_str ( ) , rhs. as_str ( ) ) {
238
+ match ( self . to_string ( ) . as_str ( ) , rhs. to_string ( ) . as_str ( ) ) {
237
239
( _, "0" ) => self . clone ( ) ,
238
240
( "0" , _) => ( -rhs. 0 . clone ( ) ) . into ( ) ,
239
241
( x, y) if x == y => sugg:: ZERO . into ( ) ,
@@ -245,7 +247,7 @@ impl std::ops::Sub for &MinifyingSugg<'static> {
245
247
impl std:: ops:: Add < & MinifyingSugg < ' static > > for MinifyingSugg < ' static > {
246
248
type Output = MinifyingSugg < ' static > ;
247
249
fn add ( self , rhs : & MinifyingSugg < ' static > ) -> MinifyingSugg < ' static > {
248
- match ( self . as_str ( ) , rhs. as_str ( ) ) {
250
+ match ( self . to_string ( ) . as_str ( ) , rhs. to_string ( ) . as_str ( ) ) {
249
251
( "0" , _) => rhs. clone ( ) ,
250
252
( _, "0" ) => self ,
251
253
( _, _) => ( self . 0 + & rhs. 0 ) . into ( ) ,
@@ -256,7 +258,7 @@ impl std::ops::Add<&MinifyingSugg<'static>> for MinifyingSugg<'static> {
256
258
impl std:: ops:: Sub < & MinifyingSugg < ' static > > for MinifyingSugg < ' static > {
257
259
type Output = MinifyingSugg < ' static > ;
258
260
fn sub ( self , rhs : & MinifyingSugg < ' static > ) -> MinifyingSugg < ' static > {
259
- match ( self . as_str ( ) , rhs. as_str ( ) ) {
261
+ match ( self . to_string ( ) . as_str ( ) , rhs. to_string ( ) . as_str ( ) ) {
260
262
( _, "0" ) => self ,
261
263
( "0" , _) => ( -rhs. 0 . clone ( ) ) . into ( ) ,
262
264
( x, y) if x == y => sugg:: ZERO . into ( ) ,
0 commit comments