@@ -1229,43 +1229,36 @@ fn lint_or_fun_call<'a, 'tcx>(
1229
1229
or_has_args : bool ,
1230
1230
span : Span ,
1231
1231
) -> bool {
1232
- if or_has_args {
1233
- return false ;
1234
- }
1235
-
1236
- if name == "unwrap_or" {
1237
- if let hir:: ExprKind :: Path ( ref qpath) = fun. node {
1238
- let path = & * last_path_segment ( qpath) . ident . as_str ( ) ;
1232
+ if_chain ! {
1233
+ if !or_has_args;
1234
+ if name == "unwrap_or" ;
1235
+ if let hir:: ExprKind :: Path ( ref qpath) = fun. node;
1236
+ let path = & * last_path_segment( qpath) . ident. as_str( ) ;
1237
+ if [ "default" , "new" ] . contains( & path) ;
1238
+ let arg_ty = cx. tables. expr_ty( arg) ;
1239
+ if let Some ( default_trait_id) = get_trait_def_id( cx, & paths:: DEFAULT_TRAIT ) ;
1240
+ if implements_trait( cx, arg_ty, default_trait_id, & [ ] ) ;
1239
1241
1240
- if [ "default" , "new" ] . contains ( & path) {
1241
- let arg_ty = cx. tables . expr_ty ( arg) ;
1242
- let default_trait_id = if let Some ( default_trait_id) = get_trait_def_id ( cx, & paths:: DEFAULT_TRAIT ) {
1243
- default_trait_id
1244
- } else {
1245
- return false ;
1246
- } ;
1242
+ then {
1243
+ let mut applicability = Applicability :: MachineApplicable ;
1244
+ span_lint_and_sugg(
1245
+ cx,
1246
+ OR_FUN_CALL ,
1247
+ span,
1248
+ & format!( "use of `{}` followed by a call to `{}`" , name, path) ,
1249
+ "try this" ,
1250
+ format!(
1251
+ "{}.unwrap_or_default()" ,
1252
+ snippet_with_applicability( cx, self_expr. span, "_" , & mut applicability)
1253
+ ) ,
1254
+ applicability,
1255
+ ) ;
1247
1256
1248
- if implements_trait ( cx, arg_ty, default_trait_id, & [ ] ) {
1249
- let mut applicability = Applicability :: MachineApplicable ;
1250
- span_lint_and_sugg (
1251
- cx,
1252
- OR_FUN_CALL ,
1253
- span,
1254
- & format ! ( "use of `{}` followed by a call to `{}`" , name, path) ,
1255
- "try this" ,
1256
- format ! (
1257
- "{}.unwrap_or_default()" ,
1258
- snippet_with_applicability( cx, self_expr. span, "_" , & mut applicability)
1259
- ) ,
1260
- applicability,
1261
- ) ;
1262
- return true ;
1263
- }
1264
- }
1257
+ true
1258
+ } else {
1259
+ false
1265
1260
}
1266
1261
}
1267
-
1268
- false
1269
1262
}
1270
1263
1271
1264
/// Checks for `*or(foo())`.
0 commit comments