Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint for Iterator + Copy #1534

Open
sinkuu opened this issue Feb 13, 2017 · 1 comment
Open

Lint for Iterator + Copy #1534

sinkuu opened this issue Feb 13, 2017 · 1 comment
Labels
A-lint Area: New lints E-medium Call for participation: Medium difficulty level problem and requires some initial experience. good-first-issue These issues are a good way to get started with Clippy L-correctness Lint: Belongs in the correctness lint group

Comments

@sinkuu
Copy link
Contributor

sinkuu commented Feb 13, 2017

Implementing Copy for iterators makes footguns, and the standard library settled not to do so for now.

let mut it = /* a Copy + Iterator */;
for x in it { if cond { break; } } // `it` copied here (forgot to `&mut it`)
let x = it.next(); // `it` is in the initial state

Clippy should have a lint that warns if "use of the original iterator after copied" is detected.

@oli-obk oli-obk added L-correctness Lint: Belongs in the correctness lint group good-first-issue These issues are a good way to get started with Clippy E-medium Call for participation: Medium difficulty level problem and requires some initial experience. A-lint Area: New lints labels Feb 13, 2017
@oli-obk
Copy link
Contributor

oli-obk commented Feb 13, 2017

The E-easy part of this is a lint triggering on any type that implements Iterator and Copy at the same time. The E-medium part is a lint triggering only on the duplicate use.

niklasf added a commit to niklasf/rust-clippy that referenced this issue Jul 17, 2018
niklasf added a commit to niklasf/rust-clippy that referenced this issue Aug 24, 2018
flip1995 added a commit that referenced this issue Aug 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints E-medium Call for participation: Medium difficulty level problem and requires some initial experience. good-first-issue These issues are a good way to get started with Clippy L-correctness Lint: Belongs in the correctness lint group
Projects
None yet
Development

No branches or pull requests

4 participants