You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When compiling with MIR-borrowck via -Z borrowck-mir, the diagnostics printed when errors involves borrows/moves into the bodies of closures (where the origin path is from the outside of that closure) are pretty bad.
For example, for the test src/test/compile-fail/borrowck/borrowck-closures-two-mut.rs, the AST-borrowck error messages tend to highlight the particular uses within the closure body, while the MIR-borrowck error messages just treat the whole closure as a black box.
Specifically, look at this AST-borrowck error:
error[E0499]: cannot borrow `x` as mutable more than once at a time (Ast)
--> ../src/test/compile-fail/borrowck/borrowck-closures-two-mut.rs:55:24
|
54 | let c1 = to_fn_mut(|| set(&mut *x.f));
| -- - previous borrow occurs due to use of `x` in closure
| |
| first mutable borrow occurs here
55 | let c2 = to_fn_mut(|| set(&mut *x.f));
| ^^ - borrow occurs due to use of `x` in closure
| |
| second mutable borrow occurs here
56 | //~^ ERROR cannot borrow `x` as mutable more than once
57 | }
| - first borrow ends here
and compare that to the corresponding MIR-borrowck error:
error[E0499]: cannot borrow `x` as mutable more than once at a time (Mir)
--> ../src/test/compile-fail/borrowck/borrowck-closures-two-mut.rs:55:24
|
54 | let c1 = to_fn_mut(|| set(&mut *x.f));
| ----------------- first mutable borrow occurs here
55 | let c2 = to_fn_mut(|| set(&mut *x.f));
| ^^^^^^^^^^^^^^^^^ second mutable borrow occurs here
56 | //~^ ERROR cannot borrow `x` as mutable more than once
57 | }
| - first borrow ends here
What MIR-borrowck needs, if we can somehow get it, is the equivalent to the "previous borrow occurs due to use of x in closure" and "borrow occurs due to use of x in closure" messages, with the corresponding (very) precise spans.
The text was updated successfully, but these errors were encountered:
…bank
MIR-borrowck: fix diagnostics for closures
Emit notes for captured variables in the same manner as AST borrowck.
```
error[E0499]: cannot borrow `x` as mutable more than once at a time (Ast)
--> $DIR/borrowck-closures-two-mut.rs:24:24
|
23 | let c1 = to_fn_mut(|| x = 4);
| -- - previous borrow occurs due to use of `x` in closure
| |
| first mutable borrow occurs here
24 | let c2 = to_fn_mut(|| x = 5); //~ ERROR cannot borrow `x` as mutable more than once
| ^^ - borrow occurs due to use of `x` in closure
| |
| second mutable borrow occurs here
25 | }
| - first borrow ends here
error[E0499]: cannot borrow `x` as mutable more than once at a time (Mir)
--> $DIR/borrowck-closures-two-mut.rs:24:24
|
23 | let c1 = to_fn_mut(|| x = 4);
| -- - previous borrow occurs due to use of `x` in closure
| |
| first mutable borrow occurs here
24 | let c2 = to_fn_mut(|| x = 5); //~ ERROR cannot borrow `x` as mutable more than once
| ^^ - borrow occurs due to use of `x` in closure
| |
| second mutable borrow occurs here
25 | }
| - first borrow ends here
```
Fixesrust-lang#45362.
When compiling with MIR-borrowck via
-Z borrowck-mir
, the diagnostics printed when errors involves borrows/moves into the bodies of closures (where the origin path is from the outside of that closure) are pretty bad.For example, for the test
src/test/compile-fail/borrowck/borrowck-closures-two-mut.rs
, the AST-borrowck error messages tend to highlight the particular uses within the closure body, while the MIR-borrowck error messages just treat the whole closure as a black box.Specifically, look at this AST-borrowck error:
and compare that to the corresponding MIR-borrowck error:
What MIR-borrowck needs, if we can somehow get it, is the equivalent to the "previous borrow occurs due to use of
x
in closure" and "borrow occurs due to use ofx
in closure" messages, with the corresponding (very) precise spans.The text was updated successfully, but these errors were encountered: