11use clippy_utils:: { diagnostics:: span_lint_and_then, match_def_path, paths, source:: snippet} ;
22use rustc_errors:: Applicability ;
3- use rustc_hir:: * ;
3+ use rustc_hir:: { Expr , ExprKind , PatKind , Stmt , StmtKind , UnOp } ;
44use rustc_lint:: LateContext ;
55use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
66use rustc_span:: { symbol:: Ident , Span } ;
@@ -36,13 +36,7 @@ declare_clippy_lint! {
3636}
3737declare_lint_pass ! ( WhilePopUnwrap => [ WHILE_POP_UNWRAP ] ) ;
3838
39- fn report_lint < ' tcx > (
40- cx : & LateContext < ' tcx > ,
41- pop_span : Span ,
42- ident : Option < Ident > ,
43- loop_span : Span ,
44- receiver_span : Span ,
45- ) {
39+ fn report_lint ( cx : & LateContext < ' _ > , pop_span : Span , ident : Option < Ident > , loop_span : Span , receiver_span : Span ) {
4640 span_lint_and_then (
4741 cx,
4842 WHILE_POP_UNWRAP ,
@@ -54,7 +48,7 @@ fn report_lint<'tcx>(
5448 "try" ,
5549 format ! (
5650 "while let Some({}) = {}.pop()" ,
57- ident. as_ref( ) . map ( Ident :: as_str) . unwrap_or ( "element" ) ,
51+ ident. as_ref( ) . map_or ( "element" , Ident :: as_str) ,
5852 snippet( cx, receiver_span, ".." )
5953 ) ,
6054 Applicability :: MaybeIncorrect ,
@@ -75,11 +69,11 @@ fn match_method_call(cx: &LateContext<'_>, expr: &Expr<'_>, method: &[&str]) ->
7569 }
7670}
7771
78- fn is_vec_pop < ' tcx > ( cx : & LateContext < ' tcx > , expr : & Expr < ' _ > ) -> bool {
72+ fn is_vec_pop ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) -> bool {
7973 match_method_call ( cx, expr, & paths:: VEC_POP )
8074}
8175
82- fn is_vec_pop_unwrap < ' tcx > ( cx : & LateContext < ' tcx > , expr : & Expr < ' _ > ) -> bool {
76+ fn is_vec_pop_unwrap ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) -> bool {
8377 if let ExprKind :: MethodCall ( _, inner, ..) = expr. kind
8478 && ( match_method_call ( cx, expr, & paths:: OPTION_UNWRAP ) || match_method_call ( cx, expr, & paths:: OPTION_EXPECT ) )
8579 && is_vec_pop ( cx, inner)
@@ -90,7 +84,7 @@ fn is_vec_pop_unwrap<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> bool {
9084 }
9185}
9286
93- fn check_local < ' tcx > ( cx : & LateContext < ' tcx > , stmt : & Stmt < ' _ > , loop_span : Span , recv_span : Span ) {
87+ fn check_local ( cx : & LateContext < ' _ > , stmt : & Stmt < ' _ > , loop_span : Span , recv_span : Span ) {
9488 if let StmtKind :: Local ( local) = stmt. kind
9589 && let PatKind :: Binding ( .., ident, _) = local. pat . kind
9690 && let Some ( init) = local. init
@@ -101,10 +95,12 @@ fn check_local<'tcx>(cx: &LateContext<'tcx>, stmt: &Stmt<'_>, loop_span: Span, r
10195 }
10296}
10397
104- fn check_call_arguments < ' tcx > ( cx : & LateContext < ' tcx > , stmt : & Stmt < ' _ > , loop_span : Span , recv_span : Span ) {
98+ fn check_call_arguments ( cx : & LateContext < ' _ > , stmt : & Stmt < ' _ > , loop_span : Span , recv_span : Span ) {
10599 if let StmtKind :: Semi ( expr) | StmtKind :: Expr ( expr) = stmt. kind {
106100 if let ExprKind :: MethodCall ( _, _, args, _) | ExprKind :: Call ( _, args) = expr. kind {
107- let offending_arg = args. iter ( ) . find_map ( |arg| is_vec_pop_unwrap ( cx, arg) . then ( || arg. span ) ) ;
101+ let offending_arg = args
102+ . iter ( )
103+ . find_map ( |arg| is_vec_pop_unwrap ( cx, arg) . then_some ( arg. span ) ) ;
108104
109105 if let Some ( offending_arg) = offending_arg {
110106 report_lint ( cx, offending_arg, None , loop_span, recv_span) ;
0 commit comments