Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsized rvalues now making this lint inaccurate #3420

Open
earthengine opened this issue Nov 9, 2018 · 0 comments
Open

Unsized rvalues now making this lint inaccurate #3420

earthengine opened this issue Nov 9, 2018 · 0 comments

Comments

@earthengine
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant