Skip to content

Instantly share code, notes, and snippets.

@DaGenix
Last active December 27, 2015 21:19
Show Gist options
  • Save DaGenix/7390603 to your computer and use it in GitHub Desktop.
Save DaGenix/7390603 to your computer and use it in GitHub Desktop.
type_id collision
use std::hash;
use std::hash::Streaming;
// I believe that this pretty much the same thing as hash_crate_independent() in ty.rs
// for a ty_struct on a 64-bit platform
fn hash_struct(local_hash: &str, node: u64) -> u64 {
let mut state = hash::default_state();
state.input([18]);
state.input(local_hash.as_bytes());
do node.iter_bytes(true) |bytes| { state.input(bytes); true };
state.result_u64()
}
fn main() {
// This represents two structures with different node values from a crate with a local_hash value
// of "local" that end up getting the same hash and thus, I think, the same type_id
assert!(hash_struct("local", 0x9e02c8943c336302) == hash_struct("local", 0x366a806b1d5f1b2));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment