@@ -10,8 +10,6 @@ use rustc_lint::{LateContext, LateLintPass};
10
10
use rustc_middle:: hir:: map:: Map ;
11
11
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
12
12
13
- use std:: marker:: PhantomData ;
14
-
15
13
declare_clippy_lint ! {
16
14
/// **What it does:**
17
15
/// Lints usage of `if let Some(v) = ... { y } else { x }` which is more
@@ -88,19 +86,17 @@ struct OptionIfLetElseOccurence {
88
86
wrap_braces : bool ,
89
87
}
90
88
91
- struct ReturnBreakContinueVisitor < ' tcx > {
89
+ struct ReturnBreakContinueMacroVisitor {
92
90
seen_return_break_continue : bool ,
93
- phantom_data : PhantomData < & ' tcx bool > ,
94
91
}
95
- impl < ' tcx > ReturnBreakContinueVisitor < ' tcx > {
96
- fn new ( ) -> ReturnBreakContinueVisitor < ' tcx > {
97
- ReturnBreakContinueVisitor {
92
+ impl ReturnBreakContinueMacroVisitor {
93
+ fn new ( ) -> ReturnBreakContinueMacroVisitor {
94
+ ReturnBreakContinueMacroVisitor {
98
95
seen_return_break_continue : false ,
99
- phantom_data : PhantomData ,
100
96
}
101
97
}
102
98
}
103
- impl < ' tcx > Visitor < ' tcx > for ReturnBreakContinueVisitor < ' tcx > {
99
+ impl < ' tcx > Visitor < ' tcx > for ReturnBreakContinueMacroVisitor {
104
100
type Map = Map < ' tcx > ;
105
101
fn nested_visit_map ( & mut self ) -> NestedVisitorMap < Self :: Map > {
106
102
NestedVisitorMap :: None
@@ -119,14 +115,18 @@ impl<'tcx> Visitor<'tcx> for ReturnBreakContinueVisitor<'tcx> {
119
115
// desugaring, as this will detect a break if there's a while loop
120
116
// or a for loop inside the expression.
121
117
_ => {
122
- rustc_hir:: intravisit:: walk_expr ( self , ex) ;
118
+ if utils:: in_macro ( ex. span ) {
119
+ self . seen_return_break_continue = true ;
120
+ } else {
121
+ rustc_hir:: intravisit:: walk_expr ( self , ex) ;
122
+ }
123
123
} ,
124
124
}
125
125
}
126
126
}
127
127
128
- fn contains_return_break_continue < ' tcx > ( expression : & ' tcx Expr < ' tcx > ) -> bool {
129
- let mut recursive_visitor: ReturnBreakContinueVisitor < ' tcx > = ReturnBreakContinueVisitor :: new ( ) ;
128
+ fn contains_return_break_continue_macro ( expression : & Expr < ' _ > ) -> bool {
129
+ let mut recursive_visitor = ReturnBreakContinueMacroVisitor :: new ( ) ;
130
130
recursive_visitor. visit_expr ( expression) ;
131
131
recursive_visitor. seen_return_break_continue
132
132
}
@@ -205,8 +205,8 @@ fn detect_option_if_let_else<'a>(cx: &LateContext<'_, 'a>, expr: &'a Expr<'a>) -
205
205
if let PatKind :: TupleStruct ( struct_qpath, & [ inner_pat] , _) = & arms[ 0 ] . pat. kind;
206
206
if utils:: match_qpath( struct_qpath, & paths:: OPTION_SOME ) ;
207
207
if let PatKind :: Binding ( bind_annotation, _, id, _) = & inner_pat. kind;
208
- if !contains_return_break_continue ( arms[ 0 ] . body) ;
209
- if !contains_return_break_continue ( arms[ 1 ] . body) ;
208
+ if !contains_return_break_continue_macro ( arms[ 0 ] . body) ;
209
+ if !contains_return_break_continue_macro ( arms[ 1 ] . body) ;
210
210
then {
211
211
let capture_mut = if bind_annotation == & BindingAnnotation :: Mutable { "mut " } else { "" } ;
212
212
let some_body = extract_body_from_arm( & arms[ 0 ] ) ?;
0 commit comments