Skip to content

Commit f8ea496

Browse files
committed
add tests for type-aliased hash types
1 parent 938984a commit f8ea496

File tree

2 files changed

+44
-13
lines changed

2 files changed

+44
-13
lines changed

tests/ui/iter_over_hash_type.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
//@aux-build:proc_macros.rs
2-
2+
#![feature(rustc_private)]
33
#![warn(clippy::iter_over_hash_type)]
44
use std::collections::{HashMap, HashSet};
55

6+
extern crate rustc_data_structures;
7+
68
extern crate proc_macros;
79

810
fn main() {
911
let mut hash_set = HashSet::<i32>::new();
1012
let mut hash_map = HashMap::<i32, i32>::new();
13+
let mut fx_hash_map = rustc_data_structures::fx::FxHashMap::<i32, i32>::default();
14+
let mut fx_hash_set = rustc_data_structures::fx::FxHashMap::<i32, i32>::default();
1115
let vec = Vec::<i32>::new();
1216

17+
// test hashset
1318
for x in &hash_set {
1419
let _ = x;
1520
}
@@ -22,6 +27,8 @@ fn main() {
2227
for x in hash_set.drain() {
2328
let _ = x;
2429
}
30+
31+
// test hashmap
2532
for (x, y) in &hash_map {
2633
let _ = (x, y);
2734
}
@@ -44,6 +51,14 @@ fn main() {
4451
let _ = x;
4552
}
4653

54+
// test type-aliased hashers
55+
for x in fx_hash_set {
56+
let _ = x;
57+
}
58+
for x in fx_hash_map {
59+
let _ = x;
60+
}
61+
4762
// shouldnt fire
4863
for x in &vec {
4964
let _ = x;

tests/ui/iter_over_hash_type.stderr

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: iteration over unordered hash-based type
2-
--> $DIR/iter_over_hash_type.rs:13:5
2+
--> $DIR/iter_over_hash_type.rs:18:5
33
|
44
LL | / for x in &hash_set {
55
LL | | let _ = x;
@@ -10,84 +10,100 @@ LL | | }
1010
= help: to override `-D warnings` add `#[allow(clippy::iter_over_hash_type)]`
1111

1212
error: iteration over unordered hash-based type
13-
--> $DIR/iter_over_hash_type.rs:16:5
13+
--> $DIR/iter_over_hash_type.rs:21:5
1414
|
1515
LL | / for x in hash_set.iter() {
1616
LL | | let _ = x;
1717
LL | | }
1818
| |_____^
1919

2020
error: iteration over unordered hash-based type
21-
--> $DIR/iter_over_hash_type.rs:19:5
21+
--> $DIR/iter_over_hash_type.rs:24:5
2222
|
2323
LL | / for x in hash_set.clone() {
2424
LL | | let _ = x;
2525
LL | | }
2626
| |_____^
2727

2828
error: iteration over unordered hash-based type
29-
--> $DIR/iter_over_hash_type.rs:22:5
29+
--> $DIR/iter_over_hash_type.rs:27:5
3030
|
3131
LL | / for x in hash_set.drain() {
3232
LL | | let _ = x;
3333
LL | | }
3434
| |_____^
3535

3636
error: iteration over unordered hash-based type
37-
--> $DIR/iter_over_hash_type.rs:25:5
37+
--> $DIR/iter_over_hash_type.rs:32:5
3838
|
3939
LL | / for (x, y) in &hash_map {
4040
LL | | let _ = (x, y);
4141
LL | | }
4242
| |_____^
4343

4444
error: iteration over unordered hash-based type
45-
--> $DIR/iter_over_hash_type.rs:28:5
45+
--> $DIR/iter_over_hash_type.rs:35:5
4646
|
4747
LL | / for x in hash_map.keys() {
4848
LL | | let _ = x;
4949
LL | | }
5050
| |_____^
5151

5252
error: iteration over unordered hash-based type
53-
--> $DIR/iter_over_hash_type.rs:31:5
53+
--> $DIR/iter_over_hash_type.rs:38:5
5454
|
5555
LL | / for x in hash_map.values() {
5656
LL | | let _ = x;
5757
LL | | }
5858
| |_____^
5959

6060
error: iteration over unordered hash-based type
61-
--> $DIR/iter_over_hash_type.rs:34:5
61+
--> $DIR/iter_over_hash_type.rs:41:5
6262
|
6363
LL | / for x in hash_map.values_mut() {
6464
LL | | *x += 1;
6565
LL | | }
6666
| |_____^
6767

6868
error: iteration over unordered hash-based type
69-
--> $DIR/iter_over_hash_type.rs:37:5
69+
--> $DIR/iter_over_hash_type.rs:44:5
7070
|
7171
LL | / for x in hash_map.iter() {
7272
LL | | let _ = x;
7373
LL | | }
7474
| |_____^
7575

7676
error: iteration over unordered hash-based type
77-
--> $DIR/iter_over_hash_type.rs:40:5
77+
--> $DIR/iter_over_hash_type.rs:47:5
7878
|
7979
LL | / for x in hash_map.clone() {
8080
LL | | let _ = x;
8181
LL | | }
8282
| |_____^
8383

8484
error: iteration over unordered hash-based type
85-
--> $DIR/iter_over_hash_type.rs:43:5
85+
--> $DIR/iter_over_hash_type.rs:50:5
8686
|
8787
LL | / for x in hash_map.drain() {
8888
LL | | let _ = x;
8989
LL | | }
9090
| |_____^
9191

92-
error: aborting due to 11 previous errors
92+
error: iteration over unordered hash-based type
93+
--> $DIR/iter_over_hash_type.rs:55:5
94+
|
95+
LL | / for x in fx_hash_set {
96+
LL | | let _ = x;
97+
LL | | }
98+
| |_____^
99+
100+
error: iteration over unordered hash-based type
101+
--> $DIR/iter_over_hash_type.rs:58:5
102+
|
103+
LL | / for x in fx_hash_map {
104+
LL | | let _ = x;
105+
LL | | }
106+
| |_____^
107+
108+
error: aborting due to 13 previous errors
93109

0 commit comments

Comments
 (0)