@@ -78,7 +78,7 @@ use std::sync::OnceLock;
7878use std:: sync:: { Mutex , MutexGuard } ;
7979
8080use if_chain:: if_chain;
81- use rustc_ast:: ast:: { self , LitKind } ;
81+ use rustc_ast:: ast:: { self , LitKind , RangeLimits } ;
8282use rustc_ast:: Attribute ;
8383use rustc_data_structures:: fx:: FxHashMap ;
8484use rustc_data_structures:: unhash:: UnhashMap ;
@@ -115,6 +115,7 @@ use rustc_span::Span;
115115use rustc_target:: abi:: Integer ;
116116
117117use crate :: consts:: { constant, Constant } ;
118+ use crate :: higher:: Range ;
118119use crate :: ty:: { can_partially_move_ty, expr_sig, is_copy, is_recursively_primitive_type, ty_is_fn_once_param} ;
119120use crate :: visitors:: for_each_expr;
120121
@@ -1491,6 +1492,24 @@ pub fn is_else_clause(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool {
14911492 }
14921493}
14931494
1495+ /// Checks whether the given `Range` is equivalent to a `RangeFull`.
1496+ /// Inclusive ranges are not considered because they already constitute a lint.
1497+ pub fn is_range_full ( cx : & LateContext < ' _ > , container : & Expr < ' _ > , range : Range < ' _ > ) -> bool {
1498+ range. start . map_or ( true , |e| is_integer_const ( cx, e, 0 ) )
1499+ && range. end . map_or ( true , |e| {
1500+ if range. limits == RangeLimits :: HalfOpen
1501+ && let ExprKind :: Path ( QPath :: Resolved ( None , container_path) ) = container. kind
1502+ && let ExprKind :: MethodCall ( name, self_arg, [ ] , _) = e. kind
1503+ && name. ident . name == sym:: len
1504+ && let ExprKind :: Path ( QPath :: Resolved ( None , path) ) = self_arg. kind
1505+ {
1506+ container_path. res == path. res
1507+ } else {
1508+ false
1509+ }
1510+ } )
1511+ }
1512+
14941513/// Checks whether the given expression is a constant integer of the given value.
14951514/// unlike `is_integer_literal`, this version does const folding
14961515pub fn is_integer_const ( cx : & LateContext < ' _ > , e : & Expr < ' _ > , value : u128 ) -> bool {
0 commit comments