Skip to content

Borrowing strings seems broken #11869

Closed
@emberian

Description

@emberian
#[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

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions