-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
str.word_iter().collect() allows slices to escape the borrowck #7713
Comments
Investigating. |
I believe this is due to #5781 |
This appears to be fixed: <anon>:5:28: 5:29 error: borrowed value does not live long enough
<anon>:5 let s = ~"foo bar"; s.word_iter().collect::<~[&str]>()
^
<anon>:3:10: 8:1 note: borrowed pointer must be valid for the block at 3:10...
<anon>:3 fn main() {
<anon>:4 let r = {
<anon>:5 let s = ~"foo bar"; s.word_iter().collect::<~[&str]>()
<anon>:6 };
<anon>:7 println(fmt!("%?", r))
<anon>:8 }
<anon>:4:12: 6:5 note: ...but borrowed value is only valid for the block at 4:12
<anon>:4 let r = {
<anon>:5 let s = ~"foo bar"; s.word_iter().collect::<~[&str]>()
<anon>:6 };
error: aborting due to previous error
application terminated with error code 101 But I'm not sure why: @nikomatsakis do you know of anything that would've fixed this? |
This does compile now, and outputs |
I still suspect the error is #5781. If I find the time, I'll probe a bit more deeply this week. |
Closing, this compiles with a correct error now: fn main() {
let v = {
let s = "foo bar".to_string();
s.as_slice().words().collect::<Vec<&str>>()
};
println!("{}", v.to_string());
} Additionally, the cc'd issue #5781, is closed, so I believe the relevant tests are all checked in. |
Changing the
v.to_str()
tofmt!("%?", v)
still compiles and outputsThe text was updated successfully, but these errors were encountered: