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

drop_non_drop should not conditionally trigger depending on target-specific implementations of Mutex #9332

Open
yvt opened this issue Aug 14, 2022 · 0 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

Comments

@yvt
Copy link

yvt commented Aug 14, 2022

Summary

Starting from rust-lang/rust#95035, std::sync::Mutex and other similar synchronization primitives have trivial destructors on some but not all platforms, causing the drop_non_drop lint to conditionally trigger on drop(mutex) depending on current build targets.

Since this makes #[expect(...)] hard to use and might lead programmers to incorrectly generalize the behavior from what they see on their local machines, I think Clippy should assume non-trivial destructors for these types regardless of their underlying implementations.

Lint Name

drop_non_drop

Reproducer

I tried this code:

#[allow(unused_assignments)]
pub fn hoge() {
    let mut x = 42;
    let m = std::sync::Mutex::new(&mut x);
    drop(m);
    x = 56;
}

I saw this happen:

$ cargo clippy --target aarch64-unknown-linux-gnu
    Checking hoge v0.1.0 (/private/tmp/hoge)
warning: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes
 --> src/lib.rs:5:5
  |
5 |     drop(m);
  |     ^^^^^^^
  |
  = note: `#[warn(clippy::drop_non_drop)]` on by default
note: argument has type `std::sync::Mutex<&mut i32>`
 --> src/lib.rs:5:10
  |
5 |     drop(m);
  |          ^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#drop_non_drop

warning: `hoge` (lib) generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 0.14s

$ cargo clippy --target aarch64-apple-darwin
    Checking hoge v0.1.0 (/private/tmp/hoge)
    Finished dev [unoptimized + debuginfo] target(s) in 0.38s

I expected to see this happen: Identical results for both targets

$ cargo clippy --target aarch64-unknown-linux-gnu
    Checking hoge v0.1.0 (/private/tmp/hoge)
    Finished dev [unoptimized + debuginfo] target(s) in 0.38s

$ cargo clippy --target aarch64-apple-darwin
    Checking hoge v0.1.0 (/private/tmp/hoge)
    Finished dev [unoptimized + debuginfo] target(s) in 0.38s

Version

rustc 1.65.0-nightly (29e4a9ee0 2022-08-10)
binary: rustc
commit-hash: 29e4a9ee0253cd39e552a77f51f11f9a5f1c41e6
commit-date: 2022-08-10
host: aarch64-apple-darwin
release: 1.65.0-nightly
LLVM version: 14.0.6

Additional Labels

No response

@yvt yvt 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 Aug 14, 2022
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
Projects
None yet
Development

No branches or pull requests

1 participant