Skip to content

Instantly share code, notes, and snippets.

@whatisaphone
Created January 17, 2014 22:31
Show Gist options
  • Save whatisaphone/8482878 to your computer and use it in GitHub Desktop.
Save whatisaphone/8482878 to your computer and use it in GitHub Desktop.
Segfault in rust 0.9-ish (rust commit 74258eae)
fn main() {
let mut c = Container { tests: ~[] };
c.add_str_test(~"/");
c.tests[0].test();
}
trait Test {
fn test(&self) -> bool;
}
struct Container {
tests: ~[~Test],
}
impl Container {
fn add_test(&mut self, test: ~Test) {
self.tests.push(test);
}
fn add_str_test(&mut self, data: ~str) {
self.add_test(~StrTest { data: data });
// changing to this doesn't segfault:
// self.add_test(~StrTest { data: data } as ~Test);
}
}
struct StrTest {
data: ~str,
}
impl Test for StrTest {
fn test(&self) -> bool {
self.data.len(); // Segmentation fault occurs here
true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment