@@ -111,42 +111,51 @@ fn check_manual_swap(cx: &LateContext<'_, '_>, block: &Block) {
111
111
return ;
112
112
} else if let Slice :: Swappable ( slice, idx1, idx2) = slice {
113
113
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
+ )
120
124
} else {
121
125
( false , String :: new( ) , String :: new( ) )
122
126
}
123
127
} 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
+ )
126
133
} else {
127
134
( true , String :: new( ) , String :: new( ) )
128
135
} ;
129
136
130
137
let span = w[ 0 ] . span. to( second. span) ;
131
138
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
+ ) ;
144
152
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
+ ) ;
150
159
}
151
160
}
152
161
}
0 commit comments