rust-lang / rust-lang/rust

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

Open
#128,225 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-borrow-checker T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

#[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
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by compiling the standalone Rust reproducer in the issue and inspect the lifetime diagnostic around the assignment to root.part. Compare the reported error with the intended lifetime behavior; done requires establishing whether this is a compiler bug and, if so, adding an appropriate regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.