Use nohash_hasher, rm comment
This commit is contained in:
parent
7e1992a0d9
commit
85dd7b22b4
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -917,7 +917,7 @@ version = "0.0.0"
|
||||
name = "line-index"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"non-hash",
|
||||
"nohash-hasher",
|
||||
"text-size",
|
||||
]
|
||||
|
||||
@ -1064,8 +1064,10 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "non-hash"
|
||||
version = "0.1.0"
|
||||
name = "nohash-hasher"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451"
|
||||
|
||||
[[package]]
|
||||
name = "notify"
|
||||
@ -1706,7 +1708,7 @@ dependencies = [
|
||||
"backtrace",
|
||||
"libc",
|
||||
"miow",
|
||||
"non-hash",
|
||||
"nohash-hasher",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
|
@ -74,10 +74,12 @@ toolchain = { path = "./crates/toolchain", version = "0.0.0" }
|
||||
tt = { path = "./crates/tt", version = "0.0.0" }
|
||||
vfs-notify = { path = "./crates/vfs-notify", version = "0.0.0" }
|
||||
vfs = { path = "./crates/vfs", version = "0.0.0" }
|
||||
line-index = { version = "0.1.0", path = "./lib/line-index" }
|
||||
|
||||
# non-local crates
|
||||
smallvec = { version = "1.10.0", features = ["const_new", "union", "const_generics"] }
|
||||
smol_str = "0.2.0"
|
||||
nohash-hasher = "0.2.0"
|
||||
# the following crates are pinned to prevent us from pulling in syn 2 until all our dependencies have moved
|
||||
serde = { version = "=1.0.156", features = ["derive"] }
|
||||
serde_json = "1.0.94"
|
||||
|
@ -37,8 +37,7 @@ text-edit.workspace = true
|
||||
# something from some `hir-xxx` subpackage, reexport the API via `hir`.
|
||||
hir.workspace = true
|
||||
|
||||
# used to be a module, turned into its own library
|
||||
line-index = { version = "0.1.0", path = "../../lib/line-index" }
|
||||
line-index.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
expect-test = "1.4.0"
|
||||
|
@ -15,7 +15,7 @@ doctest = false
|
||||
libc = "0.2.135"
|
||||
backtrace = { version = "0.3.65", optional = true }
|
||||
always-assert = { version = "0.1.2", features = ["log"] }
|
||||
non-hash = { version = "0.1.0", path = "../../lib/non-hash" }
|
||||
nohash-hasher.workspace = true
|
||||
# Think twice before adding anything here
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
|
5
crates/stdx/src/hash.rs
Normal file
5
crates/stdx/src/hash.rs
Normal file
@ -0,0 +1,5 @@
|
||||
//! Re-exports from [`nohash_hasher`].
|
||||
|
||||
pub use nohash_hasher::IntMap as NoHashHashMap;
|
||||
pub use nohash_hasher::IntSet as NoHashHashSet;
|
||||
pub use nohash_hasher::IsEnabled;
|
@ -11,9 +11,9 @@
|
||||
pub mod panic_context;
|
||||
pub mod non_empty_vec;
|
||||
pub mod rand;
|
||||
pub mod hash;
|
||||
|
||||
pub use always_assert::{always, never};
|
||||
pub use non_hash as hash;
|
||||
|
||||
#[inline(always)]
|
||||
pub fn is_ci() -> bool {
|
||||
|
@ -62,7 +62,8 @@
|
||||
#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
|
||||
pub struct FileId(pub u32);
|
||||
|
||||
impl stdx::hash::NoHashHashable for FileId {}
|
||||
/// safe because `FileId` is a newtype of `u32`
|
||||
impl stdx::hash::IsEnabled for FileId {}
|
||||
|
||||
/// Storage for all files read by rust-analyzer.
|
||||
///
|
||||
|
@ -3,9 +3,9 @@ name = "line-index"
|
||||
version = "0.1.0"
|
||||
description = "Maps flat `TextSize` offsets into `(line, column)` representation."
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/rust-lang/rust-analyzer/tree/master/lib/non-hash"
|
||||
repository = "https://github.com/rust-lang/rust-analyzer/tree/master/lib/line-index"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
text-size = "1"
|
||||
non-hash = { version = "0.1.0", path = "../non-hash" }
|
||||
nohash-hasher.workspace = true
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
use std::{iter, mem};
|
||||
|
||||
use non_hash::NoHashHashMap;
|
||||
use nohash_hasher::IntMap as NoHashHashMap;
|
||||
use text_size::{TextRange, TextSize};
|
||||
|
||||
/// Maps flat [`TextSize`] offsets into `(line, column)` representation.
|
||||
|
@ -1,7 +0,0 @@
|
||||
[package]
|
||||
name = "non-hash"
|
||||
version = "0.1.0"
|
||||
description = "A non-hashing `Hasher` implementation."
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/rust-lang/rust-analyzer/tree/master/lib/non-hash"
|
||||
edition = "2021"
|
@ -1,104 +0,0 @@
|
||||
//! A non-hashing [`Hasher`] implementation.
|
||||
|
||||
#![deny(clippy::pedantic, missing_debug_implementations, missing_docs, rust_2018_idioms)]
|
||||
|
||||
use std::{
|
||||
hash::{BuildHasher, Hasher},
|
||||
marker::PhantomData,
|
||||
};
|
||||
|
||||
/// A [`std::collections::HashMap`] with [`NoHashHasherBuilder`].
|
||||
pub type NoHashHashMap<K, V> = std::collections::HashMap<K, V, NoHashHasherBuilder<K>>;
|
||||
|
||||
/// A [`std::collections::HashSet`] with [`NoHashHasherBuilder`].
|
||||
pub type NoHashHashSet<K> = std::collections::HashSet<K, NoHashHasherBuilder<K>>;
|
||||
|
||||
/// A hasher builder for [`NoHashHasher`].
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub struct NoHashHasherBuilder<T>(PhantomData<T>);
|
||||
|
||||
impl<T> Default for NoHashHasherBuilder<T> {
|
||||
fn default() -> Self {
|
||||
Self(PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
/// Types for which an acceptable hash function is to return itself.
|
||||
///
|
||||
/// This trait is implemented by sufficiently-small integer types. It should only be implemented for
|
||||
/// foreign types that are newtypes of these types. If it is implemented on more complex types,
|
||||
/// hashing will panic.
|
||||
pub trait NoHashHashable {}
|
||||
|
||||
impl NoHashHashable for u8 {}
|
||||
impl NoHashHashable for u16 {}
|
||||
impl NoHashHashable for u32 {}
|
||||
impl NoHashHashable for u64 {}
|
||||
impl NoHashHashable for usize {}
|
||||
|
||||
impl NoHashHashable for i8 {}
|
||||
impl NoHashHashable for i16 {}
|
||||
impl NoHashHashable for i32 {}
|
||||
impl NoHashHashable for i64 {}
|
||||
impl NoHashHashable for isize {}
|
||||
|
||||
/// A hasher for [`NoHashHashable`] types.
|
||||
#[derive(Debug)]
|
||||
pub struct NoHashHasher(u64);
|
||||
|
||||
impl<T: NoHashHashable> BuildHasher for NoHashHasherBuilder<T> {
|
||||
type Hasher = NoHashHasher;
|
||||
fn build_hasher(&self) -> Self::Hasher {
|
||||
NoHashHasher(0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Hasher for NoHashHasher {
|
||||
fn finish(&self) -> u64 {
|
||||
self.0
|
||||
}
|
||||
|
||||
fn write(&mut self, _: &[u8]) {
|
||||
unimplemented!("NoHashHasher should only be used for hashing sufficiently-small integer types and their newtypes")
|
||||
}
|
||||
|
||||
fn write_u8(&mut self, i: u8) {
|
||||
self.0 = i as u64;
|
||||
}
|
||||
|
||||
fn write_u16(&mut self, i: u16) {
|
||||
self.0 = i as u64;
|
||||
}
|
||||
|
||||
fn write_u32(&mut self, i: u32) {
|
||||
self.0 = i as u64;
|
||||
}
|
||||
|
||||
fn write_u64(&mut self, i: u64) {
|
||||
self.0 = i;
|
||||
}
|
||||
|
||||
fn write_usize(&mut self, i: usize) {
|
||||
self.0 = i as u64;
|
||||
}
|
||||
|
||||
fn write_i8(&mut self, i: i8) {
|
||||
self.0 = i as u64;
|
||||
}
|
||||
|
||||
fn write_i16(&mut self, i: i16) {
|
||||
self.0 = i as u64;
|
||||
}
|
||||
|
||||
fn write_i32(&mut self, i: i32) {
|
||||
self.0 = i as u64;
|
||||
}
|
||||
|
||||
fn write_i64(&mut self, i: i64) {
|
||||
self.0 = i as u64;
|
||||
}
|
||||
|
||||
fn write_isize(&mut self, i: isize) {
|
||||
self.0 = i as u64;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user