rust-lang / rust-lang/rust-clippy
Incorrect collect suggestion - borrow doesn't live long enough
Open
Nobody has claimed this yet.
C-bug
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
I tried this code:
let string_clone: Vec<_> = concat_string.item.lines().map(|x| x.to_string()).collect();
if objects {
Ok(string_clone
.into_iter()...
Clippy suggests turning this into:
Ok(concat_string.item.lines().map(|x| x.to_string())...
I expected to see this happen: clippy to suggest a correct replacement
Instead, this happened: clippy suggests the above, which will not compile as concat_string.item will not live long enough.
Meta
cargo clippy -V: e.g. clippy 0.0.212 (f455e46 2020-06-20)rustc -Vv:
C:\Source\nushell(main)> cargo clippy -V
clippy 0.1.54 (ed597e7e 2021-06-08)
C:\Source\nushell(main)> 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
Start by reproducing the reported snippet with cargo clippy and identify which lint emits the collect suggestion. Trace that lint's suggestion logic, then add a regression case showing that the suggested replacement compiles and preserves the intended lifetime behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100