servo: Merge #7523 - Fix up some unnecessary uses of `unsafe` (from eefriedman:unnecessary-unsafe); r=SimonSapin
authorEli Friedman <eli.friedman@gmail.com>
Wed, 09 Sep 2015 00:05:17 -0600
changeset 383766 d8401655b47b44a84a4fa4c9367553b3ba966e26
parent 383765 3609a565b6b4438cbc06e7ded42e46b891437ae3
child 383767 7200ee4048a8d80e2ea1cb96f3a115a77714e691
push id7198
push userjlorenzo@mozilla.com
push dateTue, 18 Apr 2017 12:07:49 +0000
treeherdermozilla-beta@d57aa49c3948 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersSimonSapin
servo: Merge #7523 - Fix up some unnecessary uses of `unsafe` (from eefriedman:unnecessary-unsafe); r=SimonSapin Source-Repo: https://github.com/servo/servo Source-Revision: be9a9ffda10fa2c50b13f79dabd49255f29f12f6
servo/components/gfx/font.rs
servo/components/gfx/font_cache_task.rs
servo/components/layout/css/matching.rs
servo/components/net/http_loader.rs
servo/components/script/parse/html.rs
servo/components/util/persistent_list.rs
servo/components/util/tid.rs
servo/ports/cef/browser_host.rs
--- a/servo/components/gfx/font.rs
+++ b/servo/components/gfx/font.rs
@@ -1,19 +1,18 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 use euclid::{Point2D, Rect, Size2D};
 use smallvec::SmallVec;
 use std::borrow::ToOwned;
 use std::cell::RefCell;
-use std::mem;
 use std::rc::Rc;
-use std::slice;
+use std::str;
 use std::sync::Arc;
 use style::computed_values::{font_stretch, font_variant, font_weight};
 use style::properties::style_structs::Font as FontStyle;
 use util::cache::HashCache;
 
 use font_template::FontTemplateDescriptor;
 use platform::font::{FontHandle, FontTable};
 use platform::font_context::FontContextHandle;
@@ -51,22 +50,21 @@ pub type FractionalPixel = f64;
 pub type FontTableTag = u32;
 
 pub trait FontTableTagConversions {
     fn tag_to_str(&self) -> String;
 }
 
 impl FontTableTagConversions for FontTableTag {
     fn tag_to_str(&self) -> String {
-        unsafe {
-            let pointer = mem::transmute::<&u32, *const u8>(self);
-            let mut bytes = slice::from_raw_parts(pointer, 4).to_vec();
-            bytes.reverse();
-            String::from_utf8_unchecked(bytes)
-        }
+        let bytes = [(self >> 24) as u8,
+                     (self >> 16) as u8,
+                     (self >>  8) as u8,
+                     (self >>  0) as u8];
+        str::from_utf8(&bytes).unwrap().to_owned()
     }
 }
 
 pub trait FontTableMethods {
     fn with_buffer<F>(&self, F) where F: FnOnce(*const u8, usize);
 }
 
 #[derive(Clone, Debug, Deserialize, Serialize)]
--- a/servo/components/gfx/font_cache_task.rs
+++ b/servo/components/gfx/font_cache_task.rs
@@ -76,25 +76,21 @@ impl FontFamily {
 /// Commands that the FontContext sends to the font cache task.
 pub enum Command {
     GetFontTemplate(String, FontTemplateDescriptor, Sender<Reply>),
     GetLastResortFontTemplate(FontTemplateDescriptor, Sender<Reply>),
     AddWebFont(Atom, Source, Sender<()>),
     Exit(Sender<()>),
 }
 
-unsafe impl Send for Command {}
-
 /// Reply messages sent from the font cache task to the FontContext caller.
 pub enum Reply {
     GetFontTemplateReply(Option<Arc<FontTemplateData>>),
 }
 
-unsafe impl Send for Reply {}
-
 /// The font cache task itself. It maintains a list of reference counted
 /// font templates that are currently in use.
 struct FontCache {
     port: Receiver<Command>,
     generic_fonts: HashMap<LowercaseString, LowercaseString>,
     local_families: HashMap<LowercaseString, FontFamily>,
     web_families: HashMap<LowercaseString, FontFamily>,
     font_context: FontContextHandle,
--- a/servo/components/layout/css/matching.rs
+++ b/servo/components/layout/css/matching.rs
@@ -18,23 +18,22 @@ use script::dom::node::NodeTypeId;
 use script::layout_interface::Animation;
 use selectors::bloom::BloomFilter;
 use selectors::matching::{CommonStyleAffectingAttributeMode, CommonStyleAffectingAttributes};
 use selectors::matching::{common_style_affecting_attributes, rare_style_affecting_attributes};
 use selectors::parser::PseudoElement;
 use selectors::{Element};
 use std::borrow::ToOwned;
 use std::hash::{Hash, Hasher};
-use std::mem;
 use std::slice::Iter;
 use std::sync::Arc;
 use std::sync::mpsc::Sender;
 use string_cache::{Atom, Namespace};
 use style::node::TElementAttributes;
-use style::properties::{ComputedValues, cascade};
+use style::properties::{ComputedValues, cascade, PropertyDeclaration};
 use style::selector_matching::{Stylist, DeclarationBlock};
 use util::arc_ptr_eq;
 use util::cache::{LRUCache, SimpleHashCache};
 use util::opts;
 use util::vec::ForgetfulSink;
 
 pub struct ApplicableDeclarations {
     pub normal: SmallVec<[DeclarationBlock; 16]>,
@@ -123,19 +122,19 @@ impl<'a> PartialEq<ApplicableDeclaration
         let other_as_query = ApplicableDeclarationsCacheQuery::new(&other.declarations);
         self.eq(&other_as_query)
     }
 }
 
 impl<'a> Hash for ApplicableDeclarationsCacheQuery<'a> {
     fn hash<H: Hasher>(&self, state: &mut H) {
         for declaration in self.declarations {
-            let ptr: usize = unsafe {
-                mem::transmute_copy(declaration)
-            };
+            // Each declaration contians an Arc, which is a stable
+            // pointer; we use that for hashing and equality.
+            let ptr = &*declaration.declarations as *const Vec<PropertyDeclaration>;
             ptr.hash(state);
         }
     }
 }
 
 static APPLICABLE_DECLARATIONS_CACHE_SIZE: usize = 32;
 
 pub struct ApplicableDeclarationsCache {
--- a/servo/components/net/http_loader.rs
+++ b/servo/components/net/http_loader.rs
@@ -100,17 +100,17 @@ enum ReadResult {
     EOF,
 }
 
 fn read_block<R: Read>(reader: &mut R) -> Result<ReadResult, ()> {
     let mut buf = vec![0; 1024];
 
     match reader.read(&mut buf) {
         Ok(len) if len > 0 => {
-            unsafe { buf.set_len(len); }
+            buf.truncate(len);
             Ok(ReadResult::Payload(buf))
         }
         Ok(_) => Ok(ReadResult::EOF),
         Err(_) => Err(()),
     }
 }
 
 fn inner_url(url: &Url) -> Url {
--- a/servo/components/script/parse/html.rs
+++ b/servo/components/script/parse/html.rs
@@ -1,13 +1,13 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#![allow(unsafe_code, unrooted_must_root)]
+#![allow(unrooted_must_root)]
 
 use document_loader::DocumentLoader;
 use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
 use dom::bindings::codegen::Bindings::HTMLTemplateElementBinding::HTMLTemplateElementMethods;
 use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
 use dom::bindings::codegen::InheritTypes::{CharacterDataCast, DocumentTypeCast};
 use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLFormElementDerived};
 use dom::bindings::codegen::InheritTypes::{HTMLScriptElementCast, HTMLTemplateElementCast};
--- a/servo/components/util/persistent_list.rs
+++ b/servo/components/util/persistent_list.rs
@@ -1,15 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 //! A persistent, thread-safe singly-linked list.
 
-use std::mem;
 use std::sync::Arc;
 
 pub struct PersistentList<T> {
     head: PersistentListLink<T>,
     length: usize,
 }
 
 struct PersistentListEntry<T> {
@@ -76,25 +75,17 @@ pub struct PersistentListIterator<'a,T> 
 
 impl<'a, T> Iterator for PersistentListIterator<'a, T> where T: Send + Sync + 'static {
     type Item = &'a T;
 
     #[inline]
     fn next(&mut self) -> Option<&'a T> {
         let entry = match self.entry {
             None => return None,
-            Some(entry) => {
-                // This `transmute` is necessary to ensure that the lifetimes of the next entry and
-                // this entry match up; the compiler doesn't know this, but we do because of the
-                // reference counting behavior of `Arc`.
-                unsafe {
-                    mem::transmute::<&'a PersistentListEntry<T>,
-                                     &'static PersistentListEntry<T>>(entry)
-                }
-            }
+            Some(entry) => entry,
         };
         let value = &entry.value;
         self.entry = match entry.next {
             None => None,
             Some(ref entry) => Some(&**entry),
         };
         Some(value)
     }
--- a/servo/components/util/tid.rs
+++ b/servo/components/util/tid.rs
@@ -1,26 +1,26 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 use std::cell::RefCell;
 use std::rc::Rc;
 use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
 
-static mut next_tid: AtomicUsize = ATOMIC_USIZE_INIT;
+static NEXT_TID: AtomicUsize = ATOMIC_USIZE_INIT;
 
 thread_local!(static TASK_LOCAL_TID: Rc<RefCell<Option<usize>>> = Rc::new(RefCell::new(None)));
 
 /// Every task gets one, that's unique.
 pub fn tid() -> usize {
     TASK_LOCAL_TID.with(|ref k| {
         let ret =
             match *k.borrow() {
-                None => unsafe { next_tid.fetch_add(1, Ordering::SeqCst) },
+                None => NEXT_TID.fetch_add(1, Ordering::SeqCst),
                 Some(x) => x,
             };
 
         *k.borrow_mut() = Some(ret);
 
         ret
     })
 }
--- a/servo/ports/cef/browser_host.rs
+++ b/servo/ports/cef/browser_host.rs
@@ -12,227 +12,225 @@ use wrappers::CefWrap;
 
 use compositing::windowing::{WindowEvent, MouseWindowEvent};
 use euclid::point::Point2D;
 use euclid::size::Size2D;
 use libc::{c_double, c_int};
 use msg::constellation_msg::{self, KeyModifiers, KeyState};
 use script_traits::MouseButton;
 use std::cell::{Cell, RefCell};
-use std::intrinsics;
-use std::mem::transmute;
 
 pub struct ServoCefBrowserHost {
     /// A reference to the browser.
     pub browser: RefCell<Option<CefBrowser>>,
     /// A reference to the client.
     pub client: CefClient,
     /// flag for return value of prepare_for_composite
     pub composite_ok: Cell<bool>,
 }
 
 // From blink ui/events/keycodes/keyboard_codes_posix.h.
 #[allow(dead_code)]
-enum KeyboardCode {
-  VKEY_BACK = 0x08,
-  VKEY_TAB = 0x09,
-  VKEY_BACKTAB = 0x0A,
-  VKEY_CLEAR = 0x0C,
-  VKEY_RETURN = 0x0D,
-  VKEY_SHIFT = 0x10,
-  VKEY_CONTROL = 0x11,
-  VKEY_MENU = 0x12,
-  VKEY_PAUSE = 0x13,
-  VKEY_CAPITAL = 0x14,
-  VKEY_KANA = 0x15,
-  //VKEY_HANGUL = 0x15,
-  VKEY_JUNJA = 0x17,
-  VKEY_FINAL = 0x18,
-  VKEY_HANJA = 0x19,
-  //VKEY_KANJI = 0x19,
-  VKEY_ESCAPE = 0x1B,
-  VKEY_CONVERT = 0x1C,
-  VKEY_NONCONVERT = 0x1D,
-  VKEY_ACCEPT = 0x1E,
-  VKEY_MODECHANGE = 0x1F,
-  VKEY_SPACE = 0x20,
-  VKEY_PRIOR = 0x21,
-  VKEY_NEXT = 0x22,
-  VKEY_END = 0x23,
-  VKEY_HOME = 0x24,
-  VKEY_LEFT = 0x25,
-  VKEY_UP = 0x26,
-  VKEY_RIGHT = 0x27,
-  VKEY_DOWN = 0x28,
-  VKEY_SELECT = 0x29,
-  VKEY_PRINT = 0x2A,
-  VKEY_EXECUTE = 0x2B,
-  VKEY_SNAPSHOT = 0x2C,
-  VKEY_INSERT = 0x2D,
-  VKEY_DELETE = 0x2E,
-  VKEY_HELP = 0x2F,
-  VKEY_0 = 0x30,
-  VKEY_1 = 0x31,
-  VKEY_2 = 0x32,
-  VKEY_3 = 0x33,
-  VKEY_4 = 0x34,
-  VKEY_5 = 0x35,
-  VKEY_6 = 0x36,
-  VKEY_7 = 0x37,
-  VKEY_8 = 0x38,
-  VKEY_9 = 0x39,
-  VKEY_A = 0x41,
-  VKEY_B = 0x42,
-  VKEY_C = 0x43,
-  VKEY_D = 0x44,
-  VKEY_E = 0x45,
-  VKEY_F = 0x46,
-  VKEY_G = 0x47,
-  VKEY_H = 0x48,
-  VKEY_I = 0x49,
-  VKEY_J = 0x4A,
-  VKEY_K = 0x4B,
-  VKEY_L = 0x4C,
-  VKEY_M = 0x4D,
-  VKEY_N = 0x4E,
-  VKEY_O = 0x4F,
-  VKEY_P = 0x50,
-  VKEY_Q = 0x51,
-  VKEY_R = 0x52,
-  VKEY_S = 0x53,
-  VKEY_T = 0x54,
-  VKEY_U = 0x55,
-  VKEY_V = 0x56,
-  VKEY_W = 0x57,
-  VKEY_X = 0x58,
-  VKEY_Y = 0x59,
-  VKEY_Z = 0x5A,
-  VKEY_LWIN = 0x5B,
-  VKEY_RWIN = 0x5C,
-  VKEY_APPS = 0x5D,
-  VKEY_SLEEP = 0x5F,
-  VKEY_NUMPAD0 = 0x60,
-  VKEY_NUMPAD1 = 0x61,
-  VKEY_NUMPAD2 = 0x62,
-  VKEY_NUMPAD3 = 0x63,
-  VKEY_NUMPAD4 = 0x64,
-  VKEY_NUMPAD5 = 0x65,
-  VKEY_NUMPAD6 = 0x66,
-  VKEY_NUMPAD7 = 0x67,
-  VKEY_NUMPAD8 = 0x68,
-  VKEY_NUMPAD9 = 0x69,
-  VKEY_MULTIPLY = 0x6A,
-  VKEY_ADD = 0x6B,
-  VKEY_SEPARATOR = 0x6C,
-  VKEY_SUBTRACT = 0x6D,
-  VKEY_DECIMAL = 0x6E,
-  VKEY_DIVIDE = 0x6F,
-  VKEY_F1 = 0x70,
-  VKEY_F2 = 0x71,
-  VKEY_F3 = 0x72,
-  VKEY_F4 = 0x73,
-  VKEY_F5 = 0x74,
-  VKEY_F6 = 0x75,
-  VKEY_F7 = 0x76,
-  VKEY_F8 = 0x77,
-  VKEY_F9 = 0x78,
-  VKEY_F10 = 0x79,
-  VKEY_F11 = 0x7A,
-  VKEY_F12 = 0x7B,
-  VKEY_F13 = 0x7C,
-  VKEY_F14 = 0x7D,
-  VKEY_F15 = 0x7E,
-  VKEY_F16 = 0x7F,
-  VKEY_F17 = 0x80,
-  VKEY_F18 = 0x81,
-  VKEY_F19 = 0x82,
-  VKEY_F20 = 0x83,
-  VKEY_F21 = 0x84,
-  VKEY_F22 = 0x85,
-  VKEY_F23 = 0x86,
-  VKEY_F24 = 0x87,
-  VKEY_NUMLOCK = 0x90,
-  VKEY_SCROLL = 0x91,
-  VKEY_LSHIFT = 0xA0,
-  VKEY_RSHIFT = 0xA1,
-  VKEY_LCONTROL = 0xA2,
-  VKEY_RCONTROL = 0xA3,
-  VKEY_LMENU = 0xA4,
-  VKEY_RMENU = 0xA5,
-  VKEY_BROWSER_BACK = 0xA6,
-  VKEY_BROWSER_FORWARD = 0xA7,
-  VKEY_BROWSER_REFRESH = 0xA8,
-  VKEY_BROWSER_STOP = 0xA9,
-  VKEY_BROWSER_SEARCH = 0xAA,
-  VKEY_BROWSER_FAVORITES = 0xAB,
-  VKEY_BROWSER_HOME = 0xAC,
-  VKEY_VOLUME_MUTE = 0xAD,
-  VKEY_VOLUME_DOWN = 0xAE,
-  VKEY_VOLUME_UP = 0xAF,
-  VKEY_MEDIA_NEXT_TRACK = 0xB0,
-  VKEY_MEDIA_PREV_TRACK = 0xB1,
-  VKEY_MEDIA_STOP = 0xB2,
-  VKEY_MEDIA_PLAY_PAUSE = 0xB3,
-  VKEY_MEDIA_LAUNCH_MAIL = 0xB4,
-  VKEY_MEDIA_LAUNCH_MEDIA_SELECT = 0xB5,
-  VKEY_MEDIA_LAUNCH_APP1 = 0xB6,
-  VKEY_MEDIA_LAUNCH_APP2 = 0xB7,
-  VKEY_OEM_1 = 0xBA,
-  VKEY_OEM_PLUS = 0xBB,
-  VKEY_OEM_COMMA = 0xBC,
-  VKEY_OEM_MINUS = 0xBD,
-  VKEY_OEM_PERIOD = 0xBE,
-  VKEY_OEM_2 = 0xBF,
-  VKEY_OEM_3 = 0xC0,
-  VKEY_OEM_4 = 0xDB,
-  VKEY_OEM_5 = 0xDC,
-  VKEY_OEM_6 = 0xDD,
-  VKEY_OEM_7 = 0xDE,
-  VKEY_OEM_8 = 0xDF,
-  VKEY_OEM_102 = 0xE2,
-  VKEY_OEM_103 = 0xE3,  // GTV KEYCODE_MEDIA_REWIND
-  VKEY_OEM_104 = 0xE4,  // GTV KEYCODE_MEDIA_FAST_FORWARD
-  VKEY_PROCESSKEY = 0xE5,
-  VKEY_PACKET = 0xE7,
-  VKEY_DBE_SBCSCHAR = 0xF3,
-  VKEY_DBE_DBCSCHAR = 0xF4,
-  VKEY_ATTN = 0xF6,
-  VKEY_CRSEL = 0xF7,
-  VKEY_EXSEL = 0xF8,
-  VKEY_EREOF = 0xF9,
-  VKEY_PLAY = 0xFA,
-  VKEY_ZOOM = 0xFB,
-  VKEY_NONAME = 0xFC,
-  VKEY_PA1 = 0xFD,
-  VKEY_OEM_CLEAR = 0xFE,
-  VKEY_UNKNOWN = 0,
+#[allow(non_snake_case)]
+mod KeyboardCode {
+    pub const VKEY_BACK : u8 = 0x08;
+    pub const VKEY_TAB : u8 = 0x09;
+    pub const VKEY_BACKTAB : u8 = 0x0A;
+    pub const VKEY_CLEAR : u8 = 0x0C;
+    pub const VKEY_RETURN : u8 = 0x0D;
+    pub const VKEY_SHIFT : u8 = 0x10;
+    pub const VKEY_CONTROL : u8 = 0x11;
+    pub const VKEY_MENU : u8 = 0x12;
+    pub const VKEY_PAUSE : u8 = 0x13;
+    pub const VKEY_CAPITAL : u8 = 0x14;
+    pub const VKEY_KANA : u8 = 0x15;
+    //VKEY_HANGUL = 0x15,
+    pub const VKEY_JUNJA : u8 = 0x17;
+    pub const VKEY_FINAL : u8 = 0x18;
+    pub const VKEY_HANJA : u8 = 0x19;
+    //VKEY_KANJI = 0x19,
+    pub const VKEY_ESCAPE : u8 = 0x1B;
+    pub const VKEY_CONVERT : u8 = 0x1C;
+    pub const VKEY_NONCONVERT : u8 = 0x1D;
+    pub const VKEY_ACCEPT : u8 = 0x1E;
+    pub const VKEY_MODECHANGE : u8 = 0x1F;
+    pub const VKEY_SPACE : u8 = 0x20;
+    pub const VKEY_PRIOR : u8 = 0x21;
+    pub const VKEY_NEXT : u8 = 0x22;
+    pub const VKEY_END : u8 = 0x23;
+    pub const VKEY_HOME : u8 = 0x24;
+    pub const VKEY_LEFT : u8 = 0x25;
+    pub const VKEY_UP : u8 = 0x26;
+    pub const VKEY_RIGHT : u8 = 0x27;
+    pub const VKEY_DOWN : u8 = 0x28;
+    pub const VKEY_SELECT : u8 = 0x29;
+    pub const VKEY_PRINT : u8 = 0x2A;
+    pub const VKEY_EXECUTE : u8 = 0x2B;
+    pub const VKEY_SNAPSHOT : u8 = 0x2C;
+    pub const VKEY_INSERT : u8 = 0x2D;
+    pub const VKEY_DELETE : u8 = 0x2E;
+    pub const VKEY_HELP : u8 = 0x2F;
+    pub const VKEY_0 : u8 = 0x30;
+    pub const VKEY_1 : u8 = 0x31;
+    pub const VKEY_2 : u8 = 0x32;
+    pub const VKEY_3 : u8 = 0x33;
+    pub const VKEY_4 : u8 = 0x34;
+    pub const VKEY_5 : u8 = 0x35;
+    pub const VKEY_6 : u8 = 0x36;
+    pub const VKEY_7 : u8 = 0x37;
+    pub const VKEY_8 : u8 = 0x38;
+    pub const VKEY_9 : u8 = 0x39;
+    pub const VKEY_A : u8 = 0x41;
+    pub const VKEY_B : u8 = 0x42;
+    pub const VKEY_C : u8 = 0x43;
+    pub const VKEY_D : u8 = 0x44;
+    pub const VKEY_E : u8 = 0x45;
+    pub const VKEY_F : u8 = 0x46;
+    pub const VKEY_G : u8 = 0x47;
+    pub const VKEY_H : u8 = 0x48;
+    pub const VKEY_I : u8 = 0x49;
+    pub const VKEY_J : u8 = 0x4A;
+    pub const VKEY_K : u8 = 0x4B;
+    pub const VKEY_L : u8 = 0x4C;
+    pub const VKEY_M : u8 = 0x4D;
+    pub const VKEY_N : u8 = 0x4E;
+    pub const VKEY_O : u8 = 0x4F;
+    pub const VKEY_P : u8 = 0x50;
+    pub const VKEY_Q : u8 = 0x51;
+    pub const VKEY_R : u8 = 0x52;
+    pub const VKEY_S : u8 = 0x53;
+    pub const VKEY_T : u8 = 0x54;
+    pub const VKEY_U : u8 = 0x55;
+    pub const VKEY_V : u8 = 0x56;
+    pub const VKEY_W : u8 = 0x57;
+    pub const VKEY_X : u8 = 0x58;
+    pub const VKEY_Y : u8 = 0x59;
+    pub const VKEY_Z : u8 = 0x5A;
+    pub const VKEY_LWIN : u8 = 0x5B;
+    pub const VKEY_RWIN : u8 = 0x5C;
+    pub const VKEY_APPS : u8 = 0x5D;
+    pub const VKEY_SLEEP : u8 = 0x5F;
+    pub const VKEY_NUMPAD0 : u8 = 0x60;
+    pub const VKEY_NUMPAD1 : u8 = 0x61;
+    pub const VKEY_NUMPAD2 : u8 = 0x62;
+    pub const VKEY_NUMPAD3 : u8 = 0x63;
+    pub const VKEY_NUMPAD4 : u8 = 0x64;
+    pub const VKEY_NUMPAD5 : u8 = 0x65;
+    pub const VKEY_NUMPAD6 : u8 = 0x66;
+    pub const VKEY_NUMPAD7 : u8 = 0x67;
+    pub const VKEY_NUMPAD8 : u8 = 0x68;
+    pub const VKEY_NUMPAD9 : u8 = 0x69;
+    pub const VKEY_MULTIPLY : u8 = 0x6A;
+    pub const VKEY_ADD : u8 = 0x6B;
+    pub const VKEY_SEPARATOR : u8 = 0x6C;
+    pub const VKEY_SUBTRACT : u8 = 0x6D;
+    pub const VKEY_DECIMAL : u8 = 0x6E;
+    pub const VKEY_DIVIDE : u8 = 0x6F;
+    pub const VKEY_F1 : u8 = 0x70;
+    pub const VKEY_F2 : u8 = 0x71;
+    pub const VKEY_F3 : u8 = 0x72;
+    pub const VKEY_F4 : u8 = 0x73;
+    pub const VKEY_F5 : u8 = 0x74;
+    pub const VKEY_F6 : u8 = 0x75;
+    pub const VKEY_F7 : u8 = 0x76;
+    pub const VKEY_F8 : u8 = 0x77;
+    pub const VKEY_F9 : u8 = 0x78;
+    pub const VKEY_F10 : u8 = 0x79;
+    pub const VKEY_F11 : u8 = 0x7A;
+    pub const VKEY_F12 : u8 = 0x7B;
+    pub const VKEY_F13 : u8 = 0x7C;
+    pub const VKEY_F14 : u8 = 0x7D;
+    pub const VKEY_F15 : u8 = 0x7E;
+    pub const VKEY_F16 : u8 = 0x7F;
+    pub const VKEY_F17 : u8 = 0x80;
+    pub const VKEY_F18 : u8 = 0x81;
+    pub const VKEY_F19 : u8 = 0x82;
+    pub const VKEY_F20 : u8 = 0x83;
+    pub const VKEY_F21 : u8 = 0x84;
+    pub const VKEY_F22 : u8 = 0x85;
+    pub const VKEY_F23 : u8 = 0x86;
+    pub const VKEY_F24 : u8 = 0x87;
+    pub const VKEY_NUMLOCK : u8 = 0x90;
+    pub const VKEY_SCROLL : u8 = 0x91;
+    pub const VKEY_LSHIFT : u8 = 0xA0;
+    pub const VKEY_RSHIFT : u8 = 0xA1;
+    pub const VKEY_LCONTROL : u8 = 0xA2;
+    pub const VKEY_RCONTROL : u8 = 0xA3;
+    pub const VKEY_LMENU : u8 = 0xA4;
+    pub const VKEY_RMENU : u8 = 0xA5;
+    pub const VKEY_BROWSER_BACK : u8 = 0xA6;
+    pub const VKEY_BROWSER_FORWARD : u8 = 0xA7;
+    pub const VKEY_BROWSER_REFRESH : u8 = 0xA8;
+    pub const VKEY_BROWSER_STOP : u8 = 0xA9;
+    pub const VKEY_BROWSER_SEARCH : u8 = 0xAA;
+    pub const VKEY_BROWSER_FAVORITES : u8 = 0xAB;
+    pub const VKEY_BROWSER_HOME : u8 = 0xAC;
+    pub const VKEY_VOLUME_MUTE : u8 = 0xAD;
+    pub const VKEY_VOLUME_DOWN : u8 = 0xAE;
+    pub const VKEY_VOLUME_UP : u8 = 0xAF;
+    pub const VKEY_MEDIA_NEXT_TRACK : u8 = 0xB0;
+    pub const VKEY_MEDIA_PREV_TRACK : u8 = 0xB1;
+    pub const VKEY_MEDIA_STOP : u8 = 0xB2;
+    pub const VKEY_MEDIA_PLAY_PAUSE : u8 = 0xB3;
+    pub const VKEY_MEDIA_LAUNCH_MAIL : u8 = 0xB4;
+    pub const VKEY_MEDIA_LAUNCH_MEDIA_SELECT : u8 = 0xB5;
+    pub const VKEY_MEDIA_LAUNCH_APP1 : u8 = 0xB6;
+    pub const VKEY_MEDIA_LAUNCH_APP2 : u8 = 0xB7;
+    pub const VKEY_OEM_1 : u8 = 0xBA;
+    pub const VKEY_OEM_PLUS : u8 = 0xBB;
+    pub const VKEY_OEM_COMMA : u8 = 0xBC;
+    pub const VKEY_OEM_MINUS : u8 = 0xBD;
+    pub const VKEY_OEM_PERIOD : u8 = 0xBE;
+    pub const VKEY_OEM_2 : u8 = 0xBF;
+    pub const VKEY_OEM_3 : u8 = 0xC0;
+    pub const VKEY_OEM_4 : u8 = 0xDB;
+    pub const VKEY_OEM_5 : u8 = 0xDC;
+    pub const VKEY_OEM_6 : u8 = 0xDD;
+    pub const VKEY_OEM_7 : u8 = 0xDE;
+    pub const VKEY_OEM_8 : u8 = 0xDF;
+    pub const VKEY_OEM_102 : u8 = 0xE2;
+    pub const VKEY_OEM_103 : u8 = 0xE3;  // GTV KEYCODE_MEDIA_REWIND
+    pub const VKEY_OEM_104 : u8 = 0xE4;  // GTV KEYCODE_MEDIA_FAST_FORWARD
+    pub const VKEY_PROCESSKEY : u8 = 0xE5;
+    pub const VKEY_PACKET : u8 = 0xE7;
+    pub const VKEY_DBE_SBCSCHAR : u8 = 0xF3;
+    pub const VKEY_DBE_DBCSCHAR : u8 = 0xF4;
+    pub const VKEY_ATTN : u8 = 0xF6;
+    pub const VKEY_CRSEL : u8 = 0xF7;
+    pub const VKEY_EXSEL : u8 = 0xF8;
+    pub const VKEY_EREOF : u8 = 0xF9;
+    pub const VKEY_PLAY : u8 = 0xFA;
+    pub const VKEY_ZOOM : u8 = 0xFB;
+    pub const VKEY_NONAME : u8 = 0xFC;
+    pub const VKEY_PA1 : u8 = 0xFD;
+    pub const VKEY_OEM_CLEAR : u8 = 0xFE;
+    pub const VKEY_UNKNOWN : u8 = 0x0;
 
-  // POSIX specific VKEYs. Note that as of Windows SDK 7.1, 0x97-9F, 0xD8-DA,
-  // and 0xE8 are unassigned.
-  VKEY_WLAN = 0x97,
-  VKEY_POWER = 0x98,
-  VKEY_BRIGHTNESS_DOWN = 0xD8,
-  VKEY_BRIGHTNESS_UP = 0xD9,
-  VKEY_KBD_BRIGHTNESS_DOWN = 0xDA,
-  VKEY_KBD_BRIGHTNESS_UP = 0xE8,
+    // POSIX specific VKEYs. Note that as of Windows SDK 7.1, 0x97-9F, 0xD8-DA,
+    // and 0xE8 are unassigned.
+    pub const VKEY_WLAN : u8 = 0x97;
+    pub const VKEY_POWER : u8 = 0x98;
+    pub const VKEY_BRIGHTNESS_DOWN : u8 = 0xD8;
+    pub const VKEY_BRIGHTNESS_UP : u8 = 0xD9;
+    pub const VKEY_KBD_BRIGHTNESS_DOWN : u8 = 0xDA;
+    pub const VKEY_KBD_BRIGHTNESS_UP : u8 = 0xE8;
 
-  // Windows does not have a specific key code for AltGr. We use the unused 0xE1
-  // (VK_OEM_AX) code to represent AltGr, matching the behaviour of Firefox on
-  // Linux.
-  VKEY_ALTGR = 0xE1,
-  // Windows does not have a specific key code for Compose. We use the unused
-  // 0xE6 (VK_ICO_CLEAR) code to represent Compose.
-  VKEY_COMPOSE = 0xE6,
+    // Windows does not have a specific key code for AltGr. We use the unused 0xE1
+    // (VK_OEM_AX) code to represent AltGr, matching the behaviour of Firefox on
+    // Linux.
+    pub const VKEY_ALTGR : u8 = 0xE1;
+    // Windows does not have a specific key code for Compose. We use the unused
+    // 0xE6 (VK_ICO_CLEAR) code to represent Compose.
+    pub const VKEY_COMPOSE : u8 = 0xE6;
 }
 
 // this is way too much work to do 100% correctly right now.
 // see xkb_keyboard_layout_engine.cc -> XkbKeyboardLayoutEngine::Lookup in chromium for details
 fn get_key_msg(keycode: c_int, character: u16) -> Option<constellation_msg::Key> {
-    let code: KeyboardCode = unsafe { transmute(keycode as u8) };
-    match code {
+    match keycode as u8 {
         KeyboardCode::VKEY_BACK => Some(constellation_msg::Key::Backspace),
         KeyboardCode::VKEY_RIGHT => Some(constellation_msg::Key::Right),
         KeyboardCode::VKEY_LEFT => Some(constellation_msg::Key::Left),
         KeyboardCode::VKEY_UP => Some(constellation_msg::Key::Up),
         KeyboardCode::VKEY_DOWN => Some(constellation_msg::Key::Down),
         KeyboardCode::VKEY_RSHIFT => Some(constellation_msg::Key::RightShift),
         KeyboardCode::VKEY_SHIFT | KeyboardCode::VKEY_LSHIFT => Some(constellation_msg::Key::LeftShift),
         KeyboardCode::VKEY_RCONTROL => Some(constellation_msg::Key::RightControl),
@@ -412,23 +410,23 @@ full_cef_class_impl! {
             let key_state = match (*event).t {
                 // in tests with cef-real, this event had no effect
                 KEYEVENT_RAWKEYDOWN => return,
                 KEYEVENT_KEYDOWN => KeyState::Pressed,
                 KEYEVENT_CHAR => KeyState::Repeated,
                 KEYEVENT_KEYUP => KeyState::Released,
             };
             let mut key_modifiers = KeyModifiers::empty();
-            if (*event).modifiers & unsafe { intrinsics::discriminant_value(&EVENTFLAG_SHIFT_DOWN) as u32 } != 0 {
+            if (*event).modifiers & EVENTFLAG_SHIFT_DOWN as u32 != 0 {
                key_modifiers = key_modifiers | constellation_msg::SHIFT;
             }
-            if (*event).modifiers & unsafe { intrinsics::discriminant_value(&EVENTFLAG_CONTROL_DOWN) as u32 } != 0 {
+            if (*event).modifiers & EVENTFLAG_CONTROL_DOWN as u32 != 0 {
                key_modifiers = key_modifiers | constellation_msg::CONTROL;
             }
-            if (*event).modifiers & unsafe { intrinsics::discriminant_value(&EVENTFLAG_ALT_DOWN) as u32 } != 0 {
+            if (*event).modifiers & EVENTFLAG_ALT_DOWN as u32 != 0 {
                key_modifiers = key_modifiers | constellation_msg::ALT;
             }
             this.downcast().send_window_event(WindowEvent::KeyEvent(key, key_state, key_modifiers))
         }}
 
         fn send_mouse_click_event(&this,
                                   event: *const cef_mouse_event [&cef_mouse_event],
                                   mouse_button_type: cef_mouse_button_type_t [cef_mouse_button_type_t],