Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Improve diagnostics for Precise Capture #22

Closed
arora-aman opened this issue Nov 9, 2020 · 0 comments · Fixed by rust-lang/rust#81062
Closed

Improve diagnostics for Precise Capture #22

arora-aman opened this issue Nov 9, 2020 · 0 comments · Fixed by rust-lang/rust#81062
Assignees

Comments

@arora-aman
Copy link
Member

Currently, we store and report back only one expression for why a particular path is captured and how the path is captured. We prioritize how the path is captured (i.e on the CaptureKind -- ByValue/ByRef). This works today since the root variable is captured in entirety, however won't result in good diagnostics once the feature is complete.

Consider the following example

let p = Point { x: 10, y: 10 };

let c = || {
    p.x      += 10;
//  ^ E1 ^
    println!("{:?}",  p);
//                  ^ E2 ^
};

Here the result of the capture analysis is p is borrowed by a MutBorrow. This is because E1 force the MutBorrow and E2 forces the path p.

By storing only one piece of information currently E1 (since we prioritize the capture kind) in diagnostics can't express all the information a user might need to fix their code.

We need to update CaptureInformation (rustc_middle/src/ty/mod.rs) to contain two expression ids (capture_kind_expr_id, path_expr_id). We then use this to emit two notes.

let mut p = Point { x: 10, y: 10 };

let c = || {
    p.x      += 10;
//  ^ mutable borrow of `p` happens here
    println!("{:?}",  p);
//                    ^ `p` is captured since it's used here.
};

In case both the capture_kind_expr_id and path_expr_id are the same we only emit one-note similar to how we do it today.

let mut p = Point { x: 10, y: 10 };

let c = || {
    p  = Point { ... } ;
//  ^ mutable borrow of `p` happens here
};
@arora-aman arora-aman assigned ChrisPardy and unassigned null-sleep Nov 21, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Jan 27, 2021
…tics, r=nikomatsakis

Improve diagnostics for Precise Capture

This is just the capture analysis part and borrow checker logging will updated as part of rust-lang/project-rfc-2229#8

Closes rust-lang/project-rfc-2229#22
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Jan 27, 2021
…tics, r=nikomatsakis

Improve diagnostics for Precise Capture

This is just the capture analysis part and borrow checker logging will updated as part of rust-lang/project-rfc-2229#8

Closes rust-lang/project-rfc-2229#22
@nikomatsakis nikomatsakis added this to the Feature complete milestone Feb 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants