rust-lang / rust-lang/rust-clippy
Incorrect collect suggestion - underlying iterator doesn't meet constraints
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
I tried this code:
let iter = parser.map(move |contact| match contact {
Ok(c) => contact_to_value(c, tag.clone()),
Err(_) => Value::error(ShellError::labeled_error(
"Could not parse as .vcf",
"input cannot be parsed as .vcf",
tag.clone(),
)),
});
let collected: Vec<_> = iter.collect();
Ok(collected.into_iter().to_output_stream())
I expected to see this happen: clippy to notice that the underlying type for the original iterator is not compatible with the constraints for to_output_stream()
Instead, this happened: Clippy suggests replacing the collect and using the underlying iterator. This will not compile as the underlying iterator does not meet the constraints required for to_output_stream() which include constraints like Send+Sync, which the underlying iterator does not have.
Meta
cargo clippy -V: e.g. clippy 0.0.212 (f455e46 2020-06-20)rustc -Vv:
rustc 1.54.0-nightly (ed597e7e1 2021-06-08)
binary: rustc
commit-hash: ed597e7e19d0fe716d9f81b1e840a5abbfd7c28d
commit-date: 2021-06-08
host: x86_64-pc-windows-msvc
release: 1.54.0-nightly
LLVM version: 12.0.1
Backtrace
<backtrace>
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the report with the Rust snippet and the listed cargo clippy and rustc versions, then trace the lint that suggests replacing collect with the underlying iterator. No source file or test is named in the issue; completion means the suggestion is not emitted when the replacement iterator fails the constraints required by to_output_stream(), including Send and Sync.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100