@@ -1396,18 +1396,20 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
1396
1396
a : & hir:: Expr ,
1397
1397
applicability : & mut Applicability ,
1398
1398
) -> Vec < String > {
1399
- if let hir:: ExprKind :: AddrOf ( _, ref format_arg) = a. node {
1400
- if let hir:: ExprKind :: Match ( ref format_arg_expr, _, _) = format_arg. node {
1401
- if let hir:: ExprKind :: Tup ( ref format_arg_expr_tup) = format_arg_expr. node {
1402
- return format_arg_expr_tup
1403
- . iter ( )
1404
- . map ( |a| snippet_with_applicability ( cx, a. span , ".." , applicability) . into_owned ( ) )
1405
- . collect ( ) ;
1406
- }
1407
- }
1408
- } ;
1399
+ if_chain ! {
1400
+ if let hir:: ExprKind :: AddrOf ( _, ref format_arg) = a. node;
1401
+ if let hir:: ExprKind :: Match ( ref format_arg_expr, _, _) = format_arg. node;
1402
+ if let hir:: ExprKind :: Tup ( ref format_arg_expr_tup) = format_arg_expr. node;
1409
1403
1410
- unreachable ! ( )
1404
+ then {
1405
+ format_arg_expr_tup
1406
+ . iter( )
1407
+ . map( |a| snippet_with_applicability( cx, a. span, ".." , applicability) . into_owned( ) )
1408
+ . collect( )
1409
+ } else {
1410
+ unreachable!( )
1411
+ }
1412
+ }
1411
1413
}
1412
1414
1413
1415
fn is_call ( node : & hir:: ExprKind ) -> bool {
@@ -1671,20 +1673,22 @@ fn lint_cstring_as_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr, source: &hir:
1671
1673
}
1672
1674
1673
1675
fn lint_iter_cloned_collect < ' a , ' tcx > ( cx : & LateContext < ' a , ' tcx > , expr : & hir:: Expr , iter_args : & ' tcx [ hir:: Expr ] ) {
1674
- if match_type ( cx, cx. tables . expr_ty ( expr) , & paths:: VEC ) {
1675
- if let Some ( slice) = derefs_to_slice ( cx, & iter_args[ 0 ] , cx. tables . expr_ty ( & iter_args[ 0 ] ) ) {
1676
- if let Some ( to_replace) = expr. span . trim_start ( slice. span . source_callsite ( ) ) {
1677
- span_lint_and_sugg (
1678
- cx,
1679
- ITER_CLONED_COLLECT ,
1680
- to_replace,
1681
- "called `iter().cloned().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and \
1682
- more readable",
1683
- "try" ,
1684
- ".to_vec()" . to_string ( ) ,
1685
- Applicability :: MachineApplicable ,
1686
- ) ;
1687
- }
1676
+ if_chain ! {
1677
+ if match_type( cx, cx. tables. expr_ty( expr) , & paths:: VEC ) ;
1678
+ if let Some ( slice) = derefs_to_slice( cx, & iter_args[ 0 ] , cx. tables. expr_ty( & iter_args[ 0 ] ) ) ;
1679
+ if let Some ( to_replace) = expr. span. trim_start( slice. span. source_callsite( ) ) ;
1680
+
1681
+ then {
1682
+ span_lint_and_sugg(
1683
+ cx,
1684
+ ITER_CLONED_COLLECT ,
1685
+ to_replace,
1686
+ "called `iter().cloned().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and \
1687
+ more readable",
1688
+ "try" ,
1689
+ ".to_vec()" . to_string( ) ,
1690
+ Applicability :: MachineApplicable ,
1691
+ ) ;
1688
1692
}
1689
1693
}
1690
1694
}
@@ -1944,18 +1948,20 @@ fn lint_unwrap(cx: &LateContext<'_, '_>, expr: &hir::Expr, unwrap_args: &[hir::E
1944
1948
1945
1949
/// lint use of `ok().expect()` for `Result`s
1946
1950
fn lint_ok_expect ( cx : & LateContext < ' _ , ' _ > , expr : & hir:: Expr , ok_args : & [ hir:: Expr ] ) {
1947
- // lint if the caller of `ok()` is a `Result`
1948
- if match_type ( cx, cx. tables . expr_ty ( & ok_args[ 0 ] ) , & paths:: RESULT ) {
1951
+ if_chain ! {
1952
+ // lint if the caller of `ok()` is a `Result`
1953
+ if match_type( cx, cx. tables. expr_ty( & ok_args[ 0 ] ) , & paths:: RESULT ) ;
1949
1954
let result_type = cx. tables. expr_ty( & ok_args[ 0 ] ) ;
1950
- if let Some ( error_type) = get_error_type ( cx, result_type) {
1951
- if has_debug_impl ( error_type, cx) {
1952
- span_lint (
1953
- cx,
1954
- OK_EXPECT ,
1955
- expr. span ,
1956
- "called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`" ,
1957
- ) ;
1958
- }
1955
+ if let Some ( error_type) = get_error_type( cx, result_type) ;
1956
+ if has_debug_impl( error_type, cx) ;
1957
+
1958
+ then {
1959
+ span_lint(
1960
+ cx,
1961
+ OK_EXPECT ,
1962
+ expr. span,
1963
+ "called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`" ,
1964
+ ) ;
1959
1965
}
1960
1966
}
1961
1967
}
0 commit comments