Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault on calling method on owned trait object #7208

Closed
benw opened this issue Jun 18, 2013 · 1 comment
Closed

Segfault on calling method on owned trait object #7208

benw opened this issue Jun 18, 2013 · 1 comment

Comments

@benw
Copy link

benw commented Jun 18, 2013

This segfaults on the second call to fruit.eat():

trait Fruit {
  fn eat(&self);
}

struct Apple {
  x: int
}

impl Fruit for Apple {
  fn eat(&self) {
    println(fmt!("Crunching on apple %d", self.x));
  }
}

fn main() {
  let fruits: ~[ ~Fruit ] = ~[
    ~Apple{ x: 1 } as ~Fruit,
    ~Apple{ x: 2 } as ~Fruit,
    ~Apple{ x: 3 } as ~Fruit
  ];

  for fruits.each |fruit| {
    println(~"before");
    fruit.eat();
    println(~"after");
  }
}

Results:

> rustc --version
rustc 0.6
host: x86_64-apple-darwin
> rustc test.rs 
warning: no debug symbols in executable (-arch x86_64)
> ./test
before
Crunching on apple 1
after
before
Segmentation fault: 11
bors added a commit that referenced this issue Jun 22, 2013
This finishes the incomplete conversion of unique traits as two-word
allocations started in 211d038.

Fixes #5882, #6717, #7153, #7208.
@thestinger
Copy link
Contributor

Fixed by #7214.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants