1
1
use clippy_utils:: diagnostics:: { span_lint, span_lint_and_help} ;
2
- use clippy_utils:: { is_trait_method, is_try, match_trait_method, paths} ;
2
+ use clippy_utils:: { is_path_lang_item , is_trait_method, is_try, match_trait_method, paths} ;
3
3
use rustc_hir as hir;
4
4
use rustc_lint:: { LateContext , LateLintPass } ;
5
5
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
@@ -54,10 +54,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount {
54
54
match expr. kind {
55
55
hir:: ExprKind :: Match ( res, _, _) if is_try ( cx, expr) . is_some ( ) => {
56
56
if let hir:: ExprKind :: Call ( func, [ ref arg_0, ..] ) = res. kind {
57
- if matches ! (
58
- func. kind,
59
- hir:: ExprKind :: Path ( hir:: QPath :: LangItem ( hir:: LangItem :: TryTraitBranch , ..) )
60
- ) {
57
+ if is_path_lang_item ( cx, func, hir:: LangItem :: TryTraitBranch ) {
61
58
check_map_error ( cx, arg_0, expr) ;
62
59
}
63
60
} else {
@@ -77,13 +74,10 @@ impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount {
77
74
78
75
/// If `expr` is an (e).await, return the inner expression "e" that's being
79
76
/// waited on. Otherwise return None.
80
- fn try_remove_await < ' a > ( expr : & ' a hir:: Expr < ' a > ) -> Option < & hir:: Expr < ' a > > {
77
+ fn try_remove_await < ' a > ( cx : & LateContext < ' _ > , expr : & ' a hir:: Expr < ' a > ) -> Option < & ' a hir:: Expr < ' a > > {
81
78
if let hir:: ExprKind :: Match ( expr, _, hir:: MatchSource :: AwaitDesugar ) = expr. kind {
82
79
if let hir:: ExprKind :: Call ( func, [ ref arg_0, ..] ) = expr. kind {
83
- if matches ! (
84
- func. kind,
85
- hir:: ExprKind :: Path ( hir:: QPath :: LangItem ( hir:: LangItem :: IntoFutureIntoFuture , ..) )
86
- ) {
80
+ if is_path_lang_item ( cx, func, hir:: LangItem :: IntoFutureIntoFuture ) {
87
81
return Some ( arg_0) ;
88
82
}
89
83
}
@@ -102,7 +96,7 @@ fn check_map_error(cx: &LateContext<'_>, call: &hir::Expr<'_>, expr: &hir::Expr<
102
96
}
103
97
}
104
98
105
- if let Some ( call) = try_remove_await ( call) {
99
+ if let Some ( call) = try_remove_await ( cx , call) {
106
100
check_method_call ( cx, call, expr, true ) ;
107
101
} else {
108
102
check_method_call ( cx, call, expr, false ) ;
0 commit comments