MIR borrowck: mutable use of immutable upvar causes duplicate errors #46559
Labels
A-NLL
Area: Non-lexical lifetimes (NLL)
C-bug
Category: This is a bug.
NLL-diagnostics
Working towards the "diagnostic parity" goal
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Milestone
e.g. the test
compile-fail/unboxed-closures-mutate-upvar
, or this code:Causes a double error with MIR borrowck
The reason is that the borrow of
x
is inferred as mutable, rather than unique, which means there's an error when creating the closure.I think the best way to solve this would be to limit borrows of immutable upvars to unique - a mutable borrow can't succeed anyway, so this will only cause errors. We can't change the borrow to be unique, because otherwise AST borrowck will not report an error, but maybe we can do this in MIR construction?
The text was updated successfully, but these errors were encountered: