rust-lang / rust-lang/rust-clippy
redudant_clone does not lint on async function calls
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Clippy produces a false negative on a redundant_clone when the redundant clone is passed to an async function call.
This is happening on both stable and nightly rust
I tried this code:
#[tokio::main]
async fn main() -> Result<(), &'static str> {
let x = String::from("abc");
foo_async(&x.clone()).await;
Ok(())
}
async fn foo_async(s: &str) {
println!("{}", s);
}
I expected to have Clippy inform me about having a redundant clone, with this warning (when using an async function call):
warning: redundant clone
--> src/main.rs:5:16
|
5 | foo_sync(&x.clone());
| ^^^^^^^^ help: remove this
|
= note: `#[warn(clippy::redundant_clone)]` on by default
note: cloned value is neither consumed nor mutated
--> src/main.rs:5:15
|
5 | foo_sync(&x.clone());
| ^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
warning: 1 warning emitted
When using an async function call, Clippy outputs no warnings despite evidently having a redundant clone
Finished dev [unoptimized + debuginfo] target(s) in 14.10s
I suspect that there is something finnicky going on with the lifetimes due to that .await, but what exactly I do not know.
Full code:
#[tokio::main]
async fn main() -> Result<(), &'static str> {
let x = String::from("abc");
foo_async(&x.clone()).await;
//foo_sync(&x.clone());
Ok(())
}
async fn foo_async(s: &str) {
println!("{}", s);
}
//fn foo_sync(s: &str) {
//println!("{}", s);
//}
Meta
clippy 0.0.212 (346aec9 2020-07-11)rustc -Vv:
rustc 1.46.0-nightly (346aec9b0 2020-07-11)
binary: rustc
commit-hash: 346aec9b02f3c74f3fce97fd6bda24709d220e49
commit-date: 2020-07-11
host: x86_64-unknown-linux-gnu
release: 1.46.0-nightly
LLVM version: 10.0
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 redundant_clone example with the async function call and compare it with the commented synchronous call. Trace the redundant_clone lint's handling of borrowed arguments across .await; done means Clippy reports the redundant clone for the async case without regressing the synchronous behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100