Skip to content
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::view interacts strangely with @str values #3572

Closed
Dretch opened this issue Sep 24, 2012 · 2 comments
Closed

str::view interacts strangely with @str values #3572

Dretch opened this issue Sep 24, 2012 · 2 comments
Labels
A-lifetimes Area: Lifetimes / regions
Milestone

Comments

@Dretch
Copy link
Contributor

Dretch commented Sep 24, 2012

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:

    io::println(str::view(~"abcdef", 1, 5).to_unique());

Because:

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
@nikomatsakis
Copy link
Contributor

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.

@graydon
Copy link
Contributor

graydon commented Mar 22, 2013

fixed as of 2013-03-22

@graydon graydon closed this as completed Mar 22, 2013
RalfJung pushed a commit to RalfJung/rust that referenced this issue May 19, 2024
Give `FileDescription::{read, write}` access to the `MiriInterpCx `

fixes rust-lang#3572
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions
Projects
None yet
Development

No branches or pull requests

3 participants