Skip to content

Instantly share code, notes, and snippets.

@farnoy
Last active December 27, 2015 18:39
Show Gist options
  • Save farnoy/7371366 to your computer and use it in GitHub Desktop.
Save farnoy/7371366 to your computer and use it in GitHub Desktop.
use std::hashmap::HashMap;
trait Test {}
impl Test for uint {}
fn main() {
let a: &uint = &15;
let thing: &Test = a as &Test;
let mut map: HashMap<uint, &Test> = HashMap::new();
map.insert(0, thing);
println!("{:?}", a);
let a: &uint = unsafe { std::cast::transmute(map.find(&0).unwrap()) };
// doing `transmute(thing)` produces:
// error: transmute called on types with different sizes: &Test<no-bounds> (128 bits) to &uint (64 bits)
println!("{:?}", a);
}
// Desired output:
// &15u
// &15u
// Actual:
// &15u
// &6414600u
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment