@@ -120,7 +120,6 @@ use source::{SpanExt, walk_span_to_context};
120120use visitors:: { Visitable , for_each_unconsumed_temporary} ;
121121
122122use crate :: ast_utils:: unordered_over;
123- use crate :: consts:: ConstEvalCtxt ;
124123use crate :: higher:: Range ;
125124use crate :: msrvs:: Msrv ;
126125use crate :: res:: { MaybeDef , MaybeQPath , MaybeResPath } ;
@@ -1330,59 +1329,23 @@ pub fn is_else_clause_in_let_else(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool {
13301329 } )
13311330}
13321331
1333- /// Checks whether the given `Expr` is a range equivalent to a `RangeFull`.
1334- ///
1335- /// For the lower bound, this means that:
1336- /// - either there is none
1337- /// - or it is the smallest value that can be represented by the range's integer type
1338- ///
1339- /// For the upper bound, this means that:
1340- /// - either there is none
1341- /// - or it is the largest value that can be represented by the range's integer type and is
1342- /// inclusive
1343- /// - or it is a call to some container's `len` method and is exclusive, and the range is passed to
1344- /// a method call on that same container (e.g. `v.drain(..v.len())`)
1345- ///
1346- /// If the given `Expr` is not some kind of range, the function returns `false`.
1347- pub fn is_range_full ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > , container_path : Option < & Path < ' _ > > ) -> bool {
1348- let ty = cx. typeck_results ( ) . expr_ty ( expr) ;
1332+ /// Checks whether the given `Expr` is a range over the entire container.
1333+ pub fn is_full_collection_range ( cx : & LateContext < ' _ > , container : Option < HirId > , expr : & Expr < ' _ > ) -> bool {
13491334 if let Some ( Range { start, end, limits, .. } ) = Range :: hir ( cx, expr) {
1350- let start_is_none_or_min = start. is_none_or ( |start| {
1351- if let rustc_ty:: Adt ( _, subst) = ty. kind ( )
1352- && let bnd_ty = subst. type_at ( 0 )
1353- && let Some ( start_const) = ConstEvalCtxt :: new ( cx) . eval ( start)
1354- {
1355- start_const. is_numeric_min ( cx. tcx , bnd_ty)
1356- } else {
1357- false
1358- }
1359- } ) ;
1360- let end_is_none_or_max = end. is_none_or ( |end| match limits {
1361- RangeLimits :: Closed => {
1362- if let rustc_ty:: Adt ( _, subst) = ty. kind ( )
1363- && let bnd_ty = subst. type_at ( 0 )
1364- && let Some ( end_const) = ConstEvalCtxt :: new ( cx) . eval ( end)
1335+ start. is_none_or ( |start| is_integer_literal ( start, 0 ) )
1336+ && end. is_none_or ( |end| {
1337+ if limits == RangeLimits :: HalfOpen
1338+ && let Some ( container) = container
1339+ && let ExprKind :: MethodCall ( seg, recv, [ ] , _) = end. kind
13651340 {
1366- end_const . is_numeric_max ( cx . tcx , bnd_ty )
1341+ seg . ident . name == sym :: len && recv . res_local_id ( ) == Some ( container )
13671342 } else {
13681343 false
13691344 }
1370- } ,
1371- RangeLimits :: HalfOpen => {
1372- if let Some ( container_path) = container_path
1373- && let ExprKind :: MethodCall ( name, self_arg, [ ] , _) = end. kind
1374- && name. ident . name == sym:: len
1375- && let ExprKind :: Path ( QPath :: Resolved ( None , path) ) = self_arg. kind
1376- {
1377- container_path. res == path. res
1378- } else {
1379- false
1380- }
1381- } ,
1382- } ) ;
1383- return start_is_none_or_min && end_is_none_or_max;
1345+ } )
1346+ } else {
1347+ false
13841348 }
1385- false
13861349}
13871350
13881351/// Checks whether the given expression is a constant literal of the given value.
0 commit comments