Repository navigation
Suggest changing argument mutability from &T to &mut T - #162657
enesmahmtoglu wants to merge 1 commit into
Conversation
|
Thanks for the pull request, and welcome! The Rust Project has assigned @ShoyuVanilla (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks. Please see the contribution instructions and our LLM policy for more information. Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
When a function or method takes a mutable reference but an immutable reference is provided, suggest changing the borrow to be mutable.
d186516 to
bf137d3
Compare
There was a problem hiding this comment.
Looks like #162106 already exists which fixes the same issue 🤔 Though the original issue isn't claimed, I think we should respect the preexisting one
| false, | ||
| )); | ||
| } | ||
| ( |
There was a problem hiding this comment.
I think this isn't the right place to add this suggestion, as the suggestion is not about either referencing/dereferencing
| &ty::Ref(_, check_inner, hir::Mutability::Not), | ||
| ) if { | ||
| let new_mut_ref = | ||
| Ty::new_mut_ref(self.tcx, self.tcx.lifetimes.re_static, check_inner); |
There was a problem hiding this comment.
Couldn't we use the original lifetime from the expression rather than 'static?
| let new_mut_ref = | ||
| Ty::new_mut_ref(self.tcx, self.tcx.lifetimes.re_static, check_inner); | ||
| self.may_coerce(new_mut_ref, expected) | ||
| || self.can_eq(self.param_env, check_inner, exp_inner) |
There was a problem hiding this comment.
Why do we need can_eq? Isn't may_corece enough?
|
Closing this in favor of #162106, which I hadn't noticed when opening this PR. Thanks for the review, @ShoyuVanilla! |
Fixes #159490.
When a function or method takes a mutable reference
&mut Tbut an immutable reference&Tis supplied (e.g.read_line(&input)), rustc reportstypes differ in mutabilitybut did not provide a suggestion to change the borrow.This commit adds a diagnostic suggestion in
rustc_hir_typeckto change the borrow to mutable (&mut ...), along with a new UI regression test.