Skip to content

Commit

Permalink
add tests for type-aliased hash types
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacherr committed Nov 13, 2023
1 parent 938984a commit f8ea496
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
17 changes: 16 additions & 1 deletion tests/ui/iter_over_hash_type.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
//@aux-build:proc_macros.rs

#![feature(rustc_private)]
#![warn(clippy::iter_over_hash_type)]
use std::collections::{HashMap, HashSet};

extern crate rustc_data_structures;

extern crate proc_macros;

fn main() {
let mut hash_set = HashSet::<i32>::new();
let mut hash_map = HashMap::<i32, i32>::new();
let mut fx_hash_map = rustc_data_structures::fx::FxHashMap::<i32, i32>::default();
let mut fx_hash_set = rustc_data_structures::fx::FxHashMap::<i32, i32>::default();
let vec = Vec::<i32>::new();

// test hashset
for x in &hash_set {
let _ = x;
}
Expand All @@ -22,6 +27,8 @@ fn main() {
for x in hash_set.drain() {
let _ = x;
}

// test hashmap
for (x, y) in &hash_map {
let _ = (x, y);
}
Expand All @@ -44,6 +51,14 @@ fn main() {
let _ = x;
}

// test type-aliased hashers
for x in fx_hash_set {
let _ = x;
}
for x in fx_hash_map {
let _ = x;
}

// shouldnt fire
for x in &vec {
let _ = x;
Expand Down
40 changes: 28 additions & 12 deletions tests/ui/iter_over_hash_type.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: iteration over unordered hash-based type
--> $DIR/iter_over_hash_type.rs:13:5
--> $DIR/iter_over_hash_type.rs:18:5
|
LL | / for x in &hash_set {
LL | | let _ = x;
Expand All @@ -10,84 +10,100 @@ LL | | }
= help: to override `-D warnings` add `#[allow(clippy::iter_over_hash_type)]`

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

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

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

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

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

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

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

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

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

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

error: aborting due to 11 previous errors
error: iteration over unordered hash-based type
--> $DIR/iter_over_hash_type.rs:55:5
|
LL | / for x in fx_hash_set {
LL | | let _ = x;
LL | | }
| |_____^

error: iteration over unordered hash-based type
--> $DIR/iter_over_hash_type.rs:58:5
|
LL | / for x in fx_hash_map {
LL | | let _ = x;
LL | | }
| |_____^

error: aborting due to 13 previous errors

0 comments on commit f8ea496

Please sign in to comment.