1- use crate :: utils;
1+ use crate :: utils:: {
2+ indent_of, is_type_diagnostic_item, match_qpath, paths, reindent_multiline, snippet_opt, span_lint_and_sugg,
3+ } ;
24use if_chain:: if_chain;
35use rustc_errors:: Applicability ;
46use rustc_hir:: { def, Expr , ExprKind , PatKind , QPath } ;
@@ -49,18 +51,18 @@ impl LateLintPass<'_> for ManualOkOr {
4951 if args. len( ) == 3 ;
5052 let method_receiver = & args[ 0 ] ;
5153 let ty = cx. typeck_results( ) . expr_ty( method_receiver) ;
52- if utils :: is_type_diagnostic_item( cx, ty, sym!( option_type) ) ;
54+ if is_type_diagnostic_item( cx, ty, sym!( option_type) ) ;
5355 let or_expr = & args[ 1 ] ;
5456 if is_ok_wrapping( cx, & args[ 2 ] ) ;
5557 if let ExprKind :: Call ( Expr { kind: ExprKind :: Path ( err_path) , .. } , & [ ref err_arg] ) = or_expr. kind;
56- if utils :: match_qpath( err_path, & utils :: paths:: RESULT_ERR ) ;
57- if let Some ( method_receiver_snippet) = utils :: snippet_opt( cx, method_receiver. span) ;
58- if let Some ( err_arg_snippet) = utils :: snippet_opt( cx, err_arg. span) ;
59- if let Some ( indent) = utils :: indent_of( cx, scrutinee. span) ;
58+ if match_qpath( err_path, & paths:: RESULT_ERR ) ;
59+ if let Some ( method_receiver_snippet) = snippet_opt( cx, method_receiver. span) ;
60+ if let Some ( err_arg_snippet) = snippet_opt( cx, err_arg. span) ;
61+ if let Some ( indent) = indent_of( cx, scrutinee. span) ;
6062 then {
6163 let reindented_err_arg_snippet =
62- utils :: reindent_multiline( err_arg_snippet. into( ) , true , Some ( indent + 4 ) ) ;
63- utils :: span_lint_and_sugg(
64+ reindent_multiline( err_arg_snippet. into( ) , true , Some ( indent + 4 ) ) ;
65+ span_lint_and_sugg(
6466 cx,
6567 MANUAL_OK_OR ,
6668 scrutinee. span,
@@ -80,7 +82,7 @@ impl LateLintPass<'_> for ManualOkOr {
8082
8183fn is_ok_wrapping ( cx : & LateContext < ' _ > , map_expr : & Expr < ' _ > ) -> bool {
8284 if let ExprKind :: Path ( ref qpath) = map_expr. kind {
83- if utils :: match_qpath ( qpath, & utils :: paths:: RESULT_OK ) {
85+ if match_qpath ( qpath, & paths:: RESULT_OK ) {
8486 return true ;
8587 }
8688 }
@@ -89,7 +91,7 @@ fn is_ok_wrapping(cx: &LateContext<'_>, map_expr: &Expr<'_>) -> bool {
8991 let body = cx. tcx. hir( ) . body( body_id) ;
9092 if let PatKind :: Binding ( _, param_id, ..) = body. params[ 0 ] . pat. kind;
9193 if let ExprKind :: Call ( Expr { kind: ExprKind :: Path ( ok_path) , .. } , & [ ref ok_arg] ) = body. value. kind;
92- if utils :: match_qpath( ok_path, & utils :: paths:: RESULT_OK ) ;
94+ if match_qpath( ok_path, & paths:: RESULT_OK ) ;
9395 if let ExprKind :: Path ( QPath :: Resolved ( _, ok_arg_path) ) = ok_arg. kind;
9496 if let def:: Res :: Local ( ok_arg_path_id) = ok_arg_path. res;
9597 then { param_id == ok_arg_path_id } else { false }
0 commit comments