-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #7640 - kneasle:mut-key-false-positive, r=camsteffen
Improve accuracy of `mut_key` Fixes #6745. Whilst writing the tests for this, I noticed what I believe is a false negative (the code in `@xFrednet's` [comment](#6745 (comment)) doesn't trigger the lint). Currently the tests contain a case for this (which is blatantly ignored), but I'm not at all sure how to implement this (since the lint currently behaves completely differently for ADTs). I'm not sure what should be done - on the one hand the extra test cases are misleading, but on the other hand they don't cause much harm and would save effort for anyone fixing that false negative. --- changelog: Improve accuracy of `clippy::mutable_key_type`.
- Loading branch information
Showing
3 changed files
with
176 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,106 @@ | ||
error: mutable key type | ||
--> $DIR/mut_key.rs:27:32 | ||
--> $DIR/mut_key.rs:30:32 | ||
| | ||
LL | fn should_not_take_this_arg(m: &mut HashMap<Key, usize>, _n: usize) -> HashSet<Key> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::mutable-key-type` implied by `-D warnings` | ||
|
||
error: mutable key type | ||
--> $DIR/mut_key.rs:27:72 | ||
--> $DIR/mut_key.rs:30:72 | ||
| | ||
LL | fn should_not_take_this_arg(m: &mut HashMap<Key, usize>, _n: usize) -> HashSet<Key> { | ||
| ^^^^^^^^^^^^ | ||
|
||
error: mutable key type | ||
--> $DIR/mut_key.rs:28:5 | ||
--> $DIR/mut_key.rs:31:5 | ||
| | ||
LL | let _other: HashMap<Key, bool> = HashMap::new(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: mutable key type | ||
--> $DIR/mut_key.rs:47:22 | ||
--> $DIR/mut_key.rs:58:22 | ||
| | ||
LL | fn tuples_bad<U>(_m: &mut HashMap<(Key, U), bool>) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 4 previous errors | ||
error: mutable key type | ||
--> $DIR/mut_key.rs:70:5 | ||
| | ||
LL | let _map = HashMap::<Cell<usize>, usize>::new(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: mutable key type | ||
--> $DIR/mut_key.rs:71:5 | ||
| | ||
LL | let _map = HashMap::<&mut Cell<usize>, usize>::new(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: mutable key type | ||
--> $DIR/mut_key.rs:72:5 | ||
| | ||
LL | let _map = HashMap::<&mut usize, usize>::new(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: mutable key type | ||
--> $DIR/mut_key.rs:74:5 | ||
| | ||
LL | let _map = HashMap::<Vec<Cell<usize>>, usize>::new(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: mutable key type | ||
--> $DIR/mut_key.rs:75:5 | ||
| | ||
LL | let _map = HashMap::<BTreeMap<Cell<usize>, ()>, usize>::new(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: mutable key type | ||
--> $DIR/mut_key.rs:76:5 | ||
| | ||
LL | let _map = HashMap::<BTreeMap<(), Cell<usize>>, usize>::new(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: mutable key type | ||
--> $DIR/mut_key.rs:77:5 | ||
| | ||
LL | let _map = HashMap::<BTreeSet<Cell<usize>>, usize>::new(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: mutable key type | ||
--> $DIR/mut_key.rs:78:5 | ||
| | ||
LL | let _map = HashMap::<Option<Cell<usize>>, usize>::new(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: mutable key type | ||
--> $DIR/mut_key.rs:79:5 | ||
| | ||
LL | let _map = HashMap::<Option<Vec<Cell<usize>>>, usize>::new(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: mutable key type | ||
--> $DIR/mut_key.rs:80:5 | ||
| | ||
LL | let _map = HashMap::<Result<&mut usize, ()>, usize>::new(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: mutable key type | ||
--> $DIR/mut_key.rs:82:5 | ||
| | ||
LL | let _map = HashMap::<Box<Cell<usize>>, usize>::new(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: mutable key type | ||
--> $DIR/mut_key.rs:83:5 | ||
| | ||
LL | let _map = HashMap::<Rc<Cell<usize>>, usize>::new(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: mutable key type | ||
--> $DIR/mut_key.rs:84:5 | ||
| | ||
LL | let _map = HashMap::<Arc<Cell<usize>>, usize>::new(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 17 previous errors | ||
|