Skip to content

NLL allows creating variables that are immediately unusable. #53695

Closed
@matthewjasper

Description

@matthewjasper

The following code compiles with NLL currently

fn main() {
    let x = {
        let z = 0;
        &z
    };
}

because it's equivalent to:

fn main() {
    let x;
    {
        let z = 0;
        x = &z
    };
}

However, any further use of x will result in a "z does not live long enough" warning. Should there be some read of x after the rest of the let is done to ensure that this doesn't happen?

Metadata

Metadata

Assignees

Labels

A-NLLArea: Non-lexical lifetimes (NLL)NLL-soundWorking towards the "invalid code does not compile" goalT-langRelevant to the language team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions