Suggest dereferencing on assignment to mutable borrow#61054
Suggest dereferencing on assignment to mutable borrow#61054bors merged 2 commits intorust-lang:masterfrom
Conversation
|
r? @zackmdavis (rust_highfive has picked a reviewer for you, use r? to override) |
|
cc @Centril on wording |
|
@bors r+ |
|
📌 Commit 1e3302d has been approved by |
|
Won't this suggestion trigger even if the type of the pointee and the assignee are different? let mut x = 0;
(&mut x) = None; // suggestion to consider dereferencing does not work |
|
I'll add a negative check to the test to avoid regressions, but by the time we hit this code we have already checked that the two types can be unified and that the left is a mutable borrow. |
|
@bors r- Until that test is added then :) |
Centril
left a comment
There was a problem hiding this comment.
I'm a big, big fan of having a diagnostic for this as I make this mistake on a regular basis.
| } else { | ||
| String::new() | ||
| }; | ||
| if let Some(hir::Node::Expr(hir::Expr { |
There was a problem hiding this comment.
With this addition the function is ~200+ LOC -- can we avoid making it bigger? =P
There was a problem hiding this comment.
I'm focusing on slimming/splitting Parser now. I'll move to other parts of the compiler once in done with that.
There was a problem hiding this comment.
Cool, just don't forget about it... =)
|
@bors r=zackmdavis added the test |
|
🙀 |
|
@bors r=zackmdavis |
|
📌 Commit 7fbbcfa has been approved by |
|
For the case in @mark-i-m's comment, the output is: |
…avis Suggest dereferencing on assignment to mutable borrow Fix rust-lang#33570
Rollup of 6 pull requests Successful merges: - #59545 (Use arenas to avoid Lrc in queries #2) - #61054 (Suggest dereferencing on assignment to mutable borrow) - #61056 (tweak discriminant on non-nullary enum diagnostic) - #61082 (fix dangling reference in Vec::append) - #61086 (Box::into_unique: do the reborrow-to-raw *after* destroying the Box) - #61098 (Fix overflowing literal lint in loops) Failed merges: r? @ghost
Fix #33570