@@ -179,18 +179,10 @@ fn should_wrap_in_braces(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool {
179
179
} )
180
180
}
181
181
182
- fn format_option_in_sugg (
183
- cx : & LateContext < ' _ , ' _ > ,
184
- cond_expr : & Expr < ' _ > ,
185
- parens_around_option : bool ,
186
- as_ref : bool ,
187
- as_mut : bool ,
188
- ) -> String {
182
+ fn format_option_in_sugg ( cx : & LateContext < ' _ , ' _ > , cond_expr : & Expr < ' _ > , as_ref : bool , as_mut : bool ) -> String {
189
183
format ! (
190
- "{}{}{}{}" ,
191
- if parens_around_option { "(" } else { "" } ,
192
- Sugg :: hir( cx, cond_expr, ".." ) ,
193
- if parens_around_option { ")" } else { "" } ,
184
+ "{}{}" ,
185
+ Sugg :: hir( cx, cond_expr, ".." ) . maybe_par( ) ,
194
186
if as_mut {
195
187
".as_mut()"
196
188
} else if as_ref {
@@ -230,28 +222,13 @@ fn detect_option_if_let_else<'a>(cx: &LateContext<'_, 'a>, expr: &'a Expr<'a>) -
230
222
ExprKind :: AddrOf ( _, Mutability :: Mut , _) => ( false , true ) ,
231
223
_ => ( bind_annotation == & BindingAnnotation :: Ref , bind_annotation == & BindingAnnotation :: RefMut ) ,
232
224
} ;
233
- let parens_around_option = match & cond_expr. kind {
234
- // Put parens around the option expression if not doing so might
235
- // mess up the order of operations.
236
- ExprKind :: Call ( ..)
237
- | ExprKind :: MethodCall ( ..)
238
- | ExprKind :: Loop ( ..)
239
- | ExprKind :: Match ( ..)
240
- | ExprKind :: Block ( ..)
241
- | ExprKind :: Field ( ..)
242
- | ExprKind :: Path ( _)
243
- | ExprKind :: Unary ( UnOp :: UnDeref , _)
244
- | ExprKind :: AddrOf ( ..)
245
- => false ,
246
- _ => true ,
247
- } ;
248
225
let cond_expr = match & cond_expr. kind {
249
226
// Pointer dereferencing happens automatically, so we can omit it in the suggestion
250
- ExprKind :: Unary ( UnOp :: UnDeref , expr) | ExprKind :: AddrOf ( _, _, expr) => expr,
227
+ ExprKind :: Unary ( UnOp :: UnDeref , expr) | ExprKind :: AddrOf ( _, _, expr) => expr,
251
228
_ => cond_expr,
252
229
} ;
253
230
Some ( OptionIfLetElseOccurence {
254
- option: format_option_in_sugg( cx, cond_expr, parens_around_option , as_ref, as_mut) ,
231
+ option: format_option_in_sugg( cx, cond_expr, as_ref, as_mut) ,
255
232
method_sugg: method_sugg. to_string( ) ,
256
233
some_expr: format!( "|{}{}| {}" , capture_mut, capture_name, Sugg :: hir( cx, some_body, ".." ) ) ,
257
234
none_expr: format!( "{}{}" , if method_sugg == "map_or" { "" } else { "|| " } , Sugg :: hir( cx, none_body, ".." ) ) ,
0 commit comments