Skip to content

Rc runs destructors twice on trait objects #25515

Closed
@ftxqxd

Description

@ftxqxd
use std::rc::Rc;

fn main() {
    struct Bass(u8);
    impl Drop for Bass {
        fn drop(&mut self) {
            println!("DROP THE BASS: {}", self.0);
            self.0 -= 1;
        }
    }
    let _: Rc<Send> = Rc::new(Bass(37));
}

prints:

DROP THE BASS: 37
DROP THE BASS: 36

(Playpen)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions