1
+ use clippy_utils:: diagnostics:: span_lint_and_help;
2
+ use clippy_utils:: ty:: is_type_diagnostic_item;
1
3
use if_chain:: if_chain;
2
- use rustc_hir:: * ;
4
+ use rustc_hir:: { Expr , ExprKind , QPath } ;
3
5
use rustc_lint:: { LateContext , LateLintPass } ;
4
6
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
5
- use rustc_span:: { Span , sym} ;
6
- use clippy_utils:: diagnostics:: span_lint_and_help;
7
- use clippy_utils:: ty:: is_type_diagnostic_item;
8
-
7
+ use rustc_span:: { sym, Span } ;
9
8
10
9
declare_clippy_lint ! {
11
10
/// ### What it does
@@ -39,7 +38,6 @@ declare_lint_pass!(UseUnwrapOr => [USE_UNWRAP_OR]);
39
38
40
39
impl < ' tcx > LateLintPass < ' tcx > for UseUnwrapOr {
41
40
fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' _ > ) {
42
-
43
41
// look for x.or().unwrap()
44
42
if_chain ! {
45
43
if let ExprKind :: MethodCall ( path, args, unwrap_span) = expr. kind;
@@ -52,13 +50,13 @@ impl<'tcx> LateLintPass<'tcx> for UseUnwrapOr {
52
50
let title;
53
51
let arg = & caller_args[ 1 ] ; // the argument or(xyz) is called with
54
52
55
- if is_type_diagnostic_item( & cx, ty, sym:: Option ) {
53
+ if is_type_diagnostic_item( cx, ty, sym:: Option ) {
56
54
title = ".or(Some(…)).unwrap() found" ;
57
55
if !is( arg, "Some" ) {
58
56
return ;
59
57
}
60
58
61
- } else if is_type_diagnostic_item( & cx, ty, sym:: Result ) {
59
+ } else if is_type_diagnostic_item( cx, ty, sym:: Result ) {
62
60
title = ".or(Ok(…)).unwrap() found" ;
63
61
if !is( arg, "Ok" ) {
64
62
return ;
@@ -90,16 +88,14 @@ impl<'tcx> LateLintPass<'tcx> for UseUnwrapOr {
90
88
fn is < ' a > ( expr : & Expr < ' a > , name : & str ) -> bool {
91
89
if_chain ! {
92
90
if let ExprKind :: Call ( some_expr, _some_args) = expr. kind;
93
- if let ExprKind :: Path ( path) = & some_expr. kind;
94
- if let QPath :: Resolved ( _, path) = path;
91
+ if let ExprKind :: Path ( QPath :: Resolved ( _, path) ) = & some_expr. kind;
95
92
if let Some ( path_segment) = path. segments. first( ) ;
96
93
if path_segment. ident. name. as_str( ) == name;
97
94
then {
98
- return true ;
95
+ true
99
96
}
100
97
else {
101
- return false ;
98
+ false
102
99
}
103
100
}
104
101
}
105
-
0 commit comments