Skip to content

NLL: migration mistakenly downgrades when AST error is spread across closure and its parent #55492

Closed
@pnkfelix

Description

@pnkfelix

Consider the following (play):

pub fn capture_assign_whole(x: (i32,)) {
    || { x = (1,); };
}

fn main() {
    capture_assign_whole((1000,));
}

Under both AST-borrowck and #![feature(nll)], it errors.

But under NLL migration mode (the default for the 2018 edition), it downgrades the error to a warning.

My current hypothesis (which has been supported by inspecting RUST_LOG output) is that after the migrate mode encounters the NLL error, when it runs the AST-borrowck to see if it also errors, it runs the borrowck only on the closure body, not the parent, which means it misses the mutable borrow that occurs when the mutable capture occurs in the parent for an immutable binding x.

Metadata

Metadata

Assignees

Labels

A-NLLArea: Non-lexical lifetimes (NLL)NLL-soundWorking towards the "invalid code does not compile" goal

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions