-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
RangeInclusive cannot be used in const generics. #70155
Copy link
Copy link
Closed
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.F-const_generics`#![feature(const_generics)]``#![feature(const_generics)]`T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.F-const_generics`#![feature(const_generics)]``#![feature(const_generics)]`T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
All range types except
RangeInclusivecan be used in const generics:This compiles (on nightly), while the following does not:
This is because
RangeInclusivedoes not implementStructuralPartialEqandStructuralEq(#63438).RangeInclusivehas fieldsstartandendsimilar to the other range types, but also has an extra field:exhausted: bool(#68835). This was recently changed from a fieldis_empty: Option<bool>. This extra field tracks state for iteration and was added to address performance issues (#45222).The old implementation with
is_emptyhad semantic equality, however the new implementation withexhaustedhas structural equality:from range.rs
I believe this means we can either manually add implementations for
StructuralPartialEqandStructuralEq, or just derivePartialEqandEq, which will allowRangeInclusiveto also be used in const generics and remove the inconsistency with other range types.