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

Redundant closure lint recommends incorrect code #10378

Closed
iajoiner opened this issue Feb 19, 2023 · 7 comments
Closed

Redundant closure lint recommends incorrect code #10378

iajoiner opened this issue Feb 19, 2023 · 7 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@iajoiner
Copy link

iajoiner commented Feb 19, 2023

Summary

This is probably a variant of #3071 or #7435. This error is probably dependent on PyO3 which is why I have filed an issue there as well as PyO3/pyo3#2988.

The reason why it is necessary to file an issue here is that the suggestion doesn't actually fix the issue. In fact the same issue exists after refactoring the code according to the suggestion. The next suggestion is for us to directly use Vec::new as a function which causes an error.

Lint Name

redundant-closure

Reproducer

I tried this code:

use pyo3::prelude::*;

#[pyfunction]
#[pyo3(signature = (
    _data = vec![],
))]
pub fn foo(
    _data: Vec<i32>,
) {
}

I saw this happen:

Checking pycatch v0.1.0 (/home/iajoiner/Documents/tests/pycatch)
warning: redundant closure
 --> src/main.rs:5:13
  |
5 |       _data = vec![],
  |  _____________^
6 | | ))]
7 | | pub fn foo(
8 | |     _data: Vec<i32>,
  | |___________________^ help: replace the closure with `Vec::new`: `std::vec::Vec::new`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure
  = note: `#[warn(clippy::redundant_closure)]` on by default

warning: `pycatch` (bin "pycatch") generated 1 warning (run `cargo clippy --fix --bin "pycatch"` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 0.05s

I expected to see this happen:

Version

rustc 1.67.1 (d5a82bbd2 2023-02-07)
binary: rustc
commit-hash: d5a82bbd26e1ad8b7401f6a718a9c57c96905483
commit-date: 2023-02-07
host: x86_64-unknown-linux-gnu
release: 1.67.1
LLVM version: 15.0.6

Additional Labels

  • I-suggestion-causes-error
@iajoiner iajoiner added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Feb 19, 2023
@rustbot
Copy link
Collaborator

rustbot commented Feb 19, 2023

Error: Parsing relabel command in comment failed: ...' label +' | error: empty label at >| ' `I-sugges'...

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #t-infra on Zulip.

@iajoiner
Copy link
Author

@rustbot label I-suggestion-causes-error

@rustbot
Copy link
Collaborator

rustbot commented Feb 19, 2023

Error: Label I-suggestion-causes-error can only be set by Rust team members

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #t-infra on Zulip.

@Alexendoo Alexendoo added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Feb 20, 2023
@iajoiner
Copy link
Author

Minimal example added. This is a weird error that is preventing Python bindings of Apache Arrow Datafusion from using clippy in our CI.

@iajoiner
Copy link
Author

iajoiner commented Feb 26, 2023

Corresponding issue on PyO3: PyO3/pyo3#2988

@iajoiner
Copy link
Author

Closed as this is not a Clippy issue. It is a PyO3 one.

@davidhewitt
Copy link

Despite having fixed this in PyO3, I would be interested to hear if there are techniques to hint clippy that the PyO3 code is generated and users can't easily correct it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

No branches or pull requests

4 participants