@@ -111,42 +111,51 @@ fn check_manual_swap(cx: &LateContext<'_, '_>, block: &Block) {
111111 return ;
112112 } else if let Slice :: Swappable ( slice, idx1, idx2) = slice {
113113 if let Some ( slice) = Sugg :: hir_opt( cx, slice) {
114- ( false ,
115- format!( " elements of `{}`" , slice) ,
116- format!( "{}.swap({}, {})" ,
117- slice. maybe_par( ) ,
118- snippet( cx, idx1. span, ".." ) ,
119- snippet( cx, idx2. span, ".." ) ) )
114+ (
115+ false ,
116+ format!( " elements of `{}`" , slice) ,
117+ format!(
118+ "{}.swap({}, {})" ,
119+ slice. maybe_par( ) ,
120+ snippet( cx, idx1. span, ".." ) ,
121+ snippet( cx, idx2. span, ".." ) ,
122+ ) ,
123+ )
120124 } else {
121125 ( false , String :: new( ) , String :: new( ) )
122126 }
123127 } else if let ( Some ( first) , Some ( second) ) = ( Sugg :: hir_opt( cx, lhs1) , Sugg :: hir_opt( cx, rhs1) ) {
124- ( true , format!( " `{}` and `{}`" , first, second) ,
125- format!( "std::mem::swap({}, {})" , first. mut_addr( ) , second. mut_addr( ) ) )
128+ (
129+ true ,
130+ format!( " `{}` and `{}`" , first, second) ,
131+ format!( "std::mem::swap({}, {})" , first. mut_addr( ) , second. mut_addr( ) ) ,
132+ )
126133 } else {
127134 ( true , String :: new( ) , String :: new( ) )
128135 } ;
129136
130137 let span = w[ 0 ] . span. to( second. span) ;
131138
132- span_lint_and_then( cx,
133- MANUAL_SWAP ,
134- span,
135- & format!( "this looks like you are swapping{} manually" , what) ,
136- |db| {
137- if !sugg. is_empty( ) {
138- db. span_suggestion(
139- span,
140- "try" ,
141- sugg,
142- Applicability :: Unspecified ,
143- ) ;
139+ span_lint_and_then(
140+ cx,
141+ MANUAL_SWAP ,
142+ span,
143+ & format!( "this looks like you are swapping{} manually" , what) ,
144+ |db| {
145+ if !sugg. is_empty( ) {
146+ db. span_suggestion(
147+ span,
148+ "try" ,
149+ sugg,
150+ Applicability :: Unspecified ,
151+ ) ;
144152
145- if replace {
146- db. note( "or maybe you should use `std::mem::replace`?" ) ;
147- }
148- }
149- } ) ;
153+ if replace {
154+ db. note( "or maybe you should use `std::mem::replace`?" ) ;
155+ }
156+ }
157+ }
158+ ) ;
150159 }
151160 }
152161 }
0 commit comments