-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NLL diagnostics miss opportunities to suggest "change this to mut
"
#51031
Comments
Here are some tips on where this might need to get fixed. For things like rust/src/librustc_mir/borrow_check/mod.rs Lines 1375 to 1380 in 61f35e5
Notably, this call to rust/src/librustc_mir/borrow_check/mod.rs Line 1855 in 61f35e5
(You can see that I think that in the case we want, the "not mutable cause" will be a rust/src/librustc_mir/borrow_check/mod.rs Line 1395 in 61f35e5
(Given a |
If you'd like to help out with this, come join the NLL working group on Zulip. |
It turns out that we have this code already: rust/src/librustc_mir/borrow_check/mod.rs Lines 1708 to 1709 in 61f35e5
I think we ought to be replacing that code with a better version. After all, that code doesn't look like it gives particularly useful errors today:
What we would need to do:
|
I think the same code that is doing this check ( (I do agree that the code here needs revision.) |
I believe this will be eventually addressed by PR #51275 once that is finalized. |
…ermissions, r=nikomatsakis NLL diagnostics: revise `fn check_access_permissions` NLL: revise `fn check_access_permissions` so that its (still branchy) shares more code paths between the different cases, and also provide more diagnostics in more cases (though the added diagnostics still do not always meet the quality bar established by AST-borrowck) ---- Transcribing "checklist" suggested by Niko, except I am rendering it as a table to make it clear that I do not regard every item in the list to be a "must have" for landing this PR. goal | does this PR do it? -----|------------------------------ no suggestions for `ref mut` | yes suggestions for direct local assignment (`{ let x = 3; x = 4; }`) | yes (see commits at end) suggestions for direct field assignment (`{ let x = (3, 4); x.0 = 5; }` | yes (see commits at end) suggestions for upvars (`let x = 3; let c = \|\| { &mut x; }`) | yes Note that I added support for a couple of rows via changes that are not strictly part of `fn check_access_permissions`. If desired I can remove those commits from this PR and leave them for a later PR. Fix #51031 Fix #51032 (bug #51191 needs a little more investigation before closing.) Fix #51578
The following tests rightly suggest under AST borrowck to consider adding
mut
to the binding site, but there is no such suggestion under NLL.Tests:
(This list of tests is drawn from an informal paper document that I have been using to keep notes for myself as I work on this...)
The text was updated successfully, but these errors were encountered: