Skip to content
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

Improve diagnostic for wrong borrow on binary operations #114288

Merged
merged 1 commit into from
Aug 1, 2023

Conversation

Urgau
Copy link
Member

@Urgau Urgau commented Jul 31, 2023

This PR improves the diagnostic for wrong borrow on binary operations by suggesting to reborrow on appropriate expressions.

+    = note: an implementation for `&Foo * &Foo` exist
+ help: consider reborrowing both sides
+    |
+ LL |     let _ = &*ref_mut_foo * &*ref_mut_foo;
+    |             ++              ++

Fixes #109352

@rustbot
Copy link
Collaborator

rustbot commented Jul 31, 2023

r? @b-naber

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 31, 2023

let mut suggest_new_borrow = |new_mutbl, sp: Span| {
// Can reborrow (&mut -> &)
if new_mutbl == ast::Mutability::Not {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, but using is_not() meant adding type inference to the closure, not sure if it's better.

compiler/rustc_hir_typeck/src/op.rs Outdated Show resolved Hide resolved
compiler/rustc_hir_typeck/src/op.rs Outdated Show resolved Hide resolved
compiler/rustc_hir_typeck/src/op.rs Outdated Show resolved Hide resolved
@Urgau Urgau force-pushed the fix-issue-109352 branch from fecd0f1 to ad0729e Compare August 1, 2023 08:08
@b-naber
Copy link
Contributor

b-naber commented Aug 1, 2023

Looks great. Thanks!

Btw it's a little easier to review, if you push new commits that address a review instead of force pushing.

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Aug 1, 2023

📌 Commit ad0729e has been approved by b-naber

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 1, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 1, 2023
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#100455 (Implement RefUnwindSafe for Backtrace)
 - rust-lang#113428 (coverage: Replace `ExpressionOperandId` with enum `Operand`)
 - rust-lang#114283 (Use parking lot's rwlock even without parallel-rustc)
 - rust-lang#114288 (Improve diagnostic for wrong borrow on binary operations)
 - rust-lang#114296 (interpret: fix alignment handling for Repeat expressions)
 - rust-lang#114306 ([rustc_data_structures][perf] Simplify base_n::push_str.)
 - rust-lang#114320 (Cover statements for stable_mir)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit c726dcb into rust-lang:master Aug 1, 2023
@rustbot rustbot added this to the 1.73.0 milestone Aug 1, 2023
@Urgau Urgau deleted the fix-issue-109352 branch August 1, 2023 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Idea: suggest coercing to &T from &mut T if it satisfies type check
4 participants