-
Notifications
You must be signed in to change notification settings - Fork 1.6k
unnecessary_lazy_evaluations
: Shouldn't warn about values with significant Drop
impl
#9427
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
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
@rustbot claim |
This issue is not fixed, and should be reopened. struct NoisyDrop;
impl Drop for NoisyDrop {
fn drop(&mut self) {
panic!();
}
}
fn a() {
let _ = false.then(|| NoisyDrop);
} warns on |
can reproduce on master, will look at |
bors
added a commit
that referenced
this issue
Nov 22, 2022
Fix [`unnecessary_lazy_eval`] when type has significant drop fix for #9427 (comment) However current implementation gives too many false positive, rending the lint almost useless. I don't know what's the best way to check if a type has a "significant" drop (in the common meaning, not the internal rustc one, for example Option<(u8, u8)> should not be considered significant) changelog: Fix [`unnecessary_lazy_eval`] when type has significant drop
#9750 should have fixed this issue :). |
@xFrednet @kraktus I believe this issue is not fixed and should be reopened. The following code: extern crate ffi;
use core::ffi::c_char;
struct Buffer {
ptr: *mut c_char,
len: usize,
}
impl Buffer {
unsafe fn from_owned_ptr(ptr: *mut c_char, len: usize) -> Option<Self> {
(!ptr.is_null()).then(|| Self { ptr, len })
}
}
impl Drop for Buffer {
fn drop(&mut self) {
unsafe { ffi::free(self.ptr) };
}
} Triggers this warning (using clippy 0.1.76):
|
Opened #12097 for that one |
bors
added a commit
that referenced
this issue
Jan 5, 2024
don't change eagerness for struct literal syntax with significant drop Fixes the bug reported by `@ju1ius` in #9427 (comment). `eager_or_lazy` already understands to suppress eagerness changes when the expression type has a significant drop impl, but only for initialization of tuple structs or unit structs. This changes it to also avoid changing it for `Self { .. }` and `TypeWithDrop { .. }` changelog: [`unnecessary_lazy_eval`]: don't suggest changing eagerness for struct literal syntax when type has a significant drop impl
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
Summary
The case in question that was wrongly reported is the following
Self
here has a significantDrop
impl, specifically it will close theisize
there (it's basically like afd
and closing-1
is UB).Lint Name
unnecessary_lazy_evaluations
Reproducer
I tried this code:
I saw this happen:
I expected to see this happen: nothing because the suggestion gives different behaviour
Version
Additional Labels
@rustbot label +I-suggestion-causes-error
The text was updated successfully, but these errors were encountered: