Created
January 17, 2014 22:31
-
-
Save whatisaphone/8482878 to your computer and use it in GitHub Desktop.
Segfault in rust 0.9-ish (rust commit 74258eae)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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