Skip to content

Returning a struct that holds an owned trait object results in a segfault #6717

Closed
@zargony

Description

@zargony

Using rustc 0.6, the compiled executable of the following code results in a segfault. I'm not exactly sure why, but I suppose this shouldn't happen ;).

Btw, using @Animal instead of ~Animal works fine. Using @Cage or ~Cage doesn't matter (both crash). Building ~Cage directly in main() also works fine.

pub trait Animal { }

struct Cage {
  animal: ~Animal,
}

fn capture (animal: ~Animal) -> ~Cage {
  let cage = ~Cage { animal: animal };
  debug!("still alive");
  cage
}

struct Duck { foo: int }

impl Animal for Duck { }

fn main () {
  let duck = ~Duck { foo: 123 };
  let _ = capture(duck as ~Animal);
  debug!("never reached");
}


zargony@lina:~$ uname -a
Darwin lina.fritz.box 12.3.0 Darwin Kernel Version 12.3.0: Sun Jan  6 22:37:10 PST 2013; root:xnu-2050.22.13~1/RELEASE_X86_64 x86_64
zargony@lina:~$ rustc --version
rustc 0.6
host: x86_64-apple-darwin

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