You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
This segfaults on the second call to
fruit.eat()
:Results:
The text was updated successfully, but these errors were encountered: