Skip to content

mut struct member var(ref) bind to new obj still hint: does not live long enough #128225

Open
@sosotan

Description

@sosotan
#[derive(Debug)]
struct ImportantExcerpt<'a> {
    part: &'a str,
}

fn main() {
    let mut root = ImportantExcerpt {part: "abc"};
    {
        let novel = String::from("Call me Ishmael. Some years ago...");
        let first_sentence = novel.split('.').next().expect("Could not find a '.'");
        root = ImportantExcerpt {part: first_sentence};
        root.part = "1234";  // bind to new static str
    }
    println!("{:?}", root);  // error does not live long enough
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-borrow-checkerArea: The borrow checkerT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions