Closed
Description
This bug was originally reported on the Rust subreddit by user double_to_bool_conv
: http://www.reddit.com/r/rust/comments/24kfmv/iterator_can_live_longer_than_its_parent_is_this/
The version below has been updated after the removal of the ~"string"
syntax.
$ rustc -v
rustc 0.11-pre (4f1b0b5 2014-05-03 12:21:47 -0700)
host: x86_64-unknown-linux-gnu
n owned_iterator(slice: &[~str]) -> ~Iterator<~str> {
~slice.iter().map(|s| s.clone()) as ~Iterator<~str>
}
fn main() {
let mut fail = {
owned_iterator(~["ok".to_owned()])
};
let v = ~["fail".to_owned()];
for i in fail {
println!("{}", i); // prints "fail"
}
let mut segFault = {
owned_iterator(~["ok".to_owned()])
};
let v = ~[-1];
for i in segFault {
println!("{}", i); // Segmentation fault
}
}
Metadata
Metadata
Assignees
Labels
No labels