Skip to content

Erroneous drop_bounds lint #86653

Open
Open
@jonhoo

Description

@jonhoo

I tried this code (playground):

trait Foo where Self: Sized + Drop + 'static {
    fn drop(me: *mut Self) {
        bar(me)
    }
}
pub fn bar(_: *mut dyn Drop) {}

I expected to see this happen: the code should compile without warning.

Instead, this happened: the compiler gave the following warning:

warning: bounds on `Self: Drop` are useless, consider instead using `std::mem::needs_drop` to detect if a type has a destructor
 --> src/lib.rs:1:31
  |
1 | trait Foo where Self: Sized + Drop + 'static {
  |                               ^^^^
  |
  = note: `#[warn(drop_bounds)]` on by default

But, the Drop bound is not useless here — removing it causes the code to no longer compile. It's not clear if removing the bound should make the code stop compiling, but that's a different matter (and perhaps a different bug?).

Meta

rustc --version --verbose:

rustc 1.53.0 (53cb7b09b 2021-06-17)
binary: rustc
commit-hash: 53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b
commit-date: 2021-06-17
host: x86_64-unknown-linux-gnu
release: 1.53.0
LLVM version: 12.0.1

The warning also occurs on nightly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-destructorsArea: Destructors (`Drop`, …)A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions