-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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: false positive for never return type #7812
Comments
is this something someone new to clippy could work on? I'd be interested |
Hey @divagant-martian, this is something you could potentially work on. You basically need to get the function signature that is called in the closure and check if the return type is Never. The return type can be gained by getting the function type and then calling |
@rustbot claim |
This comment has been minimized.
This comment has been minimized.
793: Fix clippy lints in nightly r=Bromeon a=Bromeon Where "fix" means mostly "disable". Lints turned off globally for the time being (might change in the future): * `clippy::missing_safety_doc` -- requires each unsafe fn/trait to have a `# Safety` section. Nice in theory, annoying for internals, and boilerplate-enforcing for obvious public cases. * `clippy::if_then_panic` -- suggests that `if (!cond) { panic!(msg); }` be written as `assert!(cond, msg);` Probably makes sense to enable later, but currently not possible due to [approx/#73](brendanzab/approx#73). Lints turned of locally: * `clippy::redundant_closure` -- works around false positive [rust-clippy/#7812](rust-lang/rust-clippy#7812) * `dead_code` (compiler warning, not clippy) -- generated field `this` not always used. Naming it `_this` doesn't seem right, either. Co-authored-by: Jan Haller <[email protected]>
Actually checking only for the never type doesn't seem to be enough to fix the false positives for this lint. We need to check for all coercions. For example: fn main() {
fn arr() -> &'static [u8; 0] { &[] }
fn slice_fn(_: impl FnOnce() -> &'static [u8]) {}
slice_fn(|| arr());
}
And replacing does work:
|
793: Fix clippy lints in nightly r=Bromeon a=Bromeon Where "fix" means mostly "disable". Lints turned off globally for the time being (might change in the future): * `clippy::missing_safety_doc` -- requires each unsafe fn/trait to have a `# Safety` section. Nice in theory, annoying for internals, and boilerplate-enforcing for obvious public cases. * `clippy::if_then_panic` -- suggests that `if (!cond) { panic!(msg); }` be written as `assert!(cond, msg);` Probably makes sense to enable later, but currently not possible due to [approx/#73](brendanzab/approx#73). Lints turned of locally: * `clippy::redundant_closure` -- works around false positive [rust-clippy/#7812](rust-lang/rust-clippy#7812) * `dead_code` (compiler warning, not clippy) -- generated field `this` not always used. Naming it `_this` doesn't seem right, either. Co-authored-by: Jan Haller <[email protected]>
793: Fix clippy lints in nightly r=Bromeon a=Bromeon Where "fix" means mostly "disable". Lints turned off globally for the time being (might change in the future): * `clippy::missing_safety_doc` -- requires each unsafe fn/trait to have a `# Safety` section. Nice in theory, annoying for internals, and boilerplate-enforcing for obvious public cases. * `clippy::if_then_panic` -- suggests that `if (!cond) { panic!(msg); }` be written as `assert!(cond, msg);` Probably makes sense to enable later, but currently not possible due to [approx/#73](brendanzab/approx#73). Lints turned of locally: * `clippy::redundant_closure` -- works around false positive [rust-clippy/#7812](rust-lang/rust-clippy#7812) * `dead_code` (compiler warning, not clippy) -- generated field `this` not always used. Naming it `_this` doesn't seem right, either. Co-authored-by: Jan Haller <[email protected]>
793: Fix clippy lints in nightly r=Bromeon a=Bromeon Where "fix" means mostly "disable". Lints turned off globally for the time being (might change in the future): * `clippy::missing_safety_doc` -- requires each unsafe fn/trait to have a `# Safety` section. Nice in theory, annoying for internals, and boilerplate-enforcing for obvious public cases. * `clippy::if_then_panic` -- suggests that `if (!cond) { panic!(msg); }` be written as `assert!(cond, msg);` Probably makes sense to enable later, but currently not possible due to [approx/#73](brendanzab/approx#73). Lints turned of locally: * `clippy::redundant_closure` -- works around false positive [rust-clippy/#7812](rust-lang/rust-clippy#7812) * `dead_code` (compiler warning, not clippy) -- generated field `this` not always used. Naming it `_this` doesn't seem right, either. Co-authored-by: Jan Haller <[email protected]>
Lint name:
redundant_closure
With this code:
Clippy emits the following warning:
However, I cannot inline the closure and use the function pointer directly -- this code:
fails to compile with:
Meta
Rust version (
rustc -Vv
):Related, but not identical issues (
redundant_closure
false positives):The text was updated successfully, but these errors were encountered: