`Cycle::size_hint` is wrong
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 54/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Rust
- Estrellas
- 122k
- Forks
- 16.7k
- Merge medio
- 2 d 16 h
- PR fusionados (30 d)
- 515
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de rust-lang/rust
-
Remove unnecessary parentheses when suggesting to remove '&' from a patternPosiblemente ocupada @BartSimpson001 la tomó hace 1 día. AbiertoA-diagnostics D-invalid-suggestion T-compiler
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
Windows `File::set_permissions` silently does nothing when clearing `readonly` leaves `FileAttributes == 0`Posiblemente ocupada @ChrisDenton la tomó hace 11 días. AbiertoA-filesystem C-bug O-windows T-libs
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
A-run-make relnotes relnotes-needs-review relnotes-tracking-issue T-lang T-libs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
A-LLVM O-Arm O-UEFI O-x86_64 relnotes relnotes-needs-review relnotes-tracking-issue T-compiler
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
rust-lang/rust#165504 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
relnotes relnotes-tracking-issue T-libs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
Todos los issues de rust-lang/rust
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
antithesishq/bombadil#473 ·
Los mantenedores suelen responder en 2 días
-
bench/api.sh exec test fails with curl exit 52, and --ignore-failure still records the timingsAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
libracoder/kiri#669 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
Los mantenedores suelen responder en 5 días
-
autofixer: follow-up
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
tursodatabase/turso#12217 ·
Los mantenedores suelen responder en 1 día
-
Declare the CMS schema library in the optional recipients extraPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertoarea:python in-progress
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
yhay81/pyropdf#1005 · 2 comentarios ·
Los mantenedores suelen responder en 1 día