Skip to content

implement const Iterator for Range#156216

Open
Randl wants to merge 4 commits intorust-lang:mainfrom
Randl:const-for-impl
Open

implement const Iterator for Range#156216
Randl wants to merge 4 commits intorust-lang:mainfrom
Randl:const-for-impl

Conversation

@Randl
Copy link
Copy Markdown
Contributor

@Randl Randl commented May 6, 2026

This allows the use of for i in i..n in const.

This I believe is interesting enough to be justified under #155816

r? @oli-obk

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 6, 2026
@Randl
Copy link
Copy Markdown
Contributor Author

Randl commented May 6, 2026

Another issue I noticed is that while is const-stable, but for isn't. So in some places, reverting the const-hack would make currently const-stable functions const-unstable. Alternatively, we wait until Iterator is const-stable.

@rust-log-analyzer

This comment has been minimized.

@Randl Randl force-pushed the const-for-impl branch from d4ee14e to 6115579 Compare May 6, 2026 02:08
@theemathas
Copy link
Copy Markdown
Contributor

Does this run into #148200 for types that implement non-const TrustedStep but implements const Step?

@rust-log-analyzer

This comment has been minimized.

@Randl Randl force-pushed the const-for-impl branch from 6115579 to 58f0c19 Compare May 6, 2026 04:23
@Randl
Copy link
Copy Markdown
Contributor Author

Randl commented May 6, 2026

@theemathas
Can you give maybe an example you had in mind? I'm not sure I can think of one. If I understand correctly, there won't be any non-const functions involved in this case, since the entire implementation will be in the const Step?

@theemathas
Copy link
Copy Markdown
Contributor

Maybe there's actually not a problem with specialization here? I suppose it's kind of fine to call a function that requires const TrustedStep even though the type only actually implements TrustedStep + const Step, since TrustedStep itself doesn't have any methods.

Comment thread library/core/src/tuple.rs Outdated
@Randl Randl force-pushed the const-for-impl branch from 58f0c19 to ccbb26c Compare May 6, 2026 08:18
#[stable(feature = "rust1", since = "1.0.0")]
impl<A: Step> DoubleEndedIterator for ops::Range<A> {
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
impl<A: [const] Step + [const] Destruct> const DoubleEndedIterator for ops::Range<A> {
Copy link
Copy Markdown
Contributor

@oli-obk oli-obk May 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change needed for the MVP? should at least be a separate commit unless the rest of this commit requires it

View changes since the review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants