@@ -12,6 +12,7 @@ use rustc_hir::{BinOpKind, Block, Expr, ExprKind, HirId, Pat, PatKind, StmtKind}
1212use rustc_lint:: LateContext ;
1313use rustc_middle:: ty:: { self , Ty } ;
1414use rustc_span:: symbol:: sym;
15+ use std:: fmt:: Display ;
1516use std:: iter:: Iterator ;
1617
1718/// Checks for for loops that sequentially copy items from one slice-like
@@ -108,7 +109,7 @@ fn build_manual_memcpy_suggestion<'tcx>(
108109 src : & IndexExpr < ' _ > ,
109110) -> String {
110111 fn print_offset ( offset : MinifyingSugg < ' static > ) -> MinifyingSugg < ' static > {
111- if offset. as_str ( ) == "0" {
112+ if offset. to_string ( ) == "0" {
112113 sugg:: EMPTY . into ( )
113114 } else {
114115 offset
@@ -123,7 +124,7 @@ fn build_manual_memcpy_suggestion<'tcx>(
123124 if let Some ( arg) = len_args. get( 0 ) ;
124125 if path_to_local( arg) == path_to_local( base) ;
125126 then {
126- if sugg. as_str ( ) == end_str {
127+ if sugg. to_string ( ) == end_str {
127128 sugg:: EMPTY . into( )
128129 } else {
129130 sugg
@@ -147,7 +148,7 @@ fn build_manual_memcpy_suggestion<'tcx>(
147148 print_offset ( apply_offset ( & start_str, & idx_expr. idx_offset ) ) . into_sugg ( ) ,
148149 print_limit (
149150 end,
150- end_str. as_str ( ) ,
151+ end_str. to_string ( ) . as_str ( ) ,
151152 idx_expr. base ,
152153 apply_offset ( & end_str, & idx_expr. idx_offset ) ,
153154 )
@@ -159,7 +160,7 @@ fn build_manual_memcpy_suggestion<'tcx>(
159160 print_offset ( apply_offset ( & counter_start, & idx_expr. idx_offset ) ) . into_sugg ( ) ,
160161 print_limit (
161162 end,
162- end_str. as_str ( ) ,
163+ end_str. to_string ( ) . as_str ( ) ,
163164 idx_expr. base ,
164165 apply_offset ( & end_str, & idx_expr. idx_offset ) + & counter_start - & start_str,
165166 )
@@ -202,12 +203,13 @@ fn build_manual_memcpy_suggestion<'tcx>(
202203#[ derive( Clone ) ]
203204struct MinifyingSugg < ' a > ( Sugg < ' a > ) ;
204205
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)
209209 }
210+ }
210211
212+ impl < ' a > MinifyingSugg < ' a > {
211213 fn into_sugg ( self ) -> Sugg < ' a > {
212214 self . 0
213215 }
@@ -222,7 +224,7 @@ impl<'a> From<Sugg<'a>> for MinifyingSugg<'a> {
222224impl std:: ops:: Add for & MinifyingSugg < ' static > {
223225 type Output = MinifyingSugg < ' static > ;
224226 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 ( ) ) {
226228 ( "0" , _) => rhs. clone ( ) ,
227229 ( _, "0" ) => self . clone ( ) ,
228230 ( _, _) => ( & self . 0 + & rhs. 0 ) . into ( ) ,
@@ -233,7 +235,7 @@ impl std::ops::Add for &MinifyingSugg<'static> {
233235impl std:: ops:: Sub for & MinifyingSugg < ' static > {
234236 type Output = MinifyingSugg < ' static > ;
235237 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 ( ) ) {
237239 ( _, "0" ) => self . clone ( ) ,
238240 ( "0" , _) => ( -rhs. 0 . clone ( ) ) . into ( ) ,
239241 ( x, y) if x == y => sugg:: ZERO . into ( ) ,
@@ -245,7 +247,7 @@ impl std::ops::Sub for &MinifyingSugg<'static> {
245247impl std:: ops:: Add < & MinifyingSugg < ' static > > for MinifyingSugg < ' static > {
246248 type Output = MinifyingSugg < ' static > ;
247249 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 ( ) ) {
249251 ( "0" , _) => rhs. clone ( ) ,
250252 ( _, "0" ) => self ,
251253 ( _, _) => ( self . 0 + & rhs. 0 ) . into ( ) ,
@@ -256,7 +258,7 @@ impl std::ops::Add<&MinifyingSugg<'static>> for MinifyingSugg<'static> {
256258impl std:: ops:: Sub < & MinifyingSugg < ' static > > for MinifyingSugg < ' static > {
257259 type Output = MinifyingSugg < ' static > ;
258260 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 ( ) ) {
260262 ( _, "0" ) => self ,
261263 ( "0" , _) => ( -rhs. 0 . clone ( ) ) . into ( ) ,
262264 ( x, y) if x == y => sugg:: ZERO . into ( ) ,
0 commit comments