Skip to content

Commit 1d49486

Browse files
committed
refactor(core): replace MyIterator with standard Iterator
[rust-lang/rust#106541][1] added `#[const_trait]` to `Iterator` as well as internal attribute to bypass the constness check for other methods than `Iterator::next`. As a result, user code can now implement `const Iterator` in a normal way, i.e., just by implementing `Iterator::next`. [1]: rust-lang/rust#106541
1 parent 8b64feb commit 1d49486

File tree

2 files changed

+5
-33
lines changed

2 files changed

+5
-33
lines changed

doc/toolchain_limitations.md

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ type Alias<T> = Struct<{<T as Trait>::N}>;
106106

107107
### `[tag:const_for]` `for` loops are unusable in `const fn`
108108

109-
Technically it's available under the compiler feature `const_for`, but the lack of essential trait implementations (e.g., `[ref:range_const_iterator]`, `[ref:const_slice_iter]`) and above all the inability of implementing `const Iterator` (`[ref:iterator_const_default]`) make it unusable.
109+
Technically it's available under the compiler feature `const_for`, but the lack of essential trait implementations (e.g., `[ref:range_const_iterator]`, `[ref:const_slice_iter]`) makes it unusable in many cases.
110110

111111

112112
### `[tag:const_static_item_ref]` `const`s and `const fn`s can't refer to `static`s
@@ -449,25 +449,6 @@ const _: () = assert!(matches!((2..4).next(), Some(2)));
449449
```
450450

451451

452-
### `[tag:iterator_const_default]` `Iterator` lack `#[const_trait]`
453-
454-
```rust,compile_fail
455-
#![feature(const_trait_impl)]
456-
#![feature(const_mut_refs)]
457-
458-
struct MyIterator;
459-
460-
// error: const `impl` for trait `Iterator` which is not marked with `#[const_trait]`
461-
impl const Iterator for MyIterator {
462-
type Item = u32;
463-
464-
fn next(&mut self) -> Option<Self::Item> {
465-
Some(42)
466-
}
467-
}
468-
```
469-
470-
471452
### `[tag:const_assert_eq]` `assert_eq!` and similar macros are unusable in `const fn`
472453

473454
```rust,compile_fail,E0015

src/r3_core/src/bind/sorter.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ pub(super) const fn sort_bindings<Callback, SorterUseInfoList, VertexList>(
318318
End,
319319
}
320320

321-
impl const MyIterator for VertexIter<'_> {
321+
impl const Iterator for VertexIter<'_> {
322322
type Item = Vertex;
323323

324324
fn next(&mut self) -> Option<Self::Item> {
@@ -369,7 +369,7 @@ pub(super) const fn sort_bindings<Callback, SorterUseInfoList, VertexList>(
369369
End,
370370
}
371371

372-
impl<Callback> const MyIterator for SuccessorIter<'_, Callback>
372+
impl<Callback> const Iterator for SuccessorIter<'_, Callback>
373373
where
374374
Callback: ~const SorterCallback,
375375
{
@@ -533,23 +533,14 @@ pub(super) const fn sort_bindings<Callback, SorterUseInfoList, VertexList>(
533533
// Helper traits
534534
// --------------------------------------------------------------------------
535535

536-
// `const Iterator` is currently very hard to implement
537-
// [ref:iterator_const_default]
538-
/// An [`Iterator`][] usable in `const fn`.
539-
#[const_trait]
540-
trait MyIterator {
541-
type Item;
542-
fn next(&mut self) -> Option<Self::Item>;
543-
}
544-
545536
#[const_trait]
546537
trait GraphAccess<VertexRef> {
547-
type VertexIter<'a>: ~const MyIterator<Item = VertexRef> + ~const Destruct + 'a
538+
type VertexIter<'a>: ~const Iterator<Item = VertexRef> + ~const Destruct + 'a
548539
where
549540
Self: 'a;
550541
fn vertices(&self) -> Self::VertexIter<'_>;
551542

552-
type SuccessorIter<'a>: ~const MyIterator<Item = VertexRef> + ~const Destruct + 'a
543+
type SuccessorIter<'a>: ~const Iterator<Item = VertexRef> + ~const Destruct + 'a
553544
where
554545
Self: 'a;
555546
fn successors(&self, v: &VertexRef) -> Self::SuccessorIter<'_>;

0 commit comments

Comments
 (0)