-
Notifications
You must be signed in to change notification settings - Fork 13.7k
overhaul &mut
suggestions in borrowck errors
#145013
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
Conversation
r? @nnethercote rustbot has assigned @nnethercote. Use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have only looked at the tests and their outputs so far, some of the suggestions seem suboptimal. Is this expected?
@rustbot author
| | ||
LL | let x: &[isize] = &mut [1, 2, 3, 4, 5]; | ||
| +++ | ||
LL | let x: &mut [isize] = &[1, 2, 3, 4, 5]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still invalid, it needs to be &mut [1, 2, 3, 4, 5]
.
| | ||
LL | let x = &mut 0 as *const i32; | ||
| +++ | ||
LL | let x: *mut i32 = &0 as *const i32; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also still invalid, let x = &mut 0 as *mut i32;
would work, without needing the type annotation.
help: consider changing this binding's type | ||
| | ||
LL - let ptr_x: *const _ = &x; | ||
LL + let ptr_x: *mut i32 = &x; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be &x
instead of &mut x
.
tests/ui/borrowck/suggestions/overloaded-index-not-mut-but-should-be-mut.stderr
Show resolved
Hide resolved
tests/ui/borrowck/suggestions/overloaded-index-not-mut-but-should-be-mut.stderr
Show resolved
Hide resolved
tests/ui/borrowck/suggestions/overloaded-index-not-mut-but-should-be-mut.stderr
Show resolved
Hide resolved
This is marked as waiting on review, but my comments about the invalid suggestions haven't been addressed. What's the status there? |
Rustbot didn't change it when you included as the "review comment", it has to be a normal comment @rustbot author |
2d1f731
to
b4b62f1
Compare
This PR was rebased onto a different master commit! Check out the changes with our |
b4b62f1
to
fe98063
Compare
w.r.t. invalid suggestions: every time I look into this code I find things to refactor, so this is currently turning into an endless time sink. The logic is an entangled mess and I tried to untangle it a bit. It is still entangled, but better from the previous state of using stringy logic for everything, having the same code path for everything from Some of them have complicated mir, which is probably why the original author chose to do string operations instead of matching on mir. (if you want to take a look, run with I put down some infrastructure to allow both an expr suggestion and a type change suggestion to exist. For some reason this doesn't fire at the moment. But this is a pre-existing issue and my PR doesn't regress them too much so I propose we could land this and fix later. |
This comment has been minimized.
This comment has been minimized.
fe98063
to
e78b417
Compare
if you want me to look into this even more, feel free to turn the labels back @rustbot ready |
return; | ||
} | ||
|
||
// no suggestion for expression; find a binding's type to make mutable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My most boomer-coded opinion is that I like sentences to begin with an upper-case letter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify:
- Punctuationless phrase fragments are bearable, e.g. "this is a comment"
- A trailing period makes it worse, e..g "this is a comment."
- Multiple sentences are beyond the pale e.g. "this is a comment. this is another comment." If it's heading into "proper paragraph" territory there are rules for a reason, they make the text easier to read.
I almost always write comments as full sentences with upper-case first letter and closing period. Occasionally I'll do a "this is a comment"-style punctuation-free sentence fragment, perhaps as a trailing comment on a line with code.
Is it accurate to mark this as fully fixing #143732? The PR is hard to review. It's hard to see what is new code and what is just moved around. I'm not sure if it could have been broken into small pieces. I'm not inclined to go over it with a fine-tooth comb but I also don't want to block it, based on the fact that it does somewhat improve the error messages and you say there is follow-up work to be done. So you can have an r=me if you want it and think it's progress. |
Yes, because I believe either the "specify this binding's type" will fire or it will go down the path of either suggesting
Went through the file and applied the stylistic changes you suggested.
Yeah, I don't know either. Perhaps it would be easier if the refactor was done first, and the new logic was added later. But I still think it would be hard to review. The followups would probably be easier. @bors r=nnethercote |
…m, r=nnethercote overhaul `&mut` suggestions in borrowck errors * This refactors the logic so that it does not use fuzzy string matching for suggestions; it instead uses information directly from MIR. * If something comes from a custom `Index` impl for which the `IndexMut` trait does not apply, do not suggest adding `mut` after `&`. * Suggest `get_mut` with `unwrap` if error is fired on `BTreeMap` or `HashMap`. Supersedes rust-lang#144018 cc `@xizheyin` Closes rust-lang#143732
…m, r=nnethercote overhaul `&mut` suggestions in borrowck errors * This refactors the logic so that it does not use fuzzy string matching for suggestions; it instead uses information directly from MIR. * If something comes from a custom `Index` impl for which the `IndexMut` trait does not apply, do not suggest adding `mut` after `&`. * Suggest `get_mut` with `unwrap` if error is fired on `BTreeMap` or `HashMap`. Supersedes rust-lang#144018 cc ``@xizheyin`` Closes rust-lang#143732
Rollup of 19 pull requests Successful merges: - #140956 (`impl PartialEq<{str,String}> for {Path,PathBuf}`) - #141744 (Stabilize `ip_from`) - #142681 (Remove the `#[no_sanitize]` attribute in favor of `#[sanitize(xyz = "on|off")]`) - #142871 (Trivial improve doc for transpose ) - #144252 (Do not copy .rmeta files into the sysroot of the build compiler during check of rustc/std) - #144476 (rustdoc-search: search backend with partitioned suffix tree) - #144567 (Fix RISC-V Test Failures in ./x test for Multiple Codegen Cases) - #144804 (Don't warn on never to any `as` casts as unreachable) - #144960 ([RTE-513] Ignore sleep_until test on SGX) - #145013 (overhaul `&mut` suggestions in borrowck errors) - #145041 (rework GAT borrowck limitation error) - #145243 (take attr style into account in diagnostics) - #145405 (cleanup: use run_in_tmpdir in run-make/rustdoc-scrape-examples-paths) - #145432 (cg_llvm: Small cleanups to `owned_target_machine`) - #145484 (Remove `LlvmArchiveBuilder` and supporting code/bindings) - #145557 (Fix uplifting in `Assemble` step) - #145563 (Remove the `From` derive macro from prelude) - #145565 (Improve context of bootstrap errors in CI) - #145584 (interpret: avoid forcing all integer newtypes into memory during clear_provenance) Failed merges: - #145359 (Fix bug where `rustdoc-js` tester would not pick the right `search.js` file if there is more than one) - #145573 (Add an experimental unsafe(force_target_feature) attribute.) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #145013 - fee1-dead-contrib:push-vwvsqsqnrxqm, r=nnethercote overhaul `&mut` suggestions in borrowck errors * This refactors the logic so that it does not use fuzzy string matching for suggestions; it instead uses information directly from MIR. * If something comes from a custom `Index` impl for which the `IndexMut` trait does not apply, do not suggest adding `mut` after `&`. * Suggest `get_mut` with `unwrap` if error is fired on `BTreeMap` or `HashMap`. Supersedes #144018 cc ```@xizheyin``` Closes #143732
Index
impl for which theIndexMut
trait does not apply, do not suggest addingmut
after&
.get_mut
withunwrap
if error is fired onBTreeMap
orHashMap
.Supersedes #144018 cc @xizheyin
Closes #143732