You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
upsuper opened this issue
Sep 29, 2019
· 0 comments
Labels
A-lintArea: New lintsE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.L-styleLint: Belongs in the style lint groupT-middleType: Probably requires verifiying types
In a discussion in our Rust group today, we saw one wrote something like
// foo is owned, and foo.x has type HashMaplet x = foo.x.borrow_mut();// something mutating through x
and then got trouble moving ownership of items from x (which is unrelated).
This code really confused me because I don't recall that HashMap has borrow_mut, until someone brought up that there is a blanket impl of BorrowMut for all type to their mutable reference.
It doesn't feel idiomatic to use this impl in normal code. If one wants to get a mutable reference, they should just use &mut. .borrow_mut() is more lengthy and confusing. Similar for .borrow().
Thus I suggest that Clippy should lint against use of .borrow() and .borrow_mut() via that blanket impl, and suggest using & and &mut instead correspondingly.
The text was updated successfully, but these errors were encountered:
flip1995
added
L-style
Lint: Belongs in the style lint group
E-medium
Call for participation: Medium difficulty level problem and requires some initial experience.
A-lint
Area: New lints
T-middle
Type: Probably requires verifiying types
labels
Oct 2, 2019
A-lintArea: New lintsE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.L-styleLint: Belongs in the style lint groupT-middleType: Probably requires verifiying types
In a discussion in our Rust group today, we saw one wrote something like
and then got trouble moving ownership of items from
x
(which is unrelated).This code really confused me because I don't recall that
HashMap
hasborrow_mut
, until someone brought up that there is a blanket impl ofBorrowMut
for all type to their mutable reference.It doesn't feel idiomatic to use this impl in normal code. If one wants to get a mutable reference, they should just use
&mut
..borrow_mut()
is more lengthy and confusing. Similar for.borrow()
.Thus I suggest that Clippy should lint against use of
.borrow()
and.borrow_mut()
via that blanket impl, and suggest using&
and&mut
instead correspondingly.The text was updated successfully, but these errors were encountered: