@@ -219,15 +219,17 @@ fn check_possible_range_contains(cx: &LateContext<'_>, op: BinOpKind, l: &Expr<'
219219 _ => return ,
220220 } ;
221221 // value, name, order (higher/lower), inclusiveness
222- if let ( Some ( ( lval, lid, name_span, lval_span, lord, linc) ) , Some ( ( rval, rid, _, rval_span, rord, rinc) ) ) =
223- ( check_range_bounds ( cx, l) , check_range_bounds ( cx, r) )
222+ if let (
223+ Some ( ( lval, lexpr, lid, name_span, lval_span, lord, linc) ) ,
224+ Some ( ( rval, _, rid, _, rval_span, rord, rinc) ) ,
225+ ) = ( check_range_bounds ( cx, l) , check_range_bounds ( cx, r) )
224226 {
225227 // we only lint comparisons on the same name and with different
226228 // direction
227229 if lid != rid || lord == rord {
228230 return ;
229231 }
230- let ord = Constant :: partial_cmp ( cx. tcx , cx. typeck_results ( ) . expr_ty ( l ) , & lval, & rval) ;
232+ let ord = Constant :: partial_cmp ( cx. tcx , cx. typeck_results ( ) . expr_ty ( lexpr ) , & lval, & rval) ;
231233 if combine_and && ord == Some ( rord) {
232234 // order lower bound and upper bound
233235 let ( l_span, u_span, l_inc, u_inc) = if rord == Ordering :: Less {
@@ -292,7 +294,10 @@ fn check_possible_range_contains(cx: &LateContext<'_>, op: BinOpKind, l: &Expr<'
292294 }
293295}
294296
295- fn check_range_bounds ( cx : & LateContext < ' _ > , ex : & Expr < ' _ > ) -> Option < ( Constant , HirId , Span , Span , Ordering , bool ) > {
297+ fn check_range_bounds < ' a > (
298+ cx : & ' a LateContext < ' _ > ,
299+ ex : & ' a Expr < ' _ > ,
300+ ) -> Option < ( Constant , & ' a Expr < ' a > , HirId , Span , Span , Ordering , bool ) > {
296301 if let ExprKind :: Binary ( ref op, l, r) = ex. kind {
297302 let ( inclusive, ordering) = match op. node {
298303 BinOpKind :: Gt => ( false , Ordering :: Greater ) ,
@@ -303,11 +308,11 @@ fn check_range_bounds(cx: &LateContext<'_>, ex: &Expr<'_>) -> Option<(Constant,
303308 } ;
304309 if let Some ( id) = path_to_local ( l) {
305310 if let Some ( ( c, _) ) = constant ( cx, cx. typeck_results ( ) , r) {
306- return Some ( ( c, id, l. span , r. span , ordering, inclusive) ) ;
311+ return Some ( ( c, r , id, l. span , r. span , ordering, inclusive) ) ;
307312 }
308313 } else if let Some ( id) = path_to_local ( r) {
309314 if let Some ( ( c, _) ) = constant ( cx, cx. typeck_results ( ) , l) {
310- return Some ( ( c, id, r. span , l. span , ordering. reverse ( ) , inclusive) ) ;
315+ return Some ( ( c, l , id, r. span , l. span , ordering. reverse ( ) , inclusive) ) ;
311316 }
312317 }
313318 }
0 commit comments