rust-lang / rust-lang/rust-clippy
Unsized rvalues now making this lint inaccurate
Open
Nobody has claimed this yet.
S-triage
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
The following code
#![feature(unsized_locals)]
fn a(f: Box<dyn FnOnce()>) {
f()
}
fn main() {
let f = || println!("Hello!");
a(Box::new(f))
}
is now allowed in nightly. However, Clippy gives inaccurate lint:
Checking playground v0.0.1 (/playground)
warning: this argument is passed by value, but not consumed in the function body
--> src/main.rs:2:9
|
2 | fn a(f: Box<dyn FnOnce()>) {
| ^^^^^^^^^^^^^^^^^ help: consider taking a reference instead: `&Box<dyn FnOnce()>`
|
= note: #[warn(clippy::needless_pass_by_value)] on by default
= help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#needless_pass_by_value
Finished dev [unoptimized + debuginfo] target(s) in 0.66s
Because when run the code above, it do consumes the variable f when using unsized rvalues, and it cannot run without it.
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 with Clippy's needless_pass_by_value lint and reproduce the provided unsized_locals example on nightly. The work is done when the lint no longer reports an inaccurate suggestion for the consumed boxed FnOnce value and the behavior is covered by an appropriate regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100