-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Suggest use .get_mut
instead of &mut
when overloaded index type not impl IndexMut
#144018
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
base: master
Are you sure you want to change the base?
Conversation
You need to compare the defid with the defid of the HashMap/BTreeMap diagnostic item and hard code the special case |
.get_mut
instead of &mut
when occur HashMap
and BtreeMap
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.
The second commit shows the testcase difference.
In your first version you checked if the assignment on the type came from an overloaded index. You should check whether the overloaded index type implements @rustbot author |
Reminder, once the PR becomes ready for a review, use |
Signed-off-by: xizheyin <[email protected]>
8d3b265
to
c43a91f
Compare
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.
@rustbot ready
let mut vec = vec![String::new(), String::new()]; | ||
let string = &vec[0]; | ||
string.push_str("test"); //~ ERROR cannot borrow `*string` as mutable, as it is behind a `&` reference [E0596] |
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 add a case that type impls IndexMut
, i.e. Vec
.
.type_implements_trait( | ||
index_mut_trait, | ||
[ty, index_ty], | ||
self.infcx.param_env, | ||
) | ||
.must_apply_modulo_regions() |
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 use type_implements_trait
to judge if the type impl IndexMut
.
This comment has been minimized.
This comment has been minimized.
…ot impl `IndexMut` Signed-off-by: xizheyin <[email protected]>
.get_mut
instead of &mut
when occur HashMap
and BtreeMap
.get_mut
instead of &mut
when overloaded index type not impl IndexMut
Fixes #143732
r? compiler