Skip to content

Does the MIR generated for match still build in order-deps visible to MIR-borrowck? #58646

Open
@pnkfelix

Description

@pnkfelix

Spawned off of PR #57609

The above PR has an interesting unit test that checks that we aren't assuming too much order dependence; the test (from file named "match-cfg-fake-edges.rs") looks like this (play):

fn all_previous_tests_may_be_done(y: &mut (bool, bool)) {
    let r = &mut y.1;
    // We don't actually test y.1 to select the second arm, but we don't want
    // borrowck results to be based on the order we match patterns.
    match y {
        (false, true) => 1, //~ ERROR cannot use `y.1` because it was mutably borrowed
        (true, _) => { r; 2 } // (use of "above" borrow)
        (false, _) => 3,
    };
}

while reviewing that test case, I wondered whether order-dependence, as implicitly defined by the above test, would also include this variant:

fn any_tests_may_be_done(y: &mut (bool, bool)) {
    let r = &mut y.1;
    // We don't test y.1 to select the first arm. Does this present
    // an instance where borrowck results are based on the order we
    // match patterns?
    match y {
        (true, _) => { r; 2 } // (use of "below" borrow)
        (false, true) => 1, //~ ERROR cannot use `y.1` because it was mutably borrowed
        (false, _) => 3,
    };
}

Today, all_previous_tests_may_be_done is rejected (with a warning under NLL migration mode, and a hard error if you opt into #![feature(nll), but any_tests_may_be_done is accepted.

Is this an internally consistent policy?


Maybe my question is most simply put like this:

  • since we are adding some "fake edges" from some match-arms to the other arms that follow (to try to avoid prematurely tying ourselves to a particular code-generation strategy for MIR, in terms of what inputs MIR-borrowck will accept), ...
  • shouldn't we be adding even more such "fake edges" that go from the bottom arms back up to the ones before them?

That would increase our flexibility for MIR code-generation, in theory, even further, right?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-NLLArea: Non-lexical lifetimes (NLL)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