Skip to content

Segfault when casting owned structs to owned traits (double free?) #6318

Closed
@bstrie

Description

@bstrie

This compiles, but segfaults when run:

pub enum Thing {
    A(~Foo)
}

pub trait Foo {}

pub struct Struct;

impl Foo for Struct {}

fn main() {
    match A(~Struct as ~Foo) {
        A(a) => 0,
    };
}

The segfault goes away when you do the following:

  • Convert A(a) => 0 to A(_) => 0
  • Change all the unique pointers to managed pointers
  • Change the tag from A(~Foo) to A(~Struct) (and remove the cast)

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions