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
+ } ;
2
4
use if_chain:: if_chain;
3
5
use rustc_errors:: Applicability ;
4
6
use rustc_hir:: { def, Expr , ExprKind , PatKind , QPath } ;
@@ -49,18 +51,18 @@ impl LateLintPass<'_> for ManualOkOr {
49
51
if args. len( ) == 3 ;
50
52
let method_receiver = & args[ 0 ] ;
51
53
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) ) ;
53
55
let or_expr = & args[ 1 ] ;
54
56
if is_ok_wrapping( cx, & args[ 2 ] ) ;
55
57
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) ;
60
62
then {
61
63
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(
64
66
cx,
65
67
MANUAL_OK_OR ,
66
68
scrutinee. span,
@@ -80,7 +82,7 @@ impl LateLintPass<'_> for ManualOkOr {
80
82
81
83
fn is_ok_wrapping ( cx : & LateContext < ' _ > , map_expr : & Expr < ' _ > ) -> bool {
82
84
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 ) {
84
86
return true ;
85
87
}
86
88
}
@@ -89,7 +91,7 @@ fn is_ok_wrapping(cx: &LateContext<'_>, map_expr: &Expr<'_>) -> bool {
89
91
let body = cx. tcx. hir( ) . body( body_id) ;
90
92
if let PatKind :: Binding ( _, param_id, ..) = body. params[ 0 ] . pat. kind;
91
93
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 ) ;
93
95
if let ExprKind :: Path ( QPath :: Resolved ( _, ok_arg_path) ) = ok_arg. kind;
94
96
if let def:: Res :: Local ( ok_arg_path_id) = ok_arg_path. res;
95
97
then { param_id == ok_arg_path_id } else { false }
0 commit comments