Skip to content

#[unsafe_destructor] is excessively unsafe (monomorphizes wrong) #6971

Closed
@ben0x539

Description

@ben0x539
struct S<T> { field: T }

#[unsafe_destructor]
impl<T> Drop for S<T> {
    fn drop(&self) {
        println(fmt!("drop %?", self));
    }
}

fn main() {
    let i = 7496034;
    let _s1 = S { field: (&i, 4) };
    let _s2 = S { field: "foo" };
}

prints

drop &{field: "foo"}
drop &{field: "bar"}

I suppose the clue is in the name of that attribute, but I figured this case is worth noting--I expected somewhat more subtle unsafety.

It does the right thing if the destructor refers to the field specifically.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationA-destructorsArea: Destructors (`Drop`, …)I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions