Skip to content

Possible to call Drop::drop more than once on the same value using the UFCS notation #19375

Closed
@ftxqxd

Description

@ftxqxd

foo.drop() currently errors with explicit call to destructor, which is good, but the error does not fire for UFCS-style Drop::drop(&mut foo) calls, leading to the ability to call a value’s destructor more than once:

struct Bass;

impl Drop for Bass {
    fn drop(&mut self) {
        println!("D-D-D-D-DROP THE BASS");
    }
}

fn main() {
    let mut bass = Bass;
    Drop::drop(&mut bass);
    Drop::drop(&mut bass);
    Drop::drop(&mut bass);
}

Metadata

Metadata

Assignees

Labels

A-destructorsArea: Destructors (`Drop`, …)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions