[map_entry]: Check insert expression for map use
The lint makes sure that the map is not used (borrowed) before the call to `insert`. Since the lint creates a mutable borrow on the map with the `Entry`, it wouldn't be possible to replace such code with `Entry`. However, expressions up to the `insert` call are checked, but not expressions for the arguments of the `insert` call itself. This commit fixes that. Fixes #11935
This commit is contained in:
parent
10136170fe
commit
03bb7908b9
3 changed files with 75 additions and 2 deletions
|
|
@ -165,4 +165,15 @@ pub fn issue_10331() {
|
|||
}
|
||||
}
|
||||
|
||||
/// Issue 11935
|
||||
/// Do not suggest using entries if the map is used inside the `insert` expression.
|
||||
pub fn issue_11935() {
|
||||
let mut counts: HashMap<u64, u64> = HashMap::new();
|
||||
if !counts.contains_key(&1) {
|
||||
counts.insert(1, 1);
|
||||
} else {
|
||||
counts.insert(1, counts.get(&1).unwrap() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -169,4 +169,15 @@ pub fn issue_10331() {
|
|||
}
|
||||
}
|
||||
|
||||
/// Issue 11935
|
||||
/// Do not suggest using entries if the map is used inside the `insert` expression.
|
||||
pub fn issue_11935() {
|
||||
let mut counts: HashMap<u64, u64> = HashMap::new();
|
||||
if !counts.contains_key(&1) {
|
||||
counts.insert(1, 1);
|
||||
} else {
|
||||
counts.insert(1, counts.get(&1).unwrap() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue