Skip to content

Commit 1c64452

Browse files
Rollup merge of #151281 - fee1-dead-contrib:push-zmqtzvuvlmuk, r=oli-obk
constify `Iterator`, take IV Like its predecessors (rust-lang/rust#92433, rust-lang/rust#102225, rust-lang/rust#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 rust-lang/rust#92476
2 parents 7dae1ce + 9893d23 commit 1c64452

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@
199199
- [Inference details](./opaque-types-impl-trait-inference.md)
200200
- [Return Position Impl Trait In Trait](./return-position-impl-trait-in-trait.md)
201201
- [Region inference restrictions](./borrow-check/opaque-types-region-inference-restrictions.md)
202-
- [Const condition checking](./effects.md)
202+
- [Const traits and const condition checking](./effects.md)
203203
- [Pattern and exhaustiveness checking](./pat-exhaustive-checking.md)
204204
- [Unsafety checking](./unsafety-checking.md)
205205
- [MIR dataflow](./mir/dataflow.md)

src/effects.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Effects and const condition checking
1+
# Effects, const traits, and const condition checking
22

33
## The `HostEffect` predicate
44

@@ -154,3 +154,18 @@ be dropped at compile time.
154154

155155
[old solver]: https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_trait_selection/traits/effects.rs.html
156156
[new trait solver]: https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_next_trait_solver/solve/effect_goals.rs.html
157+
158+
## More on const traits
159+
160+
To be expanded later.
161+
162+
### The `#[rustc_non_const_trait_method]` attribute
163+
164+
This is intended for internal (standard library) usage only. With this attribute
165+
applied to a trait method, the compiler will not check the default body of this
166+
method for ability to run in compile time. Users of the trait will also not be
167+
allowed to use this trait method in const contexts. This attribute is primarily
168+
used for constifying large traits such as `Iterator` without having to make all
169+
its methods `const` at the same time.
170+
171+
This attribute should not be present while stabilizing the trait as `const`.

0 commit comments

Comments
 (0)