Skip to content

Prohibit specialized drops #8142

@mstewartgallus

Description

@mstewartgallus

UPDATE:

The plan for drops, as I recall, was to prohibit "specialized" drops, but this never got implemented. The idea is to require that impls of Drop meet special criteria such that the Selfparameter must (a) be a nominal type (struct or enum); (b) have fresh type parameters for each type parameter of the type with (c) no additional bounds beyond those declared in the type declaration. Note that we will have to permit type bounds in type declarations, as well, which is to some extent a separate issue (also required for DST).

For example, this is legal:

struct Foo<T> { ... }

impl<T> Drop for Foo<T> { ... }

but this is not

impl<T:Send> Drop for Foo<T> { ... }

nor the example below.

ORIGINAL:

The following code prints Dropping!. This is wrong.

struct Foo<T>;

#[unsafe_destructor]
impl Drop for Foo<bool> {
    fn drop(&self) {
        println("Dropping!")
    }
}

fn main() {
    let _foo: Foo<()> = Foo;
}

Metadata

Metadata

Assignees

Labels

A-destructorsArea: Destructors (`Drop`, …)P-mediumMedium priority

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions