-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied
Description
Summary
The case in question that was wrongly reported is the following
warning: unnecessary closure used with `bool::then`
--> glib/src/convert.rs:122:9
|
122 | (iconv as isize != -1).then(|| Self(iconv))
| ^^^^^^^^^^^^^^^^^^^^^^^--------------------
| |
| help: use `then_some(..)` instead: `then_some(Self(iconv))`
|
= note: `#[warn(clippy::unnecessary_lazy_evaluations)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations
Self
here has a significant Drop
impl, specifically it will close the isize
there (it's basically like a fd
and closing -1
is UB).
Lint Name
unnecessary_lazy_evaluations
Reproducer
I tried this code:
struct Foo(i32);
impl Drop for Foo {
fn drop(&mut self) {
println!("{}", self.0);
}
}
fn main() {
(0 == 1).then(|| Foo(0));
}
I saw this happen:
warning: unnecessary closure used with `bool::then`
--> src/main.rs:10:5
|
10 | (0 == 1).then(|| Foo(0));
| ^^^^^^^^^---------------
| |
| help: use `then_some(..)` instead: `then_some(Foo(0))`
|
= note: `#[warn(clippy::unnecessary_lazy_evaluations)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations
I expected to see this happen: nothing because the suggestion gives different behaviour
Version
rustc 1.65.0-nightly (289279de1 2022-09-04)
binary: rustc
commit-hash: 289279de116707f28cf9c18e4bbb8c6ec84ad75b
commit-date: 2022-09-04
host: x86_64-unknown-linux-gnu
release: 1.65.0-nightly
LLVM version: 15.0.0
Additional Labels
@rustbot label +I-suggestion-causes-error
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied