Skip to content

Commit a09df2c

Browse files
author
Jorge Aparicio
committed
impl Hash for arrays
closes #21402 cc #15294
1 parent 54c9a46 commit a09df2c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/libcore/array.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use clone::Clone;
1818
use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
1919
use fmt;
20+
use hash::{Hash, Hasher, self};
2021
use marker::Copy;
2122
use ops::{Deref, FullRange};
2223
use option::Option;
@@ -32,6 +33,12 @@ macro_rules! array_impls {
3233
}
3334
}
3435

36+
impl<S: hash::Writer + Hasher, T: Hash<S>> Hash<S> for [T; $N] {
37+
fn hash(&self, state: &mut S) {
38+
Hash::hash(&self[], state)
39+
}
40+
}
41+
3542
#[unstable = "waiting for Show to stabilize"]
3643
impl<T:fmt::Show> fmt::Show for [T; $N] {
3744
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {

src/test/run-pass/issue-21402.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[derive(Hash)]
12+
struct Foo {
13+
a: Vec<bool>,
14+
b: (bool, bool),
15+
c: [bool; 2],
16+
}
17+
18+
fn main() {}

0 commit comments

Comments
 (0)