Skip to content

consider fixing common regression with expansion of 2-phase borrows #51915

Open
@nikomatsakis

Description

@nikomatsakis

The following code works without NLL but not with NLL enabled:

https://play.rust-lang.org/?gist=9b797f941b3aa419991e15fd5a2d07a0&version=nightly&mode=debug

//#![feature(nll)]

struct S {
    a: &'static str,
}

fn f(_: &mut S, _: &str) {
}

fn main() {
    let mut s = S {
        a: "a",
    };

    f(&mut s, s.a);
}

NLL is not wrong to reject this code. This is #38899. However, it could plausibly be accepted if we expanded two-phase borrows ever so slightly... actually, I'm not sure about this exact source, or it least it wouldn't quite fit into what I had in mind.

I had in mind an expansion for arguments of type &mut, basically, so that foo(bar), if bar is an &mut that is being reborrowed, would reborrow using a 2-phase borrow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-NLLArea: Non-lexical lifetimes (NLL)C-enhancementCategory: An issue proposing an enhancement or a PR with one.NLL-completeWorking towards the "valid code works" goalP-mediumMedium priorityT-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