Infinite iterator consumed without a terminating adaptor
ID |
rust.correctness.infinite_iterators_finished_off_terminating |
Severity |
low |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Infinite Loop |
Language |
Rust |
Description
This chain starts from an endless iterator and then consumes it whole, so the call never returns and, for collect, grows the allocation until memory runs out. Bound the iterator with take, take_while, zip or a short-circuiting adaptor such as find or any.
Rationale
This chain starts from an endless iterator and then consumes it whole, so the call never returns and, for collect, grows the allocation until memory runs out. Bound the iterator with take, take_while, zip or a short-circuiting adaptor such as find or any.
The following code illustrates the pattern detected by this rule:
use std::iter::{repeat, repeat_with};
fn fill() -> Vec<u8> {
// FLAGGED: Infinite iterator consumed without a terminating adaptor
repeat(0u8).collect()
}