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
I was looking into a way to fix #3433 when I discovered the following issue:
fn main(){
let up_here = @"abcdef";
io::println(str::view(up_here, 1, 5).to_unique()); // prints bcde
io::println(str::view(@"abcdef", 1, 5).to_unique()); // should print bcde but instead prints e
}
Interestingly rustc rejects the erroneous println when a ~str is used instead:
test-atstr-view.rs:6:30: 6:39 error: illegal borrow: borrowed value does not live long enough
test-atstr-view.rs:6 io::println(str::view(~"abcdef", 1, 5).to_unique()); // should print bcde but instead prints e
^~~~~~~~~
test-atstr-view.rs:6:20: 6:59 note: borrowed pointer must be valid for the call at 6:20...
test-atstr-view.rs:6 io::println(str::view(~"abcdef", 1, 5).to_unique()); // should print bcde but instead prints e
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test-atstr-view.rs:6:20: 6:47 note: ...but borrowed value is only valid for the call at 6:20
test-atstr-view.rs:6 io::println(str::view(~"abcdef", 1, 5).to_unique()); // should print bcde but instead prints e
^~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
The text was updated successfully, but these errors were encountered:
The printf is not erroneous. The code should work in both cases, though the current behavior for ~str is expected, at least pending resolution of #3511. For @str, I'd expect the string to be held alive as long as the view was needed. There must be something going wrong with the code that is supposed to be doing that, or perhaps some other part of borrowing an @str is broken.
I was looking into a way to fix #3433 when I discovered the following issue:
Interestingly rustc rejects the erroneous println when a ~str is used instead:
Because:
The text was updated successfully, but these errors were encountered: