-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Improve diagnostic for wrong borrow on binary operations #114288
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
r? @b-naber (rustbot has picked a reviewer for you, use r? to override) |
compiler/rustc_hir_typeck/src/op.rs
Outdated
|
||
let mut suggest_new_borrow = |new_mutbl, sp: Span| { | ||
// Can reborrow (&mut -> &) | ||
if new_mutbl == ast::Mutability::Not { |
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.
ast::Mutability
has methods for this: https://doc.rust-lang.org/stable/nightly-rustc/rustc_ast/ast/enum.Mutability.html#method.is_not
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.
Done, but using is_not()
meant adding type inference to the closure, not sure if it's better.
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 |
…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
This PR improves the diagnostic for wrong borrow on binary operations by suggesting to reborrow on appropriate expressions.
Fixes #109352