Skip to content

Unsized rvalues now making this lint inaccurate #3420

@earthengine

Description

@earthengine

The following code

#![feature(unsized_locals)]
fn a(f: Box<dyn FnOnce()>) {
    f()
}

fn main() {
    let f = || println!("Hello!");
    a(Box::new(f))
}

Playground

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    S-triageStatus: PR was triaged and is waiting for an action from a maintainer (closing/moving/... the PR)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions