@@ -78,7 +78,7 @@ use std::sync::OnceLock;
78
78
use std:: sync:: { Mutex , MutexGuard } ;
79
79
80
80
use if_chain:: if_chain;
81
- use rustc_ast:: ast:: { self , LitKind } ;
81
+ use rustc_ast:: ast:: { self , LitKind , RangeLimits } ;
82
82
use rustc_ast:: Attribute ;
83
83
use rustc_data_structures:: fx:: FxHashMap ;
84
84
use rustc_data_structures:: unhash:: UnhashMap ;
@@ -115,6 +115,7 @@ use rustc_span::Span;
115
115
use rustc_target:: abi:: Integer ;
116
116
117
117
use crate :: consts:: { constant, Constant } ;
118
+ use crate :: higher:: Range ;
118
119
use crate :: ty:: { can_partially_move_ty, expr_sig, is_copy, is_recursively_primitive_type, ty_is_fn_once_param} ;
119
120
use crate :: visitors:: for_each_expr;
120
121
@@ -1491,6 +1492,24 @@ pub fn is_else_clause(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool {
1491
1492
}
1492
1493
}
1493
1494
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
+
1494
1513
/// Checks whether the given expression is a constant integer of the given value.
1495
1514
/// unlike `is_integer_literal`, this version does const folding
1496
1515
pub fn is_integer_const ( cx : & LateContext < ' _ > , e : & Expr < ' _ > , value : u128 ) -> bool {
0 commit comments