Skip to content

Commit 833a4d9

Browse files
InternedString: Make Hash and Eq behave consistently.
1 parent 0451083 commit 833a4d9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/libsyntax_pos/symbol.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use GLOBALS;
1818
use serialize::{Decodable, Decoder, Encodable, Encoder};
1919
use std::collections::HashMap;
2020
use std::fmt;
21+
use std::hash::{Hash, Hasher};
2122
use std::ops::Deref;
2223

2324
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
@@ -351,11 +352,17 @@ fn with_interner<T, F: FnOnce(&mut Interner) -> T>(f: F) -> T {
351352
/// destroyed. In particular, they must not access string contents. This can
352353
/// be fixed in the future by just leaking all strings until thread death
353354
/// somehow.
354-
#[derive(Clone, Copy, Hash, PartialOrd, Eq, Ord)]
355+
#[derive(Clone, Copy, PartialOrd, Eq, Ord)]
355356
pub struct InternedString {
356357
string: &'static str,
357358
}
358359

360+
impl Hash for InternedString {
361+
fn hash<H: Hasher>(&self, state: &mut H) {
362+
self.as_ptr().hash(state);
363+
}
364+
}
365+
359366
impl<U: ?Sized> ::std::convert::AsRef<U> for InternedString where str: ::std::convert::AsRef<U> {
360367
fn as_ref(&self) -> &U {
361368
self.string.as_ref()

0 commit comments

Comments
 (0)