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

Borrowing strings seems broken #11869

Closed
emberian opened this issue Jan 28, 2014 · 4 comments · Fixed by #17721
Closed

Borrowing strings seems broken #11869

emberian opened this issue Jan 28, 2014 · 4 comments · Fixed by #17721
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@emberian
Copy link
Member

#[crate_type="lib"];

struct A {
    a: ~str
}

fn borrow<'a>(binding: &'a A) -> &'a str {
    match binding.a.as_slice() {
        "in" => &'a "in_",
        "ref" => &'a "ref_",
        ident => ident
    }
}
foo.rs:8:11: 8:33 error: cannot infer an appropriate lifetime for autoref due to conflicting requirements
foo.rs:8     match binding.a.as_slice() {
                   ^~~~~~~~~~~~~~~~~~~~~~
foo.rs:8:11: 8:20 note: first, the lifetime cannot outlive the expression at 8:10...
foo.rs:8     match binding.a.as_slice() {
                   ^~~~~~~~~
foo.rs:8:11: 8:20 note: ...so that automatically reference is valid at the time of borrow
foo.rs:8     match binding.a.as_slice() {
                   ^~~~~~~~~
foo.rs:8:11: 8:33 note: but, the lifetime must be valid for the method call at 8:10...
foo.rs:8     match binding.a.as_slice() {
                   ^~~~~~~~~~~~~~~~~~~~~~
foo.rs:8:11: 8:20 note: ...so that method receiver is valid for the method call
foo.rs:8     match binding.a.as_slice() {
                   ^~~~~~~~~

This used to work.

cc @nikomatsakis

@emberian
Copy link
Member Author

(This is a stripped exerpt from gl-rs)

@nikomatsakis
Copy link
Contributor

Hmm, the issue is almost certainly the &'a "in_" expression. I think I broke something in there. I expect you could make the code compile by just writing "in" => "in_". This is related to #11641

@emberian
Copy link
Member Author

#[crate_type="lib"];

struct A {
    a: ~str
}

fn borrow<'a>(binding: &'a A) -> &'a str {
    match binding.a.as_slice() {
        "in" => "in_",
        "ref" => "ref_",
        ident => ident
    }
}

still doesn't compile (same error).

@ghost
Copy link

ghost commented Sep 20, 2014

Seems like it's fixed but may need a test.

@sfackler sfackler added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Sep 21, 2014
flip1995 pushed a commit to flip1995/rust that referenced this issue Dec 28, 2023
…lexendoo

New Lint: `result_filter_map` / Mirror of `option_filter_map`

Added the `Result` mirror of `option_filter_map`.

changelog: New Lint: [`result_filter_map`]

I had to move around some code because the function def was too long 🙃.

I have also added some pattern checks on `option_filter_map`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants