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