`Cycle::size_hint` is wrong
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
Read library/core/src/iter/adapters/cycle.rs, especially the size_hint implementation linked in the issue, and compare its branches with the Custom iterator example. Check the relevant iterator adapter tests and add coverage for clones whose reported size hints differ. Done means Cycle::size_hint is correct for every iterator allowed by the Iterator contract.
索引モデルが issue の本文から書いたものです。
説明
Similar to #90085
Cycle::size_hint is implemented as
https://github.com/rust-lang/rust/blob/6c587fd5a7f62ceb4fda4e19f0af26d2f9521ae6/library/core/src/iter/adapters/cycle.rs#L47-L52
Note that orig is a clone of inner in inner.cycle(), i.e. not the original.
Every branch except the middle one is incorrect, i.e. the only possible correct size_hint is (0, None).
struct Custom(Option<i32>, fn() -> Self);
impl Iterator for Custom {
type Item = i32;
fn next(&mut self) -> Option<Self::Item> {
self.0.take()
}
fn size_hint(&self) -> (usize, Option<usize>) {
self.0.iter().size_hint() // trivially correct
}
}
impl Clone for Custom {
fn clone(&self) -> Self {
self.1()
}
}
fn main() {
const EMPTY: Custom = Custom(None, || EMPTY);
let fake_empty = Custom(Some(1), || EMPTY).cycle();
dbg!(fake_empty.size_hint(), fake_empty.count()); // (0, Some(0)), 1
let fake_infinite = Custom(None, || Custom(Some(0), || EMPTY)).cycle();
dbg!(fake_infinite.size_hint(), fake_infinite.count()); // (usize::MAX, None), 0
}
In reality, an iterator that behaves like Custom here could conceivably happen if there is some iterator that depends on external state not preserved by Clone, e.g. a channel, with some cached items that do not get cloned, but are reported in size_hint.
Either way, Custom does not violate any part of the Iterator contract, but Cycle<Custom> does.
- 主要言語
- Rust
- スター
- 122k
- フォーク
- 16.7k
- 平均マージ
- 2日 16時間
- マージ済み PR(30日)
- 515
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
rust-lang/rust のほかの issue
-
Remove unnecessary parentheses when suggesting to remove '&' from a pattern対応中かも @BartSimpson001 が 1 日前に担当しました。 オープンA-diagnostics D-invalid-suggestion T-compiler
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
Windows `File::set_permissions` silently does nothing when clearing `readonly` leaves `FileAttributes == 0`対応中かも @ChrisDenton が 11 日前に担当しました。 オープンA-filesystem C-bug O-windows T-libs
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
A-run-make relnotes relnotes-needs-review relnotes-tracking-issue T-lang T-libs
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
A-LLVM O-Arm O-UEFI O-x86_64 relnotes relnotes-needs-review relnotes-tracking-issue T-compiler
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
rust-lang/rust#165504 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
relnotes relnotes-tracking-issue T-libs
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
antithesishq/bombadil#473 ·
メンテナーはふだん 2 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
libracoder/kiri#669 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
メンテナーはふだん 5 日以内に返信
-
autofixer: follow-up
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
tursodatabase/turso#12217 ·
メンテナーはふだん 1 日以内に返信
-
Declare the CMS schema library in the optional recipients extra対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンarea:python in-progress
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
yhay81/pyropdf#1005 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信