@@ -2,19 +2,18 @@ use clippy_utils::consts::{constant, Constant};
22use clippy_utils:: diagnostics:: { span_lint, span_lint_and_sugg, span_lint_and_then} ;
33use clippy_utils:: source:: { snippet, snippet_opt, snippet_with_applicability} ;
44use clippy_utils:: sugg:: Sugg ;
5- use clippy_utils:: { get_parent_expr, in_constant, is_integer_const, meets_msrv, msrvs, single_segment_path } ;
5+ use clippy_utils:: { get_parent_expr, in_constant, is_integer_const, meets_msrv, msrvs, path_to_local } ;
66use clippy_utils:: { higher, SpanlessEq } ;
77use if_chain:: if_chain;
88use rustc_ast:: ast:: RangeLimits ;
99use rustc_errors:: Applicability ;
10- use rustc_hir:: { BinOpKind , Expr , ExprKind , PathSegment , QPath } ;
10+ use rustc_hir:: { BinOpKind , Expr , ExprKind , HirId , PathSegment , QPath } ;
1111use rustc_lint:: { LateContext , LateLintPass } ;
1212use rustc_middle:: ty;
1313use rustc_semver:: RustcVersion ;
1414use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
1515use rustc_span:: source_map:: { Span , Spanned } ;
1616use rustc_span:: sym;
17- use rustc_span:: symbol:: Ident ;
1817use std:: cmp:: Ordering ;
1918
2019declare_clippy_lint ! {
@@ -220,12 +219,12 @@ fn check_possible_range_contains(cx: &LateContext<'_>, op: BinOpKind, l: &Expr<'
220219 _ => return ,
221220 } ;
222221 // value, name, order (higher/lower), inclusiveness
223- if let ( Some ( ( lval, lname , name_span, lval_span, lord, linc) ) , Some ( ( rval, rname , _, rval_span, rord, rinc) ) ) =
222+ if let ( Some ( ( lval, lid , name_span, lval_span, lord, linc) ) , Some ( ( rval, rid , _, rval_span, rord, rinc) ) ) =
224223 ( check_range_bounds ( cx, l) , check_range_bounds ( cx, r) )
225224 {
226225 // we only lint comparisons on the same name and with different
227226 // direction
228- if lname != rname || lord == rord {
227+ if lid != rid || lord == rord {
229228 return ;
230229 }
231230 let ord = Constant :: partial_cmp ( cx. tcx , cx. typeck_results ( ) . expr_ty ( l) , & lval, & rval) ;
@@ -293,7 +292,7 @@ fn check_possible_range_contains(cx: &LateContext<'_>, op: BinOpKind, l: &Expr<'
293292 }
294293}
295294
296- fn check_range_bounds ( cx : & LateContext < ' _ > , ex : & Expr < ' _ > ) -> Option < ( Constant , Ident , Span , Span , Ordering , bool ) > {
295+ fn check_range_bounds ( cx : & LateContext < ' _ > , ex : & Expr < ' _ > ) -> Option < ( Constant , HirId , Span , Span , Ordering , bool ) > {
297296 if let ExprKind :: Binary ( ref op, l, r) = ex. kind {
298297 let ( inclusive, ordering) = match op. node {
299298 BinOpKind :: Gt => ( false , Ordering :: Greater ) ,
@@ -302,11 +301,11 @@ fn check_range_bounds(cx: &LateContext<'_>, ex: &Expr<'_>) -> Option<(Constant,
302301 BinOpKind :: Le => ( true , Ordering :: Less ) ,
303302 _ => return None ,
304303 } ;
305- if let Some ( id) = match_ident ( l) {
304+ if let Some ( id) = path_to_local ( l) {
306305 if let Some ( ( c, _) ) = constant ( cx, cx. typeck_results ( ) , r) {
307306 return Some ( ( c, id, l. span , r. span , ordering, inclusive) ) ;
308307 }
309- } else if let Some ( id) = match_ident ( r) {
308+ } else if let Some ( id) = path_to_local ( r) {
310309 if let Some ( ( c, _) ) = constant ( cx, cx. typeck_results ( ) , l) {
311310 return Some ( ( c, id, r. span , l. span , ordering. reverse ( ) , inclusive) ) ;
312311 }
@@ -315,17 +314,6 @@ fn check_range_bounds(cx: &LateContext<'_>, ex: &Expr<'_>) -> Option<(Constant,
315314 None
316315}
317316
318- fn match_ident ( e : & Expr < ' _ > ) -> Option < Ident > {
319- if let ExprKind :: Path ( ref qpath) = e. kind {
320- if let Some ( seg) = single_segment_path ( qpath) {
321- if seg. args . is_none ( ) {
322- return Some ( seg. ident ) ;
323- }
324- }
325- }
326- None
327- }
328-
329317fn check_range_zip_with_len ( cx : & LateContext < ' _ > , path : & PathSegment < ' _ > , args : & [ Expr < ' _ > ] , span : Span ) {
330318 if_chain ! {
331319 if path. ident. as_str( ) == "zip" ;
0 commit comments