@@ -10,8 +10,6 @@ use rustc_lint::{LateContext, LateLintPass};
1010use rustc_middle:: hir:: map:: Map ;
1111use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
1212
13- use std:: marker:: PhantomData ;
14-
1513declare_clippy_lint ! {
1614 /// **What it does:**
1715 /// Lints usage of `if let Some(v) = ... { y } else { x }` which is more
@@ -88,19 +86,17 @@ struct OptionIfLetElseOccurence {
8886 wrap_braces : bool ,
8987}
9088
91- struct ReturnBreakContinueVisitor < ' tcx > {
89+ struct ReturnBreakContinueMacroVisitor {
9290 seen_return_break_continue : bool ,
93- phantom_data : PhantomData < & ' tcx bool > ,
9491}
95- impl < ' tcx > ReturnBreakContinueVisitor < ' tcx > {
96- fn new ( ) -> ReturnBreakContinueVisitor < ' tcx > {
97- ReturnBreakContinueVisitor {
92+ impl ReturnBreakContinueMacroVisitor {
93+ fn new ( ) -> ReturnBreakContinueMacroVisitor {
94+ ReturnBreakContinueMacroVisitor {
9895 seen_return_break_continue : false ,
99- phantom_data : PhantomData ,
10096 }
10197 }
10298}
103- impl < ' tcx > Visitor < ' tcx > for ReturnBreakContinueVisitor < ' tcx > {
99+ impl < ' tcx > Visitor < ' tcx > for ReturnBreakContinueMacroVisitor {
104100 type Map = Map < ' tcx > ;
105101 fn nested_visit_map ( & mut self ) -> NestedVisitorMap < Self :: Map > {
106102 NestedVisitorMap :: None
@@ -119,14 +115,18 @@ impl<'tcx> Visitor<'tcx> for ReturnBreakContinueVisitor<'tcx> {
119115 // desugaring, as this will detect a break if there's a while loop
120116 // or a for loop inside the expression.
121117 _ => {
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+ }
123123 } ,
124124 }
125125 }
126126}
127127
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 ( ) ;
130130 recursive_visitor. visit_expr ( expression) ;
131131 recursive_visitor. seen_return_break_continue
132132}
@@ -205,8 +205,8 @@ fn detect_option_if_let_else<'a>(cx: &LateContext<'_, 'a>, expr: &'a Expr<'a>) -
205205 if let PatKind :: TupleStruct ( struct_qpath, & [ inner_pat] , _) = & arms[ 0 ] . pat. kind;
206206 if utils:: match_qpath( struct_qpath, & paths:: OPTION_SOME ) ;
207207 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) ;
210210 then {
211211 let capture_mut = if bind_annotation == & BindingAnnotation :: Mutable { "mut " } else { "" } ;
212212 let some_body = extract_body_from_arm( & arms[ 0 ] ) ?;
0 commit comments