Skip to content

'error: illegal borrow: borrowed value does not live long enough' on chained methods that return &'self pointers #5475

Closed
@Kimundi

Description

@Kimundi
trait Foo {
    fn a(&self) -> &'self str;
    fn b(&self) -> &'self str;
}

impl Foo for &'self str {
    fn a(&self) -> &'self str {
        *self
    }
    fn b(&self) -> &'self str {
        *self
    }
}

fn main () {
    let c = "defg";
    c.a();
    c.b();
    c.a().b(); // error: illegal borrow: borrowed value does not live long enough
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions