Skip to content

Conversation

@fee1-dead
Copy link
Member

@fee1-dead fee1-dead commented Jan 18, 2026

Like its predecessors (#92433, #102225, #106541), this PR allows one to make Iterator implementations const, and thus enables the ability to have for loops in const contexts. I've also included constifying Option as IntoIterator, option::IntoIter as Iterator as a minimal dogfooding example.

But unlike its predecessors, it uses a new attribute (not unsound anymore!) that prevents any Iterator extension methods from being called. This is intentionally made minimal for an initial approval, the fun stuff like .fold, Range as Iterator could be done later.

cc @rust-lang/wg-const-eval, cc @oli-obk to review the compiler parts

cc #92476

@rustbot
Copy link
Collaborator

rustbot commented Jan 18, 2026

Some changes occurred in compiler/rustc_hir/src/attrs

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) 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. labels Jan 18, 2026
@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Jan 18, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 18, 2026

r? @scottmcm

rustbot has assigned @scottmcm.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@fmease fmease added the PG-const-traits Project group: Const traits label Jan 18, 2026
/// ```
#[inline]
#[unstable(feature = "iter_next_chunk", issue = "98326")]
#[rustc_non_const_trait_method]
Copy link
Member

Choose a reason for hiding this comment

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

Please also update the dev-guide docs to explain the attribute.

@rust-bors

This comment has been minimized.

rustc_non_const_trait_method, AttributeType::Normal, template!(Word),
ErrorFollowing, EncodeCrossCrate::No,
"`#[rustc_non_const_trait_method]` should only used by the standard library to mark trait methods \
as non-const to allow large traits to easier transition to const"
Copy link
Contributor

Choose a reason for hiding this comment

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

"traits an easier transition" or "traits to transition more easily"

@rustbot

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Jan 26, 2026

The rustc-dev-guide subtree was changed. If this PR only touches the dev guide consider submitting a PR directly to rust-lang/rustc-dev-guide otherwise thank you for updating the dev guide with your changes.

cc @BoxyUwU, @jieyouxu, @Kobzol, @tshepang

@rustbot rustbot added the A-rustc-dev-guide Area: rustc-dev-guide label Jan 26, 2026
@scottmcm

This comment was marked as resolved.

@rustbot rustbot assigned jieyouxu and unassigned scottmcm Jan 27, 2026
@jieyouxu

This comment was marked as off-topic.

@rustbot rustbot assigned madsmtm and unassigned jieyouxu Jan 27, 2026
@RalfJung
Copy link
Member

RalfJung commented Jan 27, 2026 via email

@rustbot rustbot assigned oli-obk and unassigned madsmtm Jan 27, 2026
@rustbot

This comment was marked as resolved.

Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

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

r=me with review commits absorbed

View changes since this review

@rust-bors

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Jan 30, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@fee1-dead
Copy link
Member Author

@bors r=oli-obk

@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 30, 2026

📌 Commit 02e10b2 has been approved by oli-obk

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 30, 2026
rust-bors bot pushed a commit that referenced this pull request Jan 30, 2026
…uwer

Rollup of 2 pull requests

Successful merges:

 - #151281 (constify `Iterator`, take IV)
 - #151873 (resolve: Remove `force` parameter from `resolve_ident_in_scope`)
@rust-bors rust-bors bot merged commit 58f03f5 into rust-lang:main Jan 31, 2026
11 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Jan 31, 2026
rust-timer added a commit that referenced this pull request Jan 31, 2026
Rollup merge of #151281 - fee1-dead-contrib:push-zmqtzvuvlmuk, r=oli-obk

constify `Iterator`, take IV

Like its predecessors (#92433, #102225, #106541), this PR allows one to make `Iterator` implementations `const`, and thus enables the ability to have `for` loops in `const` contexts. I've also included constifying `Option as IntoIterator`, `option::IntoIter as Iterator` as a minimal dogfooding example.

But unlike its predecessors, it uses a new attribute (not unsound anymore!) that prevents any `Iterator` extension methods from being called. This is intentionally made minimal for an initial approval, the fun stuff like `.fold`, `Range as Iterator` could be done later.

cc @rust-lang/wg-const-eval, cc @oli-obk to review the compiler parts

cc #92476
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Jan 31, 2026
…uwer

Rollup of 2 pull requests

Successful merges:

 - rust-lang/rust#151281 (constify `Iterator`, take IV)
 - rust-lang/rust#151873 (resolve: Remove `force` parameter from `resolve_ident_in_scope`)
@fee1-dead fee1-dead deleted the push-zmqtzvuvlmuk branch January 31, 2026 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-rustc-dev-guide Area: rustc-dev-guide PG-const-traits Project group: Const traits S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

10 participants