Rust: NLL Diagnostic Review 3: missing indication that a "partial move" has occurred

Created on 9 Dec 2018  路  6Comments  路  Source: rust-lang/rust

In ui/borrowck/borrowck-uninit-field-access.ast.nll.stderr, the below error should have the label value used here after move changed to value used here after partial move.

https://github.com/rust-lang/rust/blob/850fc6a4791b3b0ab668f9fb67c35dddd838b01f/src/test/ui/borrowck/borrowck-uninit-field-access.ast.nll.stderr#L17-L25

A-NLL E-mentor NLL-diagnostics

Most helpful comment

@davidtwco I am going to take a run at this at the suggestion of @Dylan-DPC on the Rust Discord.

All 6 comments

Here are some mentoring instructions to get started on this issue. If you're reading this and want to give this issue a go, drop a comment here and feel free to ask for any help or clarification on Zulip.

If this is your first contribution then there are instructions on getting a local build of the compiler available in the rustc guide.


These instructions are up to date as of master being 850fc6a4791b3b0ab668f9fb67c35dddd838b01f.

This error is emitted from the cannot_act_on_moved_value function:

https://github.com/rust-lang/rust/blob/850fc6a4791b3b0ab668f9fb67c35dddd838b01f/src/librustc_mir/util/borrowck_errors.rs#L485-L494

If we grep in the source, we can find that it is invoked in the report_use_of_moved_or_uninitialized function:

https://github.com/rust-lang/rust/blob/850fc6a4791b3b0ab668f9fb67c35dddd838b01f/src/librustc_mir/borrow_check/error_reporting.rs#L128-L134

Inside that function, we can see where this label is being added:

https://github.com/rust-lang/rust/blob/850fc6a4791b3b0ab668f9fb67c35dddd838b01f/src/librustc_mir/borrow_check/error_reporting.rs#L184-L192

In this branch, we'll want to check if the previous move was a partial one (that is, the field we're trying to use and can't had one of its fields moved previously and wasn't itself moved entirely).

To do this, we'll want to look at the previous moves of this data - this is already computed by this function here:

https://github.com/rust-lang/rust/blob/850fc6a4791b3b0ab668f9fb67c35dddd838b01f/src/librustc_mir/borrow_check/error_reporting.rs#L69

move_site_vec is a Vec<MoveSite> (documentation of MoveSite), we'll want to inspect these to determine whether or not it contains a partial move.

For a given MoveSite, we need to work out the path that was moved - the path to some value is represented by a Place and an example of how we can get the Place of a MoveSite is already present in this function we're working on:

https://github.com/rust-lang/rust/blob/850fc6a4791b3b0ab668f9fb67c35dddd838b01f/src/librustc_mir/borrow_check/error_reporting.rs#L144-L145

Given the place that was moved, we want to check if it was a field of the current used_place. This is done by checking if it is a prefix - eg. if we are trying to use some local _1 and it was partially moved previously, then we'd expect the _1 to be a prefix of the Place for the partial move (like _1.0). We can use the is_prefix_of function for this.

After checking if, for any MoveSite, the used_place is a prefix of associated Place (of that MoveSite), then the note can be modified to add the word "partial".


If you've got this working then you should run the tests and update any that change correctly and then open a PR with a line saying r? @davidtwco in the description so I'll be assigned to review it.

hi @davidtwco. I can work on this

@davidtwco I am going to take a run at this at the suggestion of @Dylan-DPC on the Rust Discord.

@clintfred how is it going? Have you had some time to work on that issue, maybe? :-)

@clintfred how is it going? Have you had some time to work on that issue, maybe? :-)

@bartsmykla Yes. As this is my first time working on the compiler, it took some time to get set up and build everything. I am able to build and run tests. I am on to trying to grok David's excellent mentor instructions.
I haven't yet understood how to get a failing test that I can re-run to show progress. ui/borrowck/borrowck-uninit-field-access.ast.nll.stderr is mentioned, but I could use a little guidance there.

I haven't yet understood how to get a failing test that I can re-run to show progress. ui/borrowck/borrowck-uninit-field-access.ast.nll.stderr is mentioned, but I could use a little guidance there.

@clintfred You can run x.py test src/test/ui --test-args borrowck-uninit-field-access and that will build the compiler and run that individual test. Feel free to pass any other arguments you've been giving x.py (such as --stage, --keep-stage or -j) too. There's some documentation here on running tests.

Feel free to hop on Zulip and make a new topic if you have questions and someone will get back to you (or just comment here and I'll reply when I see it).

Was this page helpful?
0 / 5 - 0 ratings