Skip to content

[NLL] Incorrect lifetimes infered with pattern #46974

Closed
@matthewjasper

Description

@matthewjasper

Minified from https://www.reddit.com/r/rust/comments/7lq5t3/featurenll_available_in_nightly/droaz2o/

This incorrectly compiles:

#![feature(nll)]

fn foo(s: &mut (i32,)) -> i32 {
    let &mut (ref x,) = &mut *s; // or {s}
    *s = (2,);
    *x    // 2, which is clearly incorrect
}

These variations correctly error:

fn foo(s: &mut (i32,)) -> i32 {
    let (ref x,) = *s;
    *s = (2,);
    *x
}

fn foo(s: &mut (i32,)) -> i32 {
    let x = &{&mut *s}.0;
    *s = (2,);
    *x
}

fn foo(s: &mut i32) -> i32 {
    let &mut ref x = &mut *s;
    *s = 2;
    *x
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-NLLArea: Non-lexical lifetimes (NLL)C-bugCategory: This is a bug.T-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