Clippy lints / Pedantic
Clippy lint · Pedantic · checked with Clippy 0.1.99
clippy::copy_iterator: Checks for types that implement Copy as well as Iterator
What it meansChecks for types that implement Copy as well as Iterator. It is in the pedantic group and off by default.
Does it matter?
Implicit copies can be confusing when working with iterator combinators.
Stricter lints with some false positives. Off by default; opt in with clippy::pedantic.
How to fix it
Clippy does not fix this one automatically. Change the code by hand:
Flagged
#[derive(Copy, Clone)]
struct Countdown(u8);
impl Iterator for Countdown {
// ...
}
let a: Vec<_> = my_iterator.take(1).collect();
let b: Vec<_> = my_iterator.collect();
Turn it off, or on
It is off by default. To use it, set it to warn or deny:
Whole crate (Cargo.toml)
[lints.clippy]
copy_iterator = "warn"In code
#![warn(clippy::copy_iterator)]One run
cargo clippy -- -W clippy::copy-iteratorThe [lints] table needs Rust 1.74 or newer. In a workspace, put it under [workspace.lints.clippy] and add [lints] workspace = true to each member.
Clippy's own documentation
What it does
Checks for types that implement Copy as well as
Iterator.
Why is this bad?
Implicit copies can be confusing when working with iterator combinators.
Example
#[derive(Copy, Clone)]
struct Countdown(u8);
impl Iterator for Countdown {
// ...
}
let a: Vec<_> = my_iterator.take(1).collect();
let b: Vec<_> = my_iterator.collect();
From the Clippy lint list (0.1.99), part of the Rust project, MIT or Apache-2.0. Official entry.
Related lints
- too_many_linesChecks for functions with a large amount of lines
- missing_errors_docChecks the doc comments of publicly visible functions that return a Result type and warns if there is no # Errors section
- must_use_candidateChecks for public functions that have no #[must_use] attribute, but return something not already marked must-use, have no mutable arg and mutate no statics
- cloned_instead_of_copiedused `cloned` where `copied` could be used instead
- collapsible_else_ifChecks for collapsible else { if
- comparison_chainChecks comparison chains written with if that can be rewritten with match and cmp
- decimal_bitwise_operandsusing decimal literal for bitwise operation
- default_trait_accesscalling `String::default()` is more clear than this expression
- doc_broken_linkpossible broken doc link: broken across multiple lines
All 847 Clippy lints · Rust compiler errors · Cargo.toml checker
Up next
Related lintclippy::too_many_linesChecks for functions with a large amount of linesRead it next →Did this answer your question?