Bug 1459558 - Sync u2f-hid-rs changes r=jcj
authorTim Taubert <ttaubert@mozilla.com>
Tue, 08 May 2018 10:04:52 +0200
changeset 474005 f1f7e0069c2ad7c55cc6b4e887950e4361f8ed07
parent 474004 00630f737536b4327f3d29234a4882fb29c862b9
child 474006 03477c2e776a77f2745c52309a8223b58acb4cba
push id1757
push userffxbld-merge
push dateFri, 24 Aug 2018 17:02:43 +0000
treeherdermozilla-release@736023aebdb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjcj
bugs1459558
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1459558 - Sync u2f-hid-rs changes r=jcj Reviewers: jcj Reviewed By: jcj Bug #: 1459558 Differential Revision: https://phabricator.services.mozilla.com/D1145
Cargo.lock
dom/webauthn/u2f-hid-rs/Cargo.toml
dom/webauthn/u2f-hid-rs/src/lib.rs
dom/webauthn/u2f-hid-rs/src/macos/iokit.rs
dom/webauthn/u2f-hid-rs/src/macos/monitor.rs
dom/webauthn/u2f-hid-rs/src/macos/transaction.rs
third_party/rust/core-foundation-0.5.1/.cargo-checksum.json
third_party/rust/core-foundation-0.5.1/Cargo.toml
third_party/rust/core-foundation-0.5.1/LICENSE-APACHE
third_party/rust/core-foundation-0.5.1/LICENSE-MIT
third_party/rust/core-foundation-0.5.1/src/array.rs
third_party/rust/core-foundation-0.5.1/src/base.rs
third_party/rust/core-foundation-0.5.1/src/boolean.rs
third_party/rust/core-foundation-0.5.1/src/bundle.rs
third_party/rust/core-foundation-0.5.1/src/data.rs
third_party/rust/core-foundation-0.5.1/src/date.rs
third_party/rust/core-foundation-0.5.1/src/dictionary.rs
third_party/rust/core-foundation-0.5.1/src/error.rs
third_party/rust/core-foundation-0.5.1/src/filedescriptor.rs
third_party/rust/core-foundation-0.5.1/src/lib.rs
third_party/rust/core-foundation-0.5.1/src/number.rs
third_party/rust/core-foundation-0.5.1/src/propertylist.rs
third_party/rust/core-foundation-0.5.1/src/runloop.rs
third_party/rust/core-foundation-0.5.1/src/set.rs
third_party/rust/core-foundation-0.5.1/src/string.rs
third_party/rust/core-foundation-0.5.1/src/timezone.rs
third_party/rust/core-foundation-0.5.1/src/url.rs
third_party/rust/core-foundation-0.5.1/src/uuid.rs
third_party/rust/core-foundation-0.5.1/tests/use_macro_outside_crate.rs
third_party/rust/core-foundation-sys-0.5.1/.cargo-checksum.json
third_party/rust/core-foundation-sys-0.5.1/Cargo.toml
third_party/rust/core-foundation-sys-0.5.1/LICENSE-APACHE
third_party/rust/core-foundation-sys-0.5.1/LICENSE-MIT
third_party/rust/core-foundation-sys-0.5.1/build.rs
third_party/rust/core-foundation-sys-0.5.1/src/array.rs
third_party/rust/core-foundation-sys-0.5.1/src/base.rs
third_party/rust/core-foundation-sys-0.5.1/src/bundle.rs
third_party/rust/core-foundation-sys-0.5.1/src/data.rs
third_party/rust/core-foundation-sys-0.5.1/src/date.rs
third_party/rust/core-foundation-sys-0.5.1/src/dictionary.rs
third_party/rust/core-foundation-sys-0.5.1/src/error.rs
third_party/rust/core-foundation-sys-0.5.1/src/filedescriptor.rs
third_party/rust/core-foundation-sys-0.5.1/src/lib.rs
third_party/rust/core-foundation-sys-0.5.1/src/messageport.rs
third_party/rust/core-foundation-sys-0.5.1/src/number.rs
third_party/rust/core-foundation-sys-0.5.1/src/propertylist.rs
third_party/rust/core-foundation-sys-0.5.1/src/runloop.rs
third_party/rust/core-foundation-sys-0.5.1/src/set.rs
third_party/rust/core-foundation-sys-0.5.1/src/string.rs
third_party/rust/core-foundation-sys-0.5.1/src/timezone.rs
third_party/rust/core-foundation-sys-0.5.1/src/url.rs
third_party/rust/core-foundation-sys-0.5.1/src/uuid.rs
third_party/rust/core-foundation-sys/.cargo-checksum.json
third_party/rust/core-foundation-sys/Cargo.toml
third_party/rust/core-foundation-sys/src/array.rs
third_party/rust/core-foundation-sys/src/base.rs
third_party/rust/core-foundation-sys/src/bundle.rs
third_party/rust/core-foundation-sys/src/data.rs
third_party/rust/core-foundation-sys/src/date.rs
third_party/rust/core-foundation-sys/src/dictionary.rs
third_party/rust/core-foundation-sys/src/error.rs
third_party/rust/core-foundation-sys/src/filedescriptor.rs
third_party/rust/core-foundation-sys/src/lib.rs
third_party/rust/core-foundation-sys/src/messageport.rs
third_party/rust/core-foundation-sys/src/number.rs
third_party/rust/core-foundation-sys/src/propertylist.rs
third_party/rust/core-foundation-sys/src/runloop.rs
third_party/rust/core-foundation-sys/src/set.rs
third_party/rust/core-foundation-sys/src/string.rs
third_party/rust/core-foundation-sys/src/timezone.rs
third_party/rust/core-foundation-sys/src/url.rs
third_party/rust/core-foundation-sys/src/uuid.rs
third_party/rust/core-foundation/.cargo-checksum.json
third_party/rust/core-foundation/Cargo.toml
third_party/rust/core-foundation/src/array.rs
third_party/rust/core-foundation/src/base.rs
third_party/rust/core-foundation/src/bundle.rs
third_party/rust/core-foundation/src/dictionary.rs
third_party/rust/core-foundation/src/filedescriptor.rs
third_party/rust/core-foundation/src/lib.rs
third_party/rust/core-foundation/src/propertylist.rs
third_party/rust/core-foundation/src/runloop.rs
third_party/rust/core-foundation/src/set.rs
third_party/rust/core-foundation/tests/use_macro_outside_crate.rs
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -334,24 +334,38 @@ name = "core-foundation"
 version = "0.5.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "core-foundation-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
+name = "core-foundation"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "core-foundation-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
 name = "core-foundation-sys"
 version = "0.5.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
+name = "core-foundation-sys"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
 name = "core-graphics"
 version = "0.13.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "foreign-types 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2120,17 +2134,18 @@ version = "0.1.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
 name = "u2fhid"
 version = "0.1.0"
 dependencies = [
  "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "boxfnonce 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "core-foundation-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "core-foundation 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "core-foundation-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
  "libudev 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "rand 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)",
  "runloop 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -2484,17 +2499,19 @@ dependencies = [
 "checksum cexpr 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "393a5f0088efbe41f9d1fcd062f24e83c278608420e62109feb2c8abee07de7d"
 "checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de"
 "checksum chrono 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "9213f7cd7c27e95c2b57c49f0e69b1ea65b27138da84a170133fd21b07659c00"
 "checksum clang-sys 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)" = "939a1a34310b120d26eba35c29475933128b0ec58e24b43327f8dbe6036fc538"
 "checksum clap 2.29.0 (registry+https://github.com/rust-lang/crates.io-index)" = "110d43e343eb29f4f51c1db31beb879d546db27998577e5715270a54bcf41d3f"
 "checksum cmake 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)" = "56d741ea7a69e577f6d06b36b7dff4738f680593dc27a701ffa8506b73ce28bb"
 "checksum cookie 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "746858cae4eae40fff37e1998320068df317bc247dc91a67c6cfa053afdc2abb"
 "checksum core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "286e0b41c3a20da26536c6000a280585d519fd07b3956b43aed8a79e9edce980"
+"checksum core-foundation 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7caa6cb9e76ddddbea09a03266d6b3bc98cd41e9fb9b017c473e7cca593ec25"
 "checksum core-foundation-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "716c271e8613ace48344f723b60b900a93150271e5be206212d052bbc0883efa"
+"checksum core-foundation-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b2a53cce0ddcf7e7e1f998738d757d5a3bf08bf799a180e50ebe50d298f52f5a"
 "checksum core-graphics 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fb0ed45fdc32f9ab426238fba9407dfead7bacd7900c9b4dd3f396f46eafdae3"
 "checksum core-text 9.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2bd581c37283d0c23311d179aefbb891f2324ee0405da58a26e8594ab76e5748"
 "checksum cose 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "72fa26cb151d3ae4b70f63d67d0fed57ce04220feafafbae7f503bef7aae590d"
 "checksum cose-c 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "49726015ab0ca765144fcca61e4a7a543a16b795a777fa53f554da2fffff9a94"
 "checksum crc 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bd5d02c0aac6bd68393ed69e00bbc2457f3e89075c6349db7189618dc4ddc1d7"
 "checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3"
 "checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150"
 "checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9"
--- a/dom/webauthn/u2f-hid-rs/Cargo.toml
+++ b/dom/webauthn/u2f-hid-rs/Cargo.toml
@@ -2,17 +2,18 @@
 name = "u2fhid"
 version = "0.1.0"
 authors = ["Kyle Machulis <kyle@nonpolynomial.com>", "J.C. Jones <jc@mozilla.com>", "Tim Taubert <ttaubert@mozilla.com>"]
 
 [target.'cfg(target_os = "linux")'.dependencies]
 libudev = "^0.2"
 
 [target.'cfg(target_os = "macos")'.dependencies]
-core-foundation-sys = "0.5.1"
+core-foundation-sys = "0.6.0"
+core-foundation = "0.6.0"
 
 [target.'cfg(target_os = "windows")'.dependencies]
 winapi = "0.2.8"
 
 [dependencies]
 rand = "0.3"
 log = "0.4"
 libc = "^0.2"
--- a/dom/webauthn/u2f-hid-rs/src/lib.rs
+++ b/dom/webauthn/u2f-hid-rs/src/lib.rs
@@ -11,16 +11,19 @@ extern crate libudev;
 #[cfg(any(target_os = "linux"))]
 #[path = "linux/mod.rs"]
 pub mod platform;
 
 #[cfg(any(target_os = "macos"))]
 extern crate core_foundation_sys;
 
 #[cfg(any(target_os = "macos"))]
+extern crate core_foundation;
+
+#[cfg(any(target_os = "macos"))]
 #[path = "macos/mod.rs"]
 pub mod platform;
 
 #[cfg(any(target_os = "windows"))]
 #[path = "windows/mod.rs"]
 pub mod platform;
 
 #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
--- a/dom/webauthn/u2f-hid-rs/src/macos/iokit.rs
+++ b/dom/webauthn/u2f-hid-rs/src/macos/iokit.rs
@@ -5,20 +5,22 @@
 #![allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
 
 extern crate core_foundation_sys;
 extern crate libc;
 
 use consts::{FIDO_USAGE_U2FHID, FIDO_USAGE_PAGE};
 use core_foundation_sys::base::*;
 use core_foundation_sys::dictionary::*;
-use core_foundation_sys::number::*;
 use core_foundation_sys::runloop::*;
 use core_foundation_sys::string::*;
-use libc::c_void;
+use core_foundation::dictionary::*;
+use core_foundation::string::*;
+use core_foundation::number::*;
+use std::os::raw::c_void;
 use std::ops::Deref;
 
 type IOOptionBits = u32;
 
 pub type IOReturn = libc::c_int;
 
 pub type IOHIDManagerRef = *mut __IOHIDManager;
 pub type IOHIDManagerOptions = IOOptionBits;
@@ -147,86 +149,32 @@ impl Drop for CFRunLoopEntryObserver {
 
             // Drop the CFRunLoopObserverContext.
             let _ = Box::from_raw(self.context_ptr);
         };
     }
 }
 
 pub struct IOHIDDeviceMatcher {
-    dict: CFDictionaryRef,
-    keys: Vec<CFStringRef>,
-    values: Vec<CFNumberRef>,
+    pub dict: CFDictionary<CFString, CFNumber>,
 }
 
 impl IOHIDDeviceMatcher {
     pub fn new() -> Self {
-        let keys = vec![
-            IOHIDDeviceMatcher::cf_string("DeviceUsage"),
-            IOHIDDeviceMatcher::cf_string("DeviceUsagePage"),
-        ];
-
-        let values = vec![
-            IOHIDDeviceMatcher::cf_number(FIDO_USAGE_U2FHID as i32),
-            IOHIDDeviceMatcher::cf_number(FIDO_USAGE_PAGE as i32),
-        ];
-
-        let dict = unsafe {
-            CFDictionaryCreate(
-                kCFAllocatorDefault,
-                keys.as_ptr() as *const *const libc::c_void,
-                values.as_ptr() as *const *const libc::c_void,
-                keys.len() as CFIndex,
-                &kCFTypeDictionaryKeyCallBacks,
-                &kCFTypeDictionaryValueCallBacks,
-            )
-        };
-
-        Self { dict, keys, values }
-    }
-
-    fn cf_number(number: i32) -> CFNumberRef {
-        let nbox = Box::new(number);
-        let nptr = Box::into_raw(nbox) as *mut libc::c_void;
-
-        unsafe {
-            // Drop when out of scope.
-            let _num = Box::from_raw(nptr as *mut i32);
-            CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, nptr)
-        }
-    }
-
-    fn cf_string(string: &str) -> CFStringRef {
-        unsafe {
-            CFStringCreateWithBytes(
-                kCFAllocatorDefault,
-                string.as_ptr(),
-                string.len() as CFIndex,
-                kCFStringEncodingUTF8,
-                false as Boolean,
-            )
-        }
-    }
-
-    pub fn get(&self) -> CFDictionaryRef {
-        self.dict
-    }
-}
-
-impl Drop for IOHIDDeviceMatcher {
-    fn drop(&mut self) {
-        unsafe { CFRelease(self.dict as *mut libc::c_void) };
-
-        for key in &self.keys {
-            unsafe { CFRelease(*key as *mut libc::c_void) };
-        }
-
-        for value in &self.values {
-            unsafe { CFRelease(*value as *mut libc::c_void) };
-        }
+        let dict = CFDictionary::<CFString, CFNumber>::from_CFType_pairs(&[
+            (
+                CFString::from_static_string("DeviceUsage"),
+                CFNumber::from(FIDO_USAGE_U2FHID as i32),
+            ),
+            (
+                CFString::from_static_string("DeviceUsagePage"),
+                CFNumber::from(FIDO_USAGE_PAGE as i32),
+            ),
+            ]);
+        Self { dict }
     }
 }
 
 #[link(name = "IOKit", kind = "framework")]
 extern "C" {
     // CFRunLoop
     pub fn CFRunLoopObserverCreate(
         allocator: CFAllocatorRef,
@@ -278,19 +226,17 @@ extern "C" {
 
 ////////////////////////////////////////////////////////////////////////
 // Tests
 ////////////////////////////////////////////////////////////////////////
 
 #[cfg(test)]
 mod tests {
     use super::*;
-    use core_foundation_sys::base::*;
-    use core_foundation_sys::runloop::*;
-    use libc::c_void;
+    use std::os::raw::c_void;
     use std::ptr;
     use std::sync::mpsc::{channel, Sender};
     use std::thread;
 
     extern "C" fn observe(_: CFRunLoopObserverRef, _: CFRunLoopActivity, context: *mut c_void) {
         let tx: &Sender<SendableRunLoop> = unsafe { &*(context as *mut _) };
 
         // Send the current runloop to the receiver to unblock it.
--- a/dom/webauthn/u2f-hid-rs/src/macos/monitor.rs
+++ b/dom/webauthn/u2f-hid-rs/src/macos/monitor.rs
@@ -2,17 +2,18 @@
  * 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/. */
 
 extern crate libc;
 extern crate log;
 
 use core_foundation_sys::base::*;
 use core_foundation_sys::runloop::*;
-use libc::c_void;
+use core_foundation::base::TCFType;
+use std::os::raw::c_void;
 use platform::iokit::*;
 use runloop::RunLoop;
 use std::collections::HashMap;
 use std::sync::mpsc::{channel, Receiver, Sender};
 use std::{io, slice};
 use util::io_err;
 
 struct DeviceData {
@@ -35,17 +36,17 @@ impl<F> Monitor<F>
 where
     F: Fn((IOHIDDeviceRef, Receiver<Vec<u8>>), &Fn() -> bool) + Sync + 'static,
 {
     pub fn new(new_device_cb: F) -> Self {
         let manager = unsafe { IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDManagerOptionNone) };
 
         // Match FIDO devices only.
         let _matcher = IOHIDDeviceMatcher::new();
-        unsafe { IOHIDManagerSetDeviceMatching(manager, _matcher.get()) };
+        unsafe { IOHIDManagerSetDeviceMatching(manager, _matcher.dict.as_concrete_TypeRef()) };
 
         Self {
             manager,
             _matcher,
             new_device_cb,
             map: HashMap::new(),
         }
     }
@@ -165,11 +166,11 @@ where
     }
 }
 
 impl<F> Drop for Monitor<F>
 where
     F: Fn((IOHIDDeviceRef, Receiver<Vec<u8>>), &Fn() -> bool) + Sync,
 {
     fn drop(&mut self) {
-        unsafe { CFRelease(self.manager as *mut libc::c_void) };
+        unsafe { CFRelease(self.manager as *mut c_void) };
     }
 }
--- a/dom/webauthn/u2f-hid-rs/src/macos/transaction.rs
+++ b/dom/webauthn/u2f-hid-rs/src/macos/transaction.rs
@@ -1,16 +1,16 @@
 /* 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/. */
 
 extern crate libc;
 
 use core_foundation_sys::runloop::*;
-use libc::c_void;
+use std::os::raw::c_void;
 use platform::iokit::{CFRunLoopEntryObserver, IOHIDDeviceRef, SendableRunLoop};
 use platform::monitor::Monitor;
 use std::sync::mpsc::{channel, Receiver, Sender};
 use std::thread;
 use util::OnceCallback;
 
 // A transaction will run the given closure in a new thread, thereby using a
 // separate per-thread state machine for each HID. It will either complete or
copy from third_party/rust/core-foundation/.cargo-checksum.json
copy to third_party/rust/core-foundation-0.5.1/.cargo-checksum.json
copy from third_party/rust/core-foundation/Cargo.toml
copy to third_party/rust/core-foundation-0.5.1/Cargo.toml
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/LICENSE-APACHE
@@ -0,0 +1,201 @@
+                              Apache License
+                        Version 2.0, January 2004
+                     http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+   "License" shall mean the terms and conditions for use, reproduction,
+   and distribution as defined by Sections 1 through 9 of this document.
+
+   "Licensor" shall mean the copyright owner or entity authorized by
+   the copyright owner that is granting the License.
+
+   "Legal Entity" shall mean the union of the acting entity and all
+   other entities that control, are controlled by, or are under common
+   control with that entity. For the purposes of this definition,
+   "control" means (i) the power, direct or indirect, to cause the
+   direction or management of such entity, whether by contract or
+   otherwise, or (ii) ownership of fifty percent (50%) or more of the
+   outstanding shares, or (iii) beneficial ownership of such entity.
+
+   "You" (or "Your") shall mean an individual or Legal Entity
+   exercising permissions granted by this License.
+
+   "Source" form shall mean the preferred form for making modifications,
+   including but not limited to software source code, documentation
+   source, and configuration files.
+
+   "Object" form shall mean any form resulting from mechanical
+   transformation or translation of a Source form, including but
+   not limited to compiled object code, generated documentation,
+   and conversions to other media types.
+
+   "Work" shall mean the work of authorship, whether in Source or
+   Object form, made available under the License, as indicated by a
+   copyright notice that is included in or attached to the work
+   (an example is provided in the Appendix below).
+
+   "Derivative Works" shall mean any work, whether in Source or Object
+   form, that is based on (or derived from) the Work and for which the
+   editorial revisions, annotations, elaborations, or other modifications
+   represent, as a whole, an original work of authorship. For the purposes
+   of this License, Derivative Works shall not include works that remain
+   separable from, or merely link (or bind by name) to the interfaces of,
+   the Work and Derivative Works thereof.
+
+   "Contribution" shall mean any work of authorship, including
+   the original version of the Work and any modifications or additions
+   to that Work or Derivative Works thereof, that is intentionally
+   submitted to Licensor for inclusion in the Work by the copyright owner
+   or by an individual or Legal Entity authorized to submit on behalf of
+   the copyright owner. For the purposes of this definition, "submitted"
+   means any form of electronic, verbal, or written communication sent
+   to the Licensor or its representatives, including but not limited to
+   communication on electronic mailing lists, source code control systems,
+   and issue tracking systems that are managed by, or on behalf of, the
+   Licensor for the purpose of discussing and improving the Work, but
+   excluding communication that is conspicuously marked or otherwise
+   designated in writing by the copyright owner as "Not a Contribution."
+
+   "Contributor" shall mean Licensor and any individual or Legal Entity
+   on behalf of whom a Contribution has been received by Licensor and
+   subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of
+   this License, each Contributor hereby grants to You a perpetual,
+   worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+   copyright license to reproduce, prepare Derivative Works of,
+   publicly display, publicly perform, sublicense, and distribute the
+   Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of
+   this License, each Contributor hereby grants to You a perpetual,
+   worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+   (except as stated in this section) patent license to make, have made,
+   use, offer to sell, sell, import, and otherwise transfer the Work,
+   where such license applies only to those patent claims licensable
+   by such Contributor that are necessarily infringed by their
+   Contribution(s) alone or by combination of their Contribution(s)
+   with the Work to which such Contribution(s) was submitted. If You
+   institute patent litigation against any entity (including a
+   cross-claim or counterclaim in a lawsuit) alleging that the Work
+   or a Contribution incorporated within the Work constitutes direct
+   or contributory patent infringement, then any patent licenses
+   granted to You under this License for that Work shall terminate
+   as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the
+   Work or Derivative Works thereof in any medium, with or without
+   modifications, and in Source or Object form, provided that You
+   meet the following conditions:
+
+   (a) You must give any other recipients of the Work or
+       Derivative Works a copy of this License; and
+
+   (b) You must cause any modified files to carry prominent notices
+       stating that You changed the files; and
+
+   (c) You must retain, in the Source form of any Derivative Works
+       that You distribute, all copyright, patent, trademark, and
+       attribution notices from the Source form of the Work,
+       excluding those notices that do not pertain to any part of
+       the Derivative Works; and
+
+   (d) If the Work includes a "NOTICE" text file as part of its
+       distribution, then any Derivative Works that You distribute must
+       include a readable copy of the attribution notices contained
+       within such NOTICE file, excluding those notices that do not
+       pertain to any part of the Derivative Works, in at least one
+       of the following places: within a NOTICE text file distributed
+       as part of the Derivative Works; within the Source form or
+       documentation, if provided along with the Derivative Works; or,
+       within a display generated by the Derivative Works, if and
+       wherever such third-party notices normally appear. The contents
+       of the NOTICE file are for informational purposes only and
+       do not modify the License. You may add Your own attribution
+       notices within Derivative Works that You distribute, alongside
+       or as an addendum to the NOTICE text from the Work, provided
+       that such additional attribution notices cannot be construed
+       as modifying the License.
+
+   You may add Your own copyright statement to Your modifications and
+   may provide additional or different license terms and conditions
+   for use, reproduction, or distribution of Your modifications, or
+   for any such Derivative Works as a whole, provided Your use,
+   reproduction, and distribution of the Work otherwise complies with
+   the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise,
+   any Contribution intentionally submitted for inclusion in the Work
+   by You to the Licensor shall be under the terms and conditions of
+   this License, without any additional terms or conditions.
+   Notwithstanding the above, nothing herein shall supersede or modify
+   the terms of any separate license agreement you may have executed
+   with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade
+   names, trademarks, service marks, or product names of the Licensor,
+   except as required for reasonable and customary use in describing the
+   origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or
+   agreed to in writing, Licensor provides the Work (and each
+   Contributor provides its Contributions) on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+   implied, including, without limitation, any warranties or conditions
+   of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+   PARTICULAR PURPOSE. You are solely responsible for determining the
+   appropriateness of using or redistributing the Work and assume any
+   risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory,
+   whether in tort (including negligence), contract, or otherwise,
+   unless required by applicable law (such as deliberate and grossly
+   negligent acts) or agreed to in writing, shall any Contributor be
+   liable to You for damages, including any direct, indirect, special,
+   incidental, or consequential damages of any character arising as a
+   result of this License or out of the use or inability to use the
+   Work (including but not limited to damages for loss of goodwill,
+   work stoppage, computer failure or malfunction, or any and all
+   other commercial damages or losses), even if such Contributor
+   has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing
+   the Work or Derivative Works thereof, You may choose to offer,
+   and charge a fee for, acceptance of support, warranty, indemnity,
+   or other liability obligations and/or rights consistent with this
+   License. However, in accepting such obligations, You may act only
+   on Your own behalf and on Your sole responsibility, not on behalf
+   of any other Contributor, and only if You agree to indemnify,
+   defend, and hold each Contributor harmless for any liability
+   incurred by, or claims asserted against, such Contributor by reason
+   of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
+
+APPENDIX: How to apply the Apache License to your work.
+
+   To apply the Apache License to your work, attach the following
+   boilerplate notice, with the fields enclosed by brackets "[]"
+   replaced with your own identifying information. (Don't include
+   the brackets!)  The text should be enclosed in the appropriate
+   comment syntax for the file format. We also recommend that a
+   file or class name and description of purpose be included on the
+   same "printed page" as the copyright notice for easier
+   identification within third-party archives.
+
+Copyright [yyyy] [name of copyright owner]
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+	http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/LICENSE-MIT
@@ -0,0 +1,25 @@
+Copyright (c) 2012-2013 Mozilla Foundation
+
+Permission is hereby granted, free of charge, to any
+person obtaining a copy of this software and associated
+documentation files (the "Software"), to deal in the
+Software without restriction, including without
+limitation the rights to use, copy, modify, merge,
+publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software
+is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice
+shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
+ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
+TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
+SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
copy from third_party/rust/core-foundation/src/array.rs
copy to third_party/rust/core-foundation-0.5.1/src/array.rs
copy from third_party/rust/core-foundation/src/base.rs
copy to third_party/rust/core-foundation-0.5.1/src/base.rs
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/src/boolean.rs
@@ -0,0 +1,70 @@
+// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! A Boolean type.
+
+pub use core_foundation_sys::number::{CFBooleanRef, CFBooleanGetTypeID, kCFBooleanTrue, kCFBooleanFalse};
+
+use base::TCFType;
+
+
+declare_TCFType!{
+    /// A Boolean type.
+    ///
+    /// FIXME(pcwalton): Should be a newtype struct, but that fails due to a Rust compiler bug.
+    CFBoolean, CFBooleanRef
+}
+impl_TCFType!(CFBoolean, CFBooleanRef, CFBooleanGetTypeID);
+impl_CFTypeDescription!(CFBoolean);
+
+impl CFBoolean {
+    pub fn true_value() -> CFBoolean {
+        unsafe {
+            TCFType::wrap_under_get_rule(kCFBooleanTrue)
+        }
+    }
+
+    pub fn false_value() -> CFBoolean {
+        unsafe {
+            TCFType::wrap_under_get_rule(kCFBooleanFalse)
+        }
+    }
+}
+
+impl From<bool> for CFBoolean {
+    fn from(value: bool) -> CFBoolean {
+        if value {
+            CFBoolean::true_value()
+        } else {
+            CFBoolean::false_value()
+        }
+    }
+}
+
+impl From<CFBoolean> for bool {
+    fn from(value: CFBoolean) -> bool {
+        value.0 == unsafe { kCFBooleanTrue }
+    }
+}
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+
+    #[test]
+    fn to_and_from_bool() {
+        let b_false = CFBoolean::from(false);
+        let b_true = CFBoolean::from(true);
+        assert_ne!(b_false, b_true);
+        assert_eq!(b_false, CFBoolean::false_value());
+        assert_eq!(b_true, CFBoolean::true_value());
+        assert!(!bool::from(b_false));
+        assert!(bool::from(b_true));
+    }
+}
copy from third_party/rust/core-foundation/src/bundle.rs
copy to third_party/rust/core-foundation-0.5.1/src/bundle.rs
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/src/data.rs
@@ -0,0 +1,63 @@
+// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Core Foundation byte buffers.
+
+pub use core_foundation_sys::data::*;
+use core_foundation_sys::base::CFIndex;
+use core_foundation_sys::base::{kCFAllocatorDefault};
+use std::ops::Deref;
+use std::slice;
+
+use base::{CFIndexConvertible, TCFType};
+
+
+declare_TCFType!{
+    /// A byte buffer.
+    CFData, CFDataRef
+}
+impl_TCFType!(CFData, CFDataRef, CFDataGetTypeID);
+impl_CFTypeDescription!(CFData);
+
+impl CFData {
+    pub fn from_buffer(buffer: &[u8]) -> CFData {
+        unsafe {
+            let data_ref = CFDataCreate(kCFAllocatorDefault,
+                                        buffer.as_ptr(),
+                                        buffer.len().to_CFIndex());
+            TCFType::wrap_under_create_rule(data_ref)
+        }
+    }
+
+    /// Returns a pointer to the underlying bytes in this data. Note that this byte buffer is
+    /// read-only.
+    #[inline]
+    pub fn bytes<'a>(&'a self) -> &'a [u8] {
+        unsafe {
+            slice::from_raw_parts(CFDataGetBytePtr(self.0), self.len() as usize)
+        }
+    }
+
+    /// Returns the length of this byte buffer.
+    #[inline]
+    pub fn len(&self) -> CFIndex {
+        unsafe {
+            CFDataGetLength(self.0)
+        }
+    }
+}
+
+impl Deref for CFData {
+    type Target = [u8];
+
+    #[inline]
+    fn deref(&self) -> &[u8] {
+        self.bytes()
+    }
+}
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/src/date.rs
@@ -0,0 +1,130 @@
+// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Core Foundation date objects.
+
+pub use core_foundation_sys::date::*;
+use core_foundation_sys::base::kCFAllocatorDefault;
+
+use base::TCFType;
+
+#[cfg(feature = "with-chrono")]
+use chrono::NaiveDateTime;
+
+
+declare_TCFType!{
+    /// A date.
+    CFDate, CFDateRef
+}
+impl_TCFType!(CFDate, CFDateRef, CFDateGetTypeID);
+impl_CFTypeDescription!(CFDate);
+impl_CFComparison!(CFDate, CFDateCompare);
+
+impl CFDate {
+    #[inline]
+    pub fn new(time: CFAbsoluteTime) -> CFDate {
+        unsafe {
+            let date_ref = CFDateCreate(kCFAllocatorDefault, time);
+            TCFType::wrap_under_create_rule(date_ref)
+        }
+    }
+
+    #[inline]
+    pub fn now() -> CFDate {
+        CFDate::new(unsafe { CFAbsoluteTimeGetCurrent() })
+    }
+
+    #[inline]
+    pub fn abs_time(&self) -> CFAbsoluteTime {
+        unsafe {
+            CFDateGetAbsoluteTime(self.0)
+        }
+    }
+
+    #[cfg(feature = "with-chrono")]
+    pub fn naive_utc(&self) -> NaiveDateTime {
+        let ts = unsafe {
+            self.abs_time() + kCFAbsoluteTimeIntervalSince1970
+        };
+        let (secs, nanos) = if ts.is_sign_positive() {
+            (ts.trunc() as i64, ts.fract())
+        } else {
+            // nanoseconds can't be negative in NaiveDateTime
+            (ts.trunc() as i64 - 1, 1.0 - ts.fract().abs())
+        };
+        NaiveDateTime::from_timestamp(secs, (nanos * 1e9).floor() as u32)
+    }
+
+    #[cfg(feature = "with-chrono")]
+    pub fn from_naive_utc(time: NaiveDateTime) -> CFDate {
+        let secs = time.timestamp();
+        let nanos = time.timestamp_subsec_nanos();
+        let ts = unsafe {
+            secs as f64 + (nanos as f64 / 1e9) - kCFAbsoluteTimeIntervalSince1970
+        };
+        CFDate::new(ts)
+    }
+}
+
+#[cfg(test)]
+mod test {
+    use super::CFDate;
+    use std::cmp::Ordering;
+
+    #[cfg(feature = "with-chrono")]
+    use chrono::NaiveDateTime;
+
+    #[cfg(feature = "with-chrono")]
+    fn approx_eq(a: f64, b: f64) -> bool {
+        use std::f64;
+
+        let same_sign = a.is_sign_positive() == b.is_sign_positive();
+        let equal = ((a - b).abs() / f64::min(a.abs() + b.abs(), f64::MAX)) < f64::EPSILON;
+        (same_sign && equal)
+    }
+
+    #[test]
+    fn date_comparison() {
+        let now = CFDate::now();
+        let past = CFDate::new(now.abs_time() - 1.0);
+        assert_eq!(now.cmp(&past), Ordering::Greater);
+        assert_eq!(now.cmp(&now), Ordering::Equal);
+        assert_eq!(past.cmp(&now), Ordering::Less);
+    }
+
+    #[test]
+    fn date_equality() {
+        let now = CFDate::now();
+        let same_time = CFDate::new(now.abs_time());
+        assert_eq!(now, same_time);
+    }
+
+    #[test]
+    #[cfg(feature = "with-chrono")]
+    fn date_chrono_conversion_positive() {
+        let date = CFDate::now();
+        let datetime = date.naive_utc();
+        let converted = CFDate::from_naive_utc(datetime);
+        assert!(approx_eq(date.abs_time(), converted.abs_time()));
+    }
+
+    #[test]
+    #[cfg(feature = "with-chrono")]
+    fn date_chrono_conversion_negative() {
+        use super::kCFAbsoluteTimeIntervalSince1970;
+
+        let ts = unsafe {
+            kCFAbsoluteTimeIntervalSince1970 - 420.0
+        };
+        let date = CFDate::new(ts);
+        let datetime: NaiveDateTime = date.naive_utc();
+        let converted = CFDate::from_naive_utc(datetime);
+        assert!(approx_eq(date.abs_time(), converted.abs_time()));
+    }
+}
copy from third_party/rust/core-foundation/src/dictionary.rs
copy to third_party/rust/core-foundation-0.5.1/src/dictionary.rs
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/src/error.rs
@@ -0,0 +1,71 @@
+// Copyright 2016 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Core Foundation errors.
+
+pub use core_foundation_sys::error::*;
+
+use std::error::Error;
+use std::fmt;
+
+use base::{CFIndex, TCFType};
+use string::CFString;
+
+
+declare_TCFType!{
+    /// An error value.
+    CFError, CFErrorRef
+}
+impl_TCFType!(CFError, CFErrorRef, CFErrorGetTypeID);
+
+impl fmt::Debug for CFError {
+    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+        fmt.debug_struct("CFError")
+           .field("domain", &self.domain())
+           .field("code", &self.code())
+           .field("description", &self.description())
+           .finish()
+    }
+}
+
+impl fmt::Display for CFError {
+    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+        write!(fmt, "{}", self.description())
+    }
+}
+
+impl Error for CFError {
+    fn description(&self) -> &str {
+        "a Core Foundation error"
+    }
+}
+
+impl CFError {
+    /// Returns a string identifying the domain with which this error is
+    /// associated.
+    pub fn domain(&self) -> CFString {
+        unsafe {
+            let s = CFErrorGetDomain(self.0);
+            CFString::wrap_under_get_rule(s)
+        }
+    }
+
+    /// Returns the code identifying this type of error.
+    pub fn code(&self) -> CFIndex {
+        unsafe { CFErrorGetCode(self.0) }
+    }
+
+    /// Returns a human-presentable description of the error.
+    pub fn description(&self) -> CFString {
+        unsafe {
+            let s = CFErrorCopyDescription(self.0);
+            CFString::wrap_under_create_rule(s)
+        }
+    }
+}
copy from third_party/rust/core-foundation/src/filedescriptor.rs
copy to third_party/rust/core-foundation-0.5.1/src/filedescriptor.rs
copy from third_party/rust/core-foundation/src/lib.rs
copy to third_party/rust/core-foundation-0.5.1/src/lib.rs
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/src/number.rs
@@ -0,0 +1,110 @@
+// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Immutable numbers.
+
+use core_foundation_sys::base::kCFAllocatorDefault;
+pub use core_foundation_sys::number::*;
+use std::mem;
+
+use base::TCFType;
+
+
+declare_TCFType!{
+    /// An immutable numeric value.
+    CFNumber, CFNumberRef
+}
+impl_TCFType!(CFNumber, CFNumberRef, CFNumberGetTypeID);
+impl_CFTypeDescription!(CFNumber);
+impl_CFComparison!(CFNumber, CFNumberCompare);
+
+impl CFNumber {
+    #[inline]
+    pub fn to_i64(&self) -> Option<i64> {
+        unsafe {
+            let mut value: i64 = 0;
+            let ok = CFNumberGetValue(self.0, kCFNumberSInt64Type, mem::transmute(&mut value));
+            if ok { Some(value) } else { None }
+        }
+    }
+
+    #[inline]
+    pub fn to_f32(&self) -> Option<f32> {
+        unsafe {
+            let mut value: f32 = 0.0;
+            let ok = CFNumberGetValue(self.0, kCFNumberFloat32Type, mem::transmute(&mut value));
+            if ok { Some(value) } else { None }
+        }
+    }
+
+    #[inline]
+    pub fn to_f64(&self) -> Option<f64> {
+        unsafe {
+            let mut value: f64 = 0.0;
+            let ok = CFNumberGetValue(self.0, kCFNumberFloat64Type, mem::transmute(&mut value));
+            if ok { Some(value) } else { None }
+        }
+    }
+}
+
+impl From<i32> for CFNumber {
+    #[inline]
+    fn from(value: i32) -> Self {
+        unsafe {
+            let number_ref = CFNumberCreate(
+                kCFAllocatorDefault,
+                kCFNumberSInt32Type,
+                mem::transmute(&value),
+            );
+            TCFType::wrap_under_create_rule(number_ref)
+        }
+    }
+}
+
+impl From<i64> for CFNumber {
+    #[inline]
+    fn from(value: i64) -> Self {
+        unsafe {
+            let number_ref = CFNumberCreate(
+                kCFAllocatorDefault,
+                kCFNumberSInt64Type,
+                mem::transmute(&value),
+            );
+            TCFType::wrap_under_create_rule(number_ref)
+        }
+    }
+}
+
+impl From<f32> for CFNumber {
+    #[inline]
+    fn from(value: f32) -> Self {
+        unsafe {
+            let number_ref = CFNumberCreate(
+                kCFAllocatorDefault,
+                kCFNumberFloat32Type,
+                mem::transmute(&value),
+            );
+            TCFType::wrap_under_create_rule(number_ref)
+        }
+    }
+}
+
+impl From<f64> for CFNumber {
+    #[inline]
+    fn from(value: f64) -> Self {
+        unsafe {
+            let number_ref = CFNumberCreate(
+                kCFAllocatorDefault,
+                kCFNumberFloat64Type,
+                mem::transmute(&value),
+            );
+            TCFType::wrap_under_create_rule(number_ref)
+        }
+    }
+}
copy from third_party/rust/core-foundation/src/propertylist.rs
copy to third_party/rust/core-foundation-0.5.1/src/propertylist.rs
copy from third_party/rust/core-foundation/src/runloop.rs
copy to third_party/rust/core-foundation-0.5.1/src/runloop.rs
copy from third_party/rust/core-foundation/src/set.rs
copy to third_party/rust/core-foundation-0.5.1/src/set.rs
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/src/string.rs
@@ -0,0 +1,143 @@
+// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Immutable strings.
+
+pub use core_foundation_sys::string::*;
+
+use base::{CFIndexConvertible, TCFType};
+
+use core_foundation_sys::base::{Boolean, CFIndex, CFRange};
+use core_foundation_sys::base::{kCFAllocatorDefault, kCFAllocatorNull};
+use std::fmt;
+use std::str::{self, FromStr};
+use std::ptr;
+use std::ffi::CStr;
+
+
+declare_TCFType!{
+    /// An immutable string in one of a variety of encodings.
+    CFString, CFStringRef
+}
+impl_TCFType!(CFString, CFStringRef, CFStringGetTypeID);
+
+impl FromStr for CFString {
+    type Err = ();
+
+    /// See also CFString::new for a variant of this which does not return a Result
+    #[inline]
+    fn from_str(string: &str) -> Result<CFString, ()> {
+        Ok(CFString::new(string))
+    }
+}
+
+impl<'a> From<&'a str> for CFString {
+    #[inline]
+    fn from(string: &'a str) -> CFString {
+        CFString::new(string)
+    }
+}
+
+impl fmt::Display for CFString {
+    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+        unsafe {
+            // Do this without allocating if we can get away with it
+            let c_string = CFStringGetCStringPtr(self.0, kCFStringEncodingUTF8);
+            if c_string != ptr::null() {
+                let c_str = CStr::from_ptr(c_string);
+                fmt.write_str(str::from_utf8_unchecked(c_str.to_bytes()))
+            } else {
+                let char_len = self.char_len();
+
+                // First, ask how big the buffer ought to be.
+                let mut bytes_required: CFIndex = 0;
+                CFStringGetBytes(self.0,
+                                 CFRange { location: 0, length: char_len },
+                                 kCFStringEncodingUTF8,
+                                 0,
+                                 false as Boolean,
+                                 ptr::null_mut(),
+                                 0,
+                                 &mut bytes_required);
+
+                // Then, allocate the buffer and actually copy.
+                let mut buffer = vec![b'\x00'; bytes_required as usize];
+
+                let mut bytes_used: CFIndex = 0;
+                let chars_written = CFStringGetBytes(self.0,
+                                                     CFRange { location: 0, length: char_len },
+                                                     kCFStringEncodingUTF8,
+                                                     0,
+                                                     false as Boolean,
+                                                     buffer.as_mut_ptr(),
+                                                     buffer.len().to_CFIndex(),
+                                                     &mut bytes_used) as usize;
+                assert!(chars_written.to_CFIndex() == char_len);
+
+                // This is dangerous; we over-allocate and null-terminate the string (during
+                // initialization).
+                assert!(bytes_used == buffer.len().to_CFIndex());
+                fmt.write_str(str::from_utf8_unchecked(&buffer))
+            }
+        }
+    }
+}
+
+impl fmt::Debug for CFString {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(f, "\"{}\"", self)
+    }
+}
+
+
+impl CFString {
+    /// Creates a new `CFString` instance from a Rust string.
+    #[inline]
+    pub fn new(string: &str) -> CFString {
+        unsafe {
+            let string_ref = CFStringCreateWithBytes(kCFAllocatorDefault,
+                                                     string.as_ptr(),
+                                                     string.len().to_CFIndex(),
+                                                     kCFStringEncodingUTF8,
+                                                     false as Boolean);
+            CFString::wrap_under_create_rule(string_ref)
+        }
+    }
+
+    /// Like `CFString::new`, but references a string that can be used as a backing store
+    /// by virtue of being statically allocated.
+    #[inline]
+    pub fn from_static_string(string: &'static str) -> CFString {
+        unsafe {
+            let string_ref = CFStringCreateWithBytesNoCopy(kCFAllocatorDefault,
+                                                           string.as_ptr(),
+                                                           string.len().to_CFIndex(),
+                                                           kCFStringEncodingUTF8,
+                                                           false as Boolean,
+                                                           kCFAllocatorNull);
+            TCFType::wrap_under_create_rule(string_ref)
+        }
+    }
+
+    /// Returns the number of characters in the string.
+    #[inline]
+    pub fn char_len(&self) -> CFIndex {
+        unsafe {
+            CFStringGetLength(self.0)
+        }
+    }
+}
+
+#[test]
+fn string_and_back() {
+    let original = "The quick brown fox jumped over the slow lazy dog.";
+    let cfstr = CFString::from_static_string(original);
+    let converted = cfstr.to_string();
+    assert!(converted == original);
+}
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/src/timezone.rs
@@ -0,0 +1,95 @@
+// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Core Foundation time zone objects.
+
+pub use core_foundation_sys::timezone::*;
+use core_foundation_sys::base::kCFAllocatorDefault;
+
+use base::TCFType;
+use date::{CFDate, CFTimeInterval};
+
+#[cfg(feature = "with-chrono")]
+use chrono::{FixedOffset, NaiveDateTime};
+
+
+declare_TCFType!{
+    /// A time zone.
+    CFTimeZone, CFTimeZoneRef
+}
+impl_TCFType!(CFTimeZone, CFTimeZoneRef, CFTimeZoneGetTypeID);
+impl_CFTypeDescription!(CFTimeZone);
+
+impl Default for CFTimeZone {
+    fn default() -> CFTimeZone {
+        unsafe {
+            let tz_ref = CFTimeZoneCopyDefault();
+            TCFType::wrap_under_create_rule(tz_ref)
+        }
+    }
+}
+
+impl CFTimeZone {
+    #[inline]
+    pub fn new(interval: CFTimeInterval) -> CFTimeZone {
+        unsafe {
+            let tz_ref = CFTimeZoneCreateWithTimeIntervalFromGMT(kCFAllocatorDefault, interval);
+            TCFType::wrap_under_create_rule(tz_ref)
+        }
+    }
+
+    #[inline]
+    pub fn system() -> CFTimeZone {
+        unsafe {
+            let tz_ref = CFTimeZoneCopySystem();
+            TCFType::wrap_under_create_rule(tz_ref)
+        }
+    }
+
+    pub fn seconds_from_gmt(&self, date: CFDate) -> CFTimeInterval {
+        unsafe {
+            CFTimeZoneGetSecondsFromGMT(self.0, date.abs_time())
+        }
+    }
+
+    #[cfg(feature = "with-chrono")]
+    pub fn offset_at_date(&self, date: NaiveDateTime) -> FixedOffset {
+        let date = CFDate::from_naive_utc(date);
+        FixedOffset::east(self.seconds_from_gmt(date) as i32)
+    }
+
+    #[cfg(feature = "with-chrono")]
+    pub fn from_offset(offset: FixedOffset) -> CFTimeZone {
+        CFTimeZone::new(offset.local_minus_utc() as f64)
+    }
+}
+
+#[cfg(test)]
+mod test {
+    use super::CFTimeZone;
+
+    #[cfg(feature = "with-chrono")]
+    use chrono::{NaiveDateTime, FixedOffset};
+
+    #[test]
+    fn timezone_comparison() {
+        let system = CFTimeZone::system();
+        let default = CFTimeZone::default();
+        assert_eq!(system, default);
+    }
+
+    #[test]
+    #[cfg(feature = "with-chrono")]
+    fn timezone_chrono_conversion() {
+        let offset = FixedOffset::west(28800);
+        let tz = CFTimeZone::from_offset(offset);
+        let converted = tz.offset_at_date(NaiveDateTime::from_timestamp(0, 0));
+        assert_eq!(offset, converted);
+    }
+}
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/src/url.rs
@@ -0,0 +1,156 @@
+// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! A URL type for Core Foundation.
+
+pub use core_foundation_sys::url::*;
+
+use base::{TCFType, CFIndex};
+use string::{CFString};
+
+use core_foundation_sys::base::{kCFAllocatorDefault, Boolean};
+use std::fmt;
+use std::ptr;
+use std::path::{Path, PathBuf};
+use std::mem;
+
+use libc::{strlen, PATH_MAX};
+
+#[cfg(unix)]
+use std::os::unix::ffi::OsStrExt;
+#[cfg(unix)]
+use std::ffi::OsStr;
+
+
+declare_TCFType!(CFURL, CFURLRef);
+impl_TCFType!(CFURL, CFURLRef, CFURLGetTypeID);
+
+impl fmt::Debug for CFURL {
+    #[inline]
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        unsafe {
+            let string: CFString = TCFType::wrap_under_get_rule(CFURLGetString(self.0));
+            write!(f, "{}", string.to_string())
+        }
+    }
+}
+
+impl CFURL {
+    pub fn from_path<P: AsRef<Path>>(path: P, isDirectory: bool) -> Option<CFURL> {
+        let path_bytes;
+        #[cfg(unix)]
+        {
+            path_bytes = path.as_ref().as_os_str().as_bytes()
+        }
+        #[cfg(not(unix))]
+        {
+            // XXX: Getting non-valid UTF8 paths into CoreFoundation on Windows is going to be unpleasant
+            // CFURLGetWideFileSystemRepresentation might help
+            path_bytes = match path.as_ref().to_str() {
+                Some(path) => path,
+                None => return None,
+            }
+        }
+
+        unsafe {
+            let url_ref = CFURLCreateFromFileSystemRepresentation(ptr::null_mut(), path_bytes.as_ptr(), path_bytes.len() as CFIndex, isDirectory as u8);
+            if url_ref.is_null() {
+                return None;
+            }
+            Some(TCFType::wrap_under_create_rule(url_ref))
+        }
+    }
+
+    pub fn from_file_system_path(filePath: CFString, pathStyle: CFURLPathStyle, isDirectory: bool) -> CFURL {
+        unsafe {
+            let url_ref = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, filePath.as_concrete_TypeRef(), pathStyle, isDirectory as u8);
+            TCFType::wrap_under_create_rule(url_ref)
+        }
+    }
+
+    #[cfg(unix)]
+    pub fn to_path(&self) -> Option<PathBuf> {
+        // implementing this on Windows is more complicated because of the different OsStr representation
+        unsafe {
+            let mut buf: [u8; PATH_MAX as usize] = mem::uninitialized();
+            let result = CFURLGetFileSystemRepresentation(self.0, true as Boolean, buf.as_mut_ptr(), buf.len() as CFIndex);
+            if result == false as Boolean {
+                return None;
+            }
+            let len = strlen(buf.as_ptr() as *const i8);
+            let path = OsStr::from_bytes(&buf[0..len]);
+            Some(PathBuf::from(path))
+        }
+    }
+
+    pub fn get_string(&self) -> CFString {
+        unsafe {
+            TCFType::wrap_under_get_rule(CFURLGetString(self.0))
+        }
+    }
+
+    pub fn get_file_system_path(&self, pathStyle: CFURLPathStyle) -> CFString {
+        unsafe {
+            TCFType::wrap_under_create_rule(CFURLCopyFileSystemPath(self.as_concrete_TypeRef(), pathStyle))
+        }
+    }
+
+    pub fn absolute(&self) -> CFURL {
+        unsafe {
+            TCFType::wrap_under_create_rule(CFURLCopyAbsoluteURL(self.as_concrete_TypeRef()))
+        }
+    }
+}
+
+#[test]
+fn file_url_from_path() {
+    let path = "/usr/local/foo/";
+    let cfstr_path = CFString::from_static_string(path);
+    let cfurl = CFURL::from_file_system_path(cfstr_path, kCFURLPOSIXPathStyle, true);
+    assert_eq!(cfurl.get_string().to_string(), "file:///usr/local/foo/");
+}
+
+#[cfg(unix)]
+#[test]
+fn non_utf8() {
+    use std::ffi::OsStr;
+    let path = Path::new(OsStr::from_bytes(b"/\xC0/blame"));
+    let cfurl = CFURL::from_path(path, false).unwrap();
+    assert_eq!(cfurl.to_path().unwrap(), path);
+    let len = unsafe { CFURLGetBytes(cfurl.as_concrete_TypeRef(), ptr::null_mut(), 0) };
+    assert_eq!(len, 17);
+}
+
+#[test]
+fn absolute_file_url() {
+    use core_foundation_sys::url::CFURLCreateWithFileSystemPathRelativeToBase;
+    use std::path::PathBuf;
+
+    let path = "/usr/local/foo";
+    let file = "bar";
+
+    let cfstr_path = CFString::from_static_string(path);
+    let cfstr_file = CFString::from_static_string(file);
+    let cfurl_base = CFURL::from_file_system_path(cfstr_path, kCFURLPOSIXPathStyle, true);
+    let cfurl_relative: CFURL = unsafe {
+        let url_ref = CFURLCreateWithFileSystemPathRelativeToBase(kCFAllocatorDefault,
+            cfstr_file.as_concrete_TypeRef(),
+            kCFURLPOSIXPathStyle,
+            false as u8,
+            cfurl_base.as_concrete_TypeRef());
+        TCFType::wrap_under_create_rule(url_ref)
+    };
+
+    let mut absolute_path = PathBuf::from(path);
+    absolute_path.push(file);
+
+    assert_eq!(cfurl_relative.get_file_system_path(kCFURLPOSIXPathStyle).to_string(), file);
+    assert_eq!(cfurl_relative.absolute().get_file_system_path(kCFURLPOSIXPathStyle).to_string(),
+        absolute_path.to_str().unwrap());
+}
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/src/uuid.rs
@@ -0,0 +1,112 @@
+// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Core Foundation UUID objects.
+
+#[cfg(feature = "with-uuid")]
+extern crate uuid;
+
+pub use core_foundation_sys::uuid::*;
+use core_foundation_sys::base::kCFAllocatorDefault;
+
+use base::TCFType;
+
+#[cfg(feature = "with-uuid")]
+use self::uuid::Uuid;
+
+
+declare_TCFType! {
+    /// A UUID.
+    CFUUID, CFUUIDRef
+}
+impl_TCFType!(CFUUID, CFUUIDRef, CFUUIDGetTypeID);
+impl_CFTypeDescription!(CFUUID);
+
+impl CFUUID {
+    #[inline]
+    pub fn new() -> CFUUID {
+        unsafe {
+            let uuid_ref = CFUUIDCreate(kCFAllocatorDefault);
+            TCFType::wrap_under_create_rule(uuid_ref)
+        }
+    }
+}
+
+#[cfg(feature = "with-uuid")]
+impl Into<Uuid> for CFUUID {
+    fn into(self) -> Uuid {
+        let b = unsafe {
+            CFUUIDGetUUIDBytes(self.0)
+        };
+        let bytes = [
+            b.byte0,
+            b.byte1,
+            b.byte2,
+            b.byte3,
+            b.byte4,
+            b.byte5,
+            b.byte6,
+            b.byte7,
+            b.byte8,
+            b.byte9,
+            b.byte10,
+            b.byte11,
+            b.byte12,
+            b.byte13,
+            b.byte14,
+            b.byte15,
+        ];
+        Uuid::from_bytes(&bytes).unwrap()
+    }
+}
+
+#[cfg(feature = "with-uuid")]
+impl From<Uuid> for CFUUID {
+    fn from(uuid: Uuid) -> CFUUID {
+        let b = uuid.as_bytes();
+        let bytes = CFUUIDBytes {
+            byte0: b[0],
+            byte1: b[1],
+            byte2: b[2],
+            byte3: b[3],
+            byte4: b[4],
+            byte5: b[5],
+            byte6: b[6],
+            byte7: b[7],
+            byte8: b[8],
+            byte9: b[9],
+            byte10: b[10],
+            byte11: b[11],
+            byte12: b[12],
+            byte13: b[13],
+            byte14: b[14],
+            byte15: b[15],
+        };
+        unsafe {
+            let uuid_ref = CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault, bytes);
+            TCFType::wrap_under_create_rule(uuid_ref)
+        }
+    }
+}
+
+
+#[cfg(test)]
+#[cfg(feature = "with-uuid")]
+mod test {
+    use super::CFUUID;
+    use uuid::Uuid;
+
+    #[test]
+    fn uuid_conversion() {
+        let cf_uuid = CFUUID::new();
+        let uuid: Uuid = cf_uuid.clone().into();
+        let converted = CFUUID::from(uuid);
+        assert!(cf_uuid == converted);
+    }
+}
copy from third_party/rust/core-foundation/tests/use_macro_outside_crate.rs
copy to third_party/rust/core-foundation-0.5.1/tests/use_macro_outside_crate.rs
copy from third_party/rust/core-foundation-sys/.cargo-checksum.json
copy to third_party/rust/core-foundation-sys-0.5.1/.cargo-checksum.json
copy from third_party/rust/core-foundation-sys/Cargo.toml
copy to third_party/rust/core-foundation-sys-0.5.1/Cargo.toml
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-sys-0.5.1/LICENSE-APACHE
@@ -0,0 +1,201 @@
+                              Apache License
+                        Version 2.0, January 2004
+                     http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+   "License" shall mean the terms and conditions for use, reproduction,
+   and distribution as defined by Sections 1 through 9 of this document.
+
+   "Licensor" shall mean the copyright owner or entity authorized by
+   the copyright owner that is granting the License.
+
+   "Legal Entity" shall mean the union of the acting entity and all
+   other entities that control, are controlled by, or are under common
+   control with that entity. For the purposes of this definition,
+   "control" means (i) the power, direct or indirect, to cause the
+   direction or management of such entity, whether by contract or
+   otherwise, or (ii) ownership of fifty percent (50%) or more of the
+   outstanding shares, or (iii) beneficial ownership of such entity.
+
+   "You" (or "Your") shall mean an individual or Legal Entity
+   exercising permissions granted by this License.
+
+   "Source" form shall mean the preferred form for making modifications,
+   including but not limited to software source code, documentation
+   source, and configuration files.
+
+   "Object" form shall mean any form resulting from mechanical
+   transformation or translation of a Source form, including but
+   not limited to compiled object code, generated documentation,
+   and conversions to other media types.
+
+   "Work" shall mean the work of authorship, whether in Source or
+   Object form, made available under the License, as indicated by a
+   copyright notice that is included in or attached to the work
+   (an example is provided in the Appendix below).
+
+   "Derivative Works" shall mean any work, whether in Source or Object
+   form, that is based on (or derived from) the Work and for which the
+   editorial revisions, annotations, elaborations, or other modifications
+   represent, as a whole, an original work of authorship. For the purposes
+   of this License, Derivative Works shall not include works that remain
+   separable from, or merely link (or bind by name) to the interfaces of,
+   the Work and Derivative Works thereof.
+
+   "Contribution" shall mean any work of authorship, including
+   the original version of the Work and any modifications or additions
+   to that Work or Derivative Works thereof, that is intentionally
+   submitted to Licensor for inclusion in the Work by the copyright owner
+   or by an individual or Legal Entity authorized to submit on behalf of
+   the copyright owner. For the purposes of this definition, "submitted"
+   means any form of electronic, verbal, or written communication sent
+   to the Licensor or its representatives, including but not limited to
+   communication on electronic mailing lists, source code control systems,
+   and issue tracking systems that are managed by, or on behalf of, the
+   Licensor for the purpose of discussing and improving the Work, but
+   excluding communication that is conspicuously marked or otherwise
+   designated in writing by the copyright owner as "Not a Contribution."
+
+   "Contributor" shall mean Licensor and any individual or Legal Entity
+   on behalf of whom a Contribution has been received by Licensor and
+   subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of
+   this License, each Contributor hereby grants to You a perpetual,
+   worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+   copyright license to reproduce, prepare Derivative Works of,
+   publicly display, publicly perform, sublicense, and distribute the
+   Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of
+   this License, each Contributor hereby grants to You a perpetual,
+   worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+   (except as stated in this section) patent license to make, have made,
+   use, offer to sell, sell, import, and otherwise transfer the Work,
+   where such license applies only to those patent claims licensable
+   by such Contributor that are necessarily infringed by their
+   Contribution(s) alone or by combination of their Contribution(s)
+   with the Work to which such Contribution(s) was submitted. If You
+   institute patent litigation against any entity (including a
+   cross-claim or counterclaim in a lawsuit) alleging that the Work
+   or a Contribution incorporated within the Work constitutes direct
+   or contributory patent infringement, then any patent licenses
+   granted to You under this License for that Work shall terminate
+   as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the
+   Work or Derivative Works thereof in any medium, with or without
+   modifications, and in Source or Object form, provided that You
+   meet the following conditions:
+
+   (a) You must give any other recipients of the Work or
+       Derivative Works a copy of this License; and
+
+   (b) You must cause any modified files to carry prominent notices
+       stating that You changed the files; and
+
+   (c) You must retain, in the Source form of any Derivative Works
+       that You distribute, all copyright, patent, trademark, and
+       attribution notices from the Source form of the Work,
+       excluding those notices that do not pertain to any part of
+       the Derivative Works; and
+
+   (d) If the Work includes a "NOTICE" text file as part of its
+       distribution, then any Derivative Works that You distribute must
+       include a readable copy of the attribution notices contained
+       within such NOTICE file, excluding those notices that do not
+       pertain to any part of the Derivative Works, in at least one
+       of the following places: within a NOTICE text file distributed
+       as part of the Derivative Works; within the Source form or
+       documentation, if provided along with the Derivative Works; or,
+       within a display generated by the Derivative Works, if and
+       wherever such third-party notices normally appear. The contents
+       of the NOTICE file are for informational purposes only and
+       do not modify the License. You may add Your own attribution
+       notices within Derivative Works that You distribute, alongside
+       or as an addendum to the NOTICE text from the Work, provided
+       that such additional attribution notices cannot be construed
+       as modifying the License.
+
+   You may add Your own copyright statement to Your modifications and
+   may provide additional or different license terms and conditions
+   for use, reproduction, or distribution of Your modifications, or
+   for any such Derivative Works as a whole, provided Your use,
+   reproduction, and distribution of the Work otherwise complies with
+   the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise,
+   any Contribution intentionally submitted for inclusion in the Work
+   by You to the Licensor shall be under the terms and conditions of
+   this License, without any additional terms or conditions.
+   Notwithstanding the above, nothing herein shall supersede or modify
+   the terms of any separate license agreement you may have executed
+   with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade
+   names, trademarks, service marks, or product names of the Licensor,
+   except as required for reasonable and customary use in describing the
+   origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or
+   agreed to in writing, Licensor provides the Work (and each
+   Contributor provides its Contributions) on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+   implied, including, without limitation, any warranties or conditions
+   of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+   PARTICULAR PURPOSE. You are solely responsible for determining the
+   appropriateness of using or redistributing the Work and assume any
+   risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory,
+   whether in tort (including negligence), contract, or otherwise,
+   unless required by applicable law (such as deliberate and grossly
+   negligent acts) or agreed to in writing, shall any Contributor be
+   liable to You for damages, including any direct, indirect, special,
+   incidental, or consequential damages of any character arising as a
+   result of this License or out of the use or inability to use the
+   Work (including but not limited to damages for loss of goodwill,
+   work stoppage, computer failure or malfunction, or any and all
+   other commercial damages or losses), even if such Contributor
+   has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing
+   the Work or Derivative Works thereof, You may choose to offer,
+   and charge a fee for, acceptance of support, warranty, indemnity,
+   or other liability obligations and/or rights consistent with this
+   License. However, in accepting such obligations, You may act only
+   on Your own behalf and on Your sole responsibility, not on behalf
+   of any other Contributor, and only if You agree to indemnify,
+   defend, and hold each Contributor harmless for any liability
+   incurred by, or claims asserted against, such Contributor by reason
+   of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
+
+APPENDIX: How to apply the Apache License to your work.
+
+   To apply the Apache License to your work, attach the following
+   boilerplate notice, with the fields enclosed by brackets "[]"
+   replaced with your own identifying information. (Don't include
+   the brackets!)  The text should be enclosed in the appropriate
+   comment syntax for the file format. We also recommend that a
+   file or class name and description of purpose be included on the
+   same "printed page" as the copyright notice for easier
+   identification within third-party archives.
+
+Copyright [yyyy] [name of copyright owner]
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+	http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-sys-0.5.1/LICENSE-MIT
@@ -0,0 +1,25 @@
+Copyright (c) 2012-2013 Mozilla Foundation
+
+Permission is hereby granted, free of charge, to any
+person obtaining a copy of this software and associated
+documentation files (the "Software"), to deal in the
+Software without restriction, including without
+limitation the rights to use, copy, modify, merge,
+publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software
+is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice
+shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
+ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
+TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
+SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-sys-0.5.1/build.rs
@@ -0,0 +1,14 @@
+// Copyright 2013-2015 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main() {
+    if std::env::var("TARGET").unwrap().contains("-apple") {
+        println!("cargo:rustc-link-lib=framework=CoreFoundation");
+    }
+}
copy from third_party/rust/core-foundation-sys/src/array.rs
copy to third_party/rust/core-foundation-sys-0.5.1/src/array.rs
copy from third_party/rust/core-foundation-sys/src/base.rs
copy to third_party/rust/core-foundation-sys-0.5.1/src/base.rs
copy from third_party/rust/core-foundation-sys/src/bundle.rs
copy to third_party/rust/core-foundation-sys-0.5.1/src/bundle.rs
copy from third_party/rust/core-foundation-sys/src/data.rs
copy to third_party/rust/core-foundation-sys-0.5.1/src/data.rs
copy from third_party/rust/core-foundation-sys/src/date.rs
copy to third_party/rust/core-foundation-sys-0.5.1/src/date.rs
copy from third_party/rust/core-foundation-sys/src/dictionary.rs
copy to third_party/rust/core-foundation-sys-0.5.1/src/dictionary.rs
copy from third_party/rust/core-foundation-sys/src/error.rs
copy to third_party/rust/core-foundation-sys-0.5.1/src/error.rs
copy from third_party/rust/core-foundation-sys/src/filedescriptor.rs
copy to third_party/rust/core-foundation-sys-0.5.1/src/filedescriptor.rs
copy from third_party/rust/core-foundation-sys/src/lib.rs
copy to third_party/rust/core-foundation-sys-0.5.1/src/lib.rs
copy from third_party/rust/core-foundation-sys/src/messageport.rs
copy to third_party/rust/core-foundation-sys-0.5.1/src/messageport.rs
copy from third_party/rust/core-foundation-sys/src/number.rs
copy to third_party/rust/core-foundation-sys-0.5.1/src/number.rs
copy from third_party/rust/core-foundation-sys/src/propertylist.rs
copy to third_party/rust/core-foundation-sys-0.5.1/src/propertylist.rs
copy from third_party/rust/core-foundation-sys/src/runloop.rs
copy to third_party/rust/core-foundation-sys-0.5.1/src/runloop.rs
copy from third_party/rust/core-foundation-sys/src/set.rs
copy to third_party/rust/core-foundation-sys-0.5.1/src/set.rs
copy from third_party/rust/core-foundation-sys/src/string.rs
copy to third_party/rust/core-foundation-sys-0.5.1/src/string.rs
copy from third_party/rust/core-foundation-sys/src/timezone.rs
copy to third_party/rust/core-foundation-sys-0.5.1/src/timezone.rs
copy from third_party/rust/core-foundation-sys/src/url.rs
copy to third_party/rust/core-foundation-sys-0.5.1/src/url.rs
copy from third_party/rust/core-foundation-sys/src/uuid.rs
copy to third_party/rust/core-foundation-sys-0.5.1/src/uuid.rs
--- a/third_party/rust/core-foundation-sys/.cargo-checksum.json
+++ b/third_party/rust/core-foundation-sys/.cargo-checksum.json
@@ -1,1 +1,1 @@
-{"files":{"Cargo.toml":"08b77adecca4222d97b0fb359b1c9ce97983e0e0914a4418834c032395af76ea","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"62065228e42caebca7e7d7db1204cbb867033de5982ca4009928915e4095f3a3","build.rs":"9433ed3b20cc99e716dda4c6d8507c29bc04882544cbbea8d4e48ba80fd0fa12","src/array.rs":"c70be1c0485612ac327a4fc9ca87098034e13df80dead23167560a38471fb823","src/base.rs":"37ad5b765d9e70f043f70a26da65cc46f0af5f1361e431e6f8591a143a31da31","src/bundle.rs":"b4e0e9b7ca2e35e3dc9bee316690538a5d17a470f8173f6b80c6816c847d12ec","src/data.rs":"21e968951fe56e080d33474f4438de2dfb7e0c8af426a6dfb100efdd6c530eec","src/date.rs":"90f29b07d3bd1549a3ab64adaaf153aff5ba546c1cd449f7248479d26bce9687","src/dictionary.rs":"37d881fbcf3232f90ab8648084b0f26b45ffee882b95e76831ac206f3e35f7de","src/error.rs":"61bc31a401ec6c8495668175eade9284e257da056fc666af74a5555af5daf33f","src/filedescriptor.rs":"14800c805b66f1fd6f995a6e73138d65a724163acb8a3f8f2539c807d333473d","src/lib.rs":"1038a1292f6f6c790ae055242015b8e3b91c2cccce34bfba240403399149f64c","src/messageport.rs":"f22b8552ff8b8e1edf25fe322eeabd9d7e5472b11514b95bc936387e4fa51b2a","src/number.rs":"4e69c688f24a1226fb40faec7d18861b5a617afcedbb352331c45a8e4eff292a","src/propertylist.rs":"cc2b27f8f8ebc80c03871b7b1ad50ee348539b016078ce721c86b8cd5f9d75bd","src/runloop.rs":"1d4aba9425669ef32450396c31655a90daf0e67d579e4617465fb7abe23c047f","src/set.rs":"22055b5ce6a2ce37847ee955f5e6e517348a351770d335373704776bc5412b9f","src/string.rs":"0e9373c6e48c97d7cbdb2ceaa07bc0af4e5d25ab0f91b138b4f8667cff337f4e","src/timezone.rs":"6711924b967d96ba88be4976cf17dfd3f9573033115da8e61ad07e8b0f26cdb7","src/url.rs":"b85110fe203c685719ba92517ff3c09ce0fe358e15380ecc0bd18356ac3573ed","src/uuid.rs":"e591e0bac875832acc15ea7ee0c9bff296543f4f77470101de0602ee69c2e527"},"package":"716c271e8613ace48344f723b60b900a93150271e5be206212d052bbc0883efa"}
\ No newline at end of file
+{"files":{"Cargo.toml":"49682adfbd90c37132993902a2e4e131474859c1f12c49bb150417d44dd47aa0","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"62065228e42caebca7e7d7db1204cbb867033de5982ca4009928915e4095f3a3","build.rs":"9433ed3b20cc99e716dda4c6d8507c29bc04882544cbbea8d4e48ba80fd0fa12","src/array.rs":"40c305658e16b07d86353a5ad34e7b5fb98720f19cc2b5173360d6a61ce2642f","src/base.rs":"f0f8424099a4269e2359b063c3f055e115aec6df0f6aa71695ca91257dfd64e2","src/bundle.rs":"e8ad47f9f0280e1eef7e9aea2eb88020443953ac2cda234396321450ffc3d48a","src/data.rs":"4547e98f4e25a99606d8f33e82f8de3d9889612485d445d4467138b8ad29b7e9","src/date.rs":"c064ee4c3ebd1927532c34871e2e41179d6e3c3e400f6b409a18ad9e2337477f","src/dictionary.rs":"3327a6f90f1e0db5e3fde1973e2df4143ca896716a816d03f2b17c8e988c5159","src/error.rs":"6205ebeb7631daa8bcd560862b6daa10f640c8c117ce5f6f7184f268dcbcb42a","src/filedescriptor.rs":"49580654b657811fade7adaa256f5f895cb011c9baa4731e2f44a6ec7fdba235","src/lib.rs":"0b1fa29a241df0bd6a2310e4905766150687f62453f635a693219f665fc70658","src/messageport.rs":"e9227d5907cba8e29cdeea41bcb3ae5c7840220442953ab19aace31a84542f47","src/number.rs":"b1154203e74cb2258ba5520e20bcd4d524f1a957e09a19dd026b18d23baa3868","src/propertylist.rs":"7ec928438826c4ce40befedf3de0a37c8ecbc0fc17896dfa629d5864000b2cfe","src/runloop.rs":"67a6c2e4773f13de9452c9f8e4791b9889e03e56c07a7bdf64dbba99e9821f45","src/set.rs":"8aef5f4ba75a067e271ad6cb960569f1d22a0acee0eb6c79e31bb8b636619d9d","src/string.rs":"3ebfa11bba928d0ab1b07ecc0bd0f11367642eb818c8e21f08c16a4be8f9494f","src/timezone.rs":"42741f556af081be32987d2705488959c60aeb794e7c737b092f0dce5851ca89","src/url.rs":"4cd2950660ad234f7f833b3f5c092f7322465085452cca8ced623564400cdef9","src/uuid.rs":"82f75efa73d0842dff2e13d299c166c6593a77fcb69c4b7629a2df1c17ae507d"},"package":"b2a53cce0ddcf7e7e1f998738d757d5a3bf08bf799a180e50ebe50d298f52f5a"}
\ No newline at end of file
--- a/third_party/rust/core-foundation-sys/Cargo.toml
+++ b/third_party/rust/core-foundation-sys/Cargo.toml
@@ -7,21 +7,21 @@
 #
 # If you believe there's an error in this file please file an
 # issue against the rust-lang/cargo repository. If you're
 # editing this file be aware that the upstream Cargo.toml
 # will likely look very different (and much more reasonable)
 
 [package]
 name = "core-foundation-sys"
-version = "0.5.1"
+version = "0.6.0"
 authors = ["The Servo Project Developers"]
 build = "build.rs"
 description = "Bindings to Core Foundation for OS X"
 homepage = "https://github.com/servo/core-foundation-rs"
 license = "MIT / Apache-2.0"
 repository = "https://github.com/servo/core-foundation-rs"
-[dependencies.libc]
-version = "0.2"
+
+[dependencies]
 
 [features]
 mac_os_10_7_support = []
 mac_os_10_8_features = []
--- a/third_party/rust/core-foundation-sys/src/array.rs
+++ b/third_party/rust/core-foundation-sys/src/array.rs
@@ -2,17 +2,17 @@
 // file at the top-level directory of this distribution.
 //
 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use libc::c_void;
+use std::os::raw::c_void;
 
 use base::{CFRange, CFIndex, CFAllocatorRef, CFTypeID, Boolean};
 use string::CFStringRef;
 
 pub type CFArrayRetainCallBack = extern "C" fn(allocator: CFAllocatorRef, value: *const c_void) -> *const c_void;
 pub type CFArrayReleaseCallBack = extern "C" fn(allocator: CFAllocatorRef, value: *const c_void);
 pub type CFArrayCopyDescriptionCallBack = extern "C" fn(value: *const c_void) -> CFStringRef;
 pub type CFArrayEqualCallBack = extern "C" fn(value1: *const c_void, value2: *const c_void) -> Boolean;
--- a/third_party/rust/core-foundation-sys/src/base.rs
+++ b/third_party/rust/core-foundation-sys/src/base.rs
@@ -3,17 +3,17 @@
 //
 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
 use std::cmp::Ordering;
-use libc::{c_uint, c_long, c_ulong, c_void, c_int};
+use std::os::raw::{c_uint, c_long, c_ulong, c_void, c_int};
 use string::CFStringRef;
 
 pub type Boolean = u8;
 pub type CFIndex = c_long;
 pub type mach_port_t = c_uint;
 pub type CFAllocatorRef = *const c_void;
 pub type CFNullRef = *const c_void;
 pub type CFHashCode = c_ulong;
--- a/third_party/rust/core-foundation-sys/src/bundle.rs
+++ b/third_party/rust/core-foundation-sys/src/bundle.rs
@@ -2,17 +2,17 @@
 // file at the top-level directory of this distribution.
 //
 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use libc::c_void;
+use std::os::raw::c_void;
 
 use base::{CFTypeID, CFAllocatorRef};
 use url::CFURLRef;
 use dictionary::CFDictionaryRef;
 use string::CFStringRef;
 
 #[repr(C)]
 pub struct __CFBundle(c_void);
--- a/third_party/rust/core-foundation-sys/src/data.rs
+++ b/third_party/rust/core-foundation-sys/src/data.rs
@@ -1,9 +1,18 @@
-use libc::c_void;
+// Copyright 2013-2015 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use std::os::raw::c_void;
 
 use base::{CFAllocatorRef, CFTypeID, CFIndex};
 
 #[repr(C)]
 pub struct __CFData(c_void);
 
 pub type CFDataRef = *const __CFData;
 
--- a/third_party/rust/core-foundation-sys/src/date.rs
+++ b/third_party/rust/core-foundation-sys/src/date.rs
@@ -2,17 +2,17 @@
 // file at the top-level directory of this distribution.
 //
 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use libc::c_void;
+use std::os::raw::c_void;
 
 use base::{CFAllocatorRef, CFComparisonResult, CFTypeID};
 
 #[repr(C)]
 pub struct __CFDate(c_void);
 
 pub type CFDateRef = *const __CFDate;
 
--- a/third_party/rust/core-foundation-sys/src/dictionary.rs
+++ b/third_party/rust/core-foundation-sys/src/dictionary.rs
@@ -2,17 +2,17 @@
 // file at the top-level directory of this distribution.
 //
 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use libc::{c_void};
+use std::os::raw::c_void;
 
 use base::{CFAllocatorRef, CFHashCode, CFIndex, CFTypeID, Boolean};
 use string::CFStringRef;
 
 pub type CFDictionaryApplierFunction = extern "C" fn(key: *const c_void, value: *const c_void, context: *mut c_void);
 
 pub type CFDictionaryRetainCallBack = extern "C" fn(allocator: CFAllocatorRef, value: *const c_void) -> *const c_void;
 pub type CFDictionaryReleaseCallBack = extern "C" fn(allocator: CFAllocatorRef, value: *const c_void);
--- a/third_party/rust/core-foundation-sys/src/error.rs
+++ b/third_party/rust/core-foundation-sys/src/error.rs
@@ -2,17 +2,17 @@
 // file at the top-level directory of this distribution.
 //
 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use libc::c_void;
+use std::os::raw::c_void;
 
 use base::{CFTypeID, CFIndex};
 use string::CFStringRef;
 
 #[repr(C)]
 pub struct __CFError(c_void);
 
 pub type CFErrorRef = *mut __CFError;
--- a/third_party/rust/core-foundation-sys/src/filedescriptor.rs
+++ b/third_party/rust/core-foundation-sys/src/filedescriptor.rs
@@ -1,9 +1,19 @@
-use libc::{c_void, c_int};
+// Copyright 2013-2015 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use std::os::raw::{c_int, c_void};
+
 use base::{Boolean, CFIndex, CFTypeID, CFOptionFlags, CFAllocatorRef};
 use string::CFStringRef;
 use runloop::CFRunLoopSourceRef;
 
 pub type CFFileDescriptorNativeDescriptor = c_int;
 
 #[repr(C)]
 pub struct __CFFileDescriptor(c_void);
--- a/third_party/rust/core-foundation-sys/src/lib.rs
+++ b/third_party/rust/core-foundation-sys/src/lib.rs
@@ -5,18 +5,16 @@
 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 #![allow(non_snake_case, non_camel_case_types, non_upper_case_globals, improper_ctypes)]
 
 #![cfg_attr(all(feature="mac_os_10_7_support", feature="mac_os_10_8_features"), feature(linkage))] // back-compat requires weak linkage
 
-extern crate libc;
-
 pub mod array;
 pub mod base;
 pub mod bundle;
 pub mod data;
 pub mod date;
 pub mod dictionary;
 pub mod error;
 pub mod filedescriptor;
--- a/third_party/rust/core-foundation-sys/src/messageport.rs
+++ b/third_party/rust/core-foundation-sys/src/messageport.rs
@@ -2,17 +2,17 @@
 // file at the top-level directory of this distribution.
 //
 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use libc::c_void;
+use std::os::raw::c_void;
 
 use base::{CFAllocatorRef, CFIndex, CFTypeID, Boolean};
 use data::CFDataRef;
 use date::CFTimeInterval;
 use runloop::CFRunLoopSourceRef;
 use string::CFStringRef;
 
 #[repr(C)]
--- a/third_party/rust/core-foundation-sys/src/number.rs
+++ b/third_party/rust/core-foundation-sys/src/number.rs
@@ -2,17 +2,17 @@
 // file at the top-level directory of this distribution.
 //
 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use libc::c_void;
+use std::os::raw::c_void;
 
 use base::{CFAllocatorRef, CFTypeID, CFComparisonResult};
 
 #[repr(C)]
 pub struct __CFBoolean(c_void);
 
 pub type CFBooleanRef = *const __CFBoolean;
 
--- a/third_party/rust/core-foundation-sys/src/propertylist.rs
+++ b/third_party/rust/core-foundation-sys/src/propertylist.rs
@@ -1,8 +1,17 @@
+// Copyright 2013-2015 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
 use base::{CFAllocatorRef, CFIndex, CFOptionFlags, CFTypeRef};
 use data::CFDataRef;
 use error::CFErrorRef;
 
 pub type CFPropertyListRef = CFTypeRef;
 
 pub type CFPropertyListFormat = CFIndex;
 pub const kCFPropertyListOpenStepFormat: CFPropertyListFormat = 1;
--- a/third_party/rust/core-foundation-sys/src/runloop.rs
+++ b/third_party/rust/core-foundation-sys/src/runloop.rs
@@ -2,17 +2,17 @@
 // file at the top-level directory of this distribution.
 //
 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use libc::c_void;
+use std::os::raw::c_void;
 
 use array::CFArrayRef;
 use base::{Boolean, CFIndex, CFTypeID, CFAllocatorRef, CFOptionFlags, CFHashCode, mach_port_t};
 use date::{CFAbsoluteTime, CFTimeInterval};
 use string::CFStringRef;
 
 #[repr(C)]
 pub struct __CFRunLoop(c_void);
--- a/third_party/rust/core-foundation-sys/src/set.rs
+++ b/third_party/rust/core-foundation-sys/src/set.rs
@@ -2,17 +2,17 @@
 // file at the top-level directory of this distribution.
 //
 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use libc::c_void;
+use std::os::raw::c_void;
 
 use base::{CFAllocatorRef, CFIndex, CFTypeID};
 
 pub type CFSetApplierFunction = extern "C" fn (value: *const c_void,
                                                context: *const c_void);
 pub type CFSetRetainCallBack = *const u8;
 pub type CFSetReleaseCallBack = *const u8;
 pub type CFSetCopyDescriptionCallBack = *const u8;
--- a/third_party/rust/core-foundation-sys/src/string.rs
+++ b/third_party/rust/core-foundation-sys/src/string.rs
@@ -2,17 +2,17 @@
 // file at the top-level directory of this distribution.
 //
 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use libc::{c_char, c_ushort, c_void};
+use std::os::raw::{c_char, c_ushort, c_void};
 
 use base::{Boolean, CFOptionFlags, CFIndex, CFAllocatorRef, CFRange, CFTypeID};
 
 pub type UniChar = c_ushort;
 
 // CFString.h
 
 pub type CFStringCompareFlags = CFOptionFlags;
--- a/third_party/rust/core-foundation-sys/src/timezone.rs
+++ b/third_party/rust/core-foundation-sys/src/timezone.rs
@@ -2,17 +2,17 @@
 // file at the top-level directory of this distribution.
 //
 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use libc::c_void;
+use std::os::raw::c_void;
 
 use base::{CFAllocatorRef, CFTypeID};
 use date::{CFTimeInterval, CFAbsoluteTime};
 
 #[repr(C)]
 pub struct __CFTimeZone(c_void);
 
 pub type CFTimeZoneRef = *const __CFTimeZone;
--- a/third_party/rust/core-foundation-sys/src/url.rs
+++ b/third_party/rust/core-foundation-sys/src/url.rs
@@ -1,17 +1,18 @@
 // Copyright 2013-2015 The Servo Project Developers. See the COPYRIGHT
 // file at the top-level directory of this distribution.
 //
 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
-use libc::c_void;
+
+use std::os::raw::c_void;
 
 use base::{CFOptionFlags, CFIndex, CFAllocatorRef, Boolean, CFTypeID, CFTypeRef, SInt32};
 use string::{CFStringRef, CFStringEncoding};
 use error::CFErrorRef;
 
 #[repr(C)]
 pub struct __CFURL(c_void);
 
--- a/third_party/rust/core-foundation-sys/src/uuid.rs
+++ b/third_party/rust/core-foundation-sys/src/uuid.rs
@@ -1,17 +1,18 @@
 // Copyright 2013-2015 The Servo Project Developers. See the COPYRIGHT
 // file at the top-level directory of this distribution.
 //
 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
-use libc::c_void;
+
+use std::os::raw::c_void;
 
 use base::{CFAllocatorRef, CFTypeID};
 
 #[repr(C)]
 pub struct __CFUUID(c_void);
 
 pub type CFUUIDRef = *const __CFUUID;
 
--- a/third_party/rust/core-foundation/.cargo-checksum.json
+++ b/third_party/rust/core-foundation/.cargo-checksum.json
@@ -1,1 +1,1 @@
-{"files":{"Cargo.toml":"01f34fc5a612332c1a3aca9fcd89cd254afa02a27e6e538b0a2fa4280ef4fa66","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"62065228e42caebca7e7d7db1204cbb867033de5982ca4009928915e4095f3a3","src/array.rs":"d7af185408d937354f484e3ef97cb1a56e06b39965cbdc89de4bcdafb1d57f06","src/base.rs":"3032ea5253b2d4bd323d0656fc863d1e787642121702ad741c6055d96d0b3d5c","src/boolean.rs":"f5b4d295aaf6cc3681212afebeae2974c5d551125badcc066e6089ac0d2a0873","src/bundle.rs":"de092198bbc3486f617131e9f5f321812c4839da505409abaa70217f05f40450","src/data.rs":"a1d7e6430c745731fc7b2aee49af9f14e79c8a288951c82ea6507689a3356af8","src/date.rs":"a02f6cca7b6e8fbabc7713177429012658dba5146556e14a08e7baaf81958d83","src/dictionary.rs":"429005bc00890b655c8bdf0d7361eb20187ba8725552261aeaf52690c3f2683f","src/error.rs":"22c21087d9c2c103d1bcb2c4af33b684317bbda5d4747902e510d410f8c1a14b","src/filedescriptor.rs":"6ecd8570fad620fc20726539fe11e9f914e3742af9f3208a31727e89a4cd92ba","src/lib.rs":"900179d9ada4b8f000ced4121a9981cdf5ea83277e812177f4126779b818f50c","src/number.rs":"0c2842b8ea973a2c12173a13544b7d49472df11e166540ca5c28f38f54a746f6","src/propertylist.rs":"2ef4b1f44f688fd49ab810a0c8eccc7c40320fa16f93ff1453edcd2fd0d7200f","src/runloop.rs":"bb400ffe84949c4faa4a91f196aeb0a88b31984d206cd236c9daf27005b7744a","src/set.rs":"f23edb8fc009c24600f017131ab734e91129907248713618be89a0719622a9e9","src/string.rs":"50c08f0504c718576e4f2397218a963ab701de0214422dc82e1991d4ab9a00e3","src/timezone.rs":"65859378232ee55f04bc4544b88f5dbc21f5db01bd16f2df3e82136ee3ce26b4","src/url.rs":"ee5370a1ba88823ee0eaa8615c5dafd55cedd7bd50172e9f2caa52ed305e2233","src/uuid.rs":"c532363a1a322a88e195f8606e613a68012708454b0d61ffe7abce432ec68596","tests/use_macro_outside_crate.rs":"452a1329d304bf0301929278aab275cc9b6d57e4ae799b4acd6f2210b1ed0a49"},"package":"286e0b41c3a20da26536c6000a280585d519fd07b3956b43aed8a79e9edce980"}
\ No newline at end of file
+{"files":{"Cargo.toml":"c0a87a7aa5bb6fa2d5a20acc9384c37e686035d043ab9e169b6a1953bf62acaf","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"62065228e42caebca7e7d7db1204cbb867033de5982ca4009928915e4095f3a3","src/array.rs":"c0d67c88f85d01303998e95b8399bc5018a1de9de610ae6365cd05eea1377176","src/base.rs":"e33fedff5017420b88c7488691b42d714cce7f8a573e14bf04329e8b0a4b6a11","src/boolean.rs":"f5b4d295aaf6cc3681212afebeae2974c5d551125badcc066e6089ac0d2a0873","src/bundle.rs":"9cd6e6bf79ea9c8ac24b2e4d62b01b9ca22935cf331a51871e061269ef2c394d","src/data.rs":"a1d7e6430c745731fc7b2aee49af9f14e79c8a288951c82ea6507689a3356af8","src/date.rs":"a02f6cca7b6e8fbabc7713177429012658dba5146556e14a08e7baaf81958d83","src/dictionary.rs":"bdae97f43b95a9c97934b102e3ec383f026d5def81faeccdddb02c56b9c954a0","src/error.rs":"22c21087d9c2c103d1bcb2c4af33b684317bbda5d4747902e510d410f8c1a14b","src/filedescriptor.rs":"f01da404e42760a50d91a43af648e781916c0a10c23753bea94f0f67bdc4d00c","src/lib.rs":"b2939b828b4d7a863c26adde3c7f20f587bcbe071f4ab3625ee83bd14fda1645","src/number.rs":"0c2842b8ea973a2c12173a13544b7d49472df11e166540ca5c28f38f54a746f6","src/propertylist.rs":"762e1ed2db80badd1b491767c02a62c9aa31d9751ecd45c2e4b3bec89ebd40ad","src/runloop.rs":"98334ee796cea1634a5a9baf59d62f02c25b718d45baab5230a5cc14cb2ee6d5","src/set.rs":"f8e80eefe5257084350f04fce2cf6b051f08efe7921f6459cba67ccd7ea1e1e7","src/string.rs":"50c08f0504c718576e4f2397218a963ab701de0214422dc82e1991d4ab9a00e3","src/timezone.rs":"65859378232ee55f04bc4544b88f5dbc21f5db01bd16f2df3e82136ee3ce26b4","src/url.rs":"ee5370a1ba88823ee0eaa8615c5dafd55cedd7bd50172e9f2caa52ed305e2233","src/uuid.rs":"c532363a1a322a88e195f8606e613a68012708454b0d61ffe7abce432ec68596","tests/use_macro_outside_crate.rs":"ed5e74ac9e988f2609c0b785189f1e6368d693f6401603ad065521f3ab51df94"},"package":"c7caa6cb9e76ddddbea09a03266d6b3bc98cd41e9fb9b017c473e7cca593ec25"}
\ No newline at end of file
--- a/third_party/rust/core-foundation/Cargo.toml
+++ b/third_party/rust/core-foundation/Cargo.toml
@@ -7,28 +7,28 @@
 #
 # If you believe there's an error in this file please file an
 # issue against the rust-lang/cargo repository. If you're
 # editing this file be aware that the upstream Cargo.toml
 # will likely look very different (and much more reasonable)
 
 [package]
 name = "core-foundation"
-version = "0.5.1"
+version = "0.6.0"
 authors = ["The Servo Project Developers"]
 description = "Bindings to Core Foundation for OS X"
 homepage = "https://github.com/servo/core-foundation-rs"
 license = "MIT / Apache-2.0"
 repository = "https://github.com/servo/core-foundation-rs"
 [dependencies.chrono]
 version = "0.4"
 optional = true
 
 [dependencies.core-foundation-sys]
-version = "0.5.1"
+version = "0.6"
 
 [dependencies.libc]
 version = "0.2"
 
 [dependencies.uuid]
 version = "0.5"
 optional = true
 
--- a/third_party/rust/core-foundation/src/array.rs
+++ b/third_party/rust/core-foundation/src/array.rs
@@ -7,65 +7,27 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
 //! Heterogeneous immutable arrays.
 
 pub use core_foundation_sys::array::*;
 pub use core_foundation_sys::base::CFIndex;
 use core_foundation_sys::base::{CFTypeRef, CFRelease, kCFAllocatorDefault};
-use libc::c_void;
 use std::mem;
-use std::mem::ManuallyDrop;
 use std::marker::PhantomData;
-use std;
-use std::ops::Deref;
-use std::fmt::{Debug, Formatter};
+use std::os::raw::c_void;
+use ConcreteCFType;
 
-use base::{CFIndexConvertible, TCFType, TCFTypeRef, CFRange};
+use base::{CFIndexConvertible, TCFType, CFRange};
+use base::{FromVoid, ItemRef};
 
 /// A heterogeneous immutable array.
 pub struct CFArray<T = *const c_void>(CFArrayRef, PhantomData<T>);
 
-/// A reference to an element inside the array
-pub struct ItemRef<'a, T: 'a>(ManuallyDrop<T>, PhantomData<&'a T>);
-
-impl<'a, T> Deref for ItemRef<'a, T> {
-    type Target = T;
-
-    fn deref(&self) -> &T {
-        &self.0
-    }
-}
-
-impl<'a, T: Debug> Debug for ItemRef<'a, T> {
-    fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> {
-        self.0.fmt(f)
-    }
-}
-
-/// A trait describing how to convert from the stored *const c_void to the desired T
-pub unsafe trait FromVoid {
-    unsafe fn from_void<'a>(x: *const c_void) -> ItemRef<'a, Self> where Self: std::marker::Sized;
-}
-
-unsafe impl FromVoid for u32 {
-    unsafe fn from_void<'a>(x: *const c_void) -> ItemRef<'a, Self> {
-        // Functions like CGFontCopyTableTags treat the void*'s as u32's
-        // so we convert by casting directly
-        ItemRef(ManuallyDrop::new(x as u32), PhantomData)
-    }
-}
-
-unsafe impl<T: TCFType> FromVoid for T {
-    unsafe fn from_void<'a>(x: *const c_void) -> ItemRef<'a, Self> {
-        ItemRef(ManuallyDrop::new(TCFType::wrap_under_create_rule(T::Ref::from_void_ptr(x))), PhantomData)
-    }
-}
-
 impl<T> Drop for CFArray<T> {
     fn drop(&mut self) {
         unsafe { CFRelease(self.as_CFTypeRef()) }
     }
 }
 
 pub struct CFArrayIterator<'a, T: 'a> {
     array: &'a CFArray<T>,
@@ -88,18 +50,20 @@ impl<'a, T: FromVoid> Iterator for CFArr
 }
 
 impl<'a, T: FromVoid> ExactSizeIterator for CFArrayIterator<'a, T> {
     fn len(&self) -> usize {
         (self.array.len() - self.index) as usize
     }
 }
 
-impl_TCFTypeGeneric!(CFArray, CFArrayRef, CFArrayGetTypeID);
-impl_CFTypeDescriptionGeneric!(CFArray);
+impl_TCFType!(CFArray<T>, CFArrayRef, CFArrayGetTypeID);
+impl_CFTypeDescription!(CFArray);
+
+unsafe impl ConcreteCFType for CFArray<*const c_void> {}
 
 impl<T> CFArray<T> {
     /// Creates a new `CFArray` with the given elements, which must be `CFType` objects.
     pub fn from_CFTypes(elems: &[T]) -> CFArray<T> where T: TCFType {
         unsafe {
             let elems: Vec<CFTypeRef> = elems.iter().map(|elem| elem.as_CFTypeRef()).collect();
             let array_ref = CFArrayCreate(kCFAllocatorDefault,
                                           mem::transmute(elems.as_ptr()),
@@ -234,16 +198,32 @@ mod tests {
                 assert_eq!(x.retain_count(), 2);
                 assert_eq!(x.to_string(), "bar");
             }
         }
         assert_eq!(x.retain_count(), 1);
     }
 
     #[test]
+    fn iter_untyped_array() {
+        use string::{CFString, CFStringRef};
+        use base::TCFTypeRef;
+
+        let cf_string = CFString::from_static_string("bar");
+        let array: CFArray = CFArray::from_CFTypes(&[cf_string.clone()]).into_untyped();
+
+        let cf_strings = array.iter().map(|ptr| {
+            unsafe { CFString::wrap_under_get_rule(CFStringRef::from_void_ptr(*ptr)) }
+        }).collect::<Vec<_>>();
+        let strings = cf_strings.iter().map(|s| s.to_string()).collect::<Vec<_>>();
+        assert_eq!(cf_string.retain_count(), 3);
+        assert_eq!(&strings[..], &["bar"]);
+    }
+
+    #[test]
     fn should_box_and_unbox() {
         use number::CFNumber;
 
         let n0 = CFNumber::from(0);
         let n1 = CFNumber::from(1);
         let n2 = CFNumber::from(2);
         let n3 = CFNumber::from(3);
         let n4 = CFNumber::from(4);
--- a/third_party/rust/core-foundation/src/base.rs
+++ b/third_party/rust/core-foundation/src/base.rs
@@ -2,22 +2,28 @@
 // file at the top-level directory of this distribution.
 //
 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+use std;
 use std::fmt;
+use std::marker::PhantomData;
 use std::mem;
+use std::mem::ManuallyDrop;
+use std::ops::Deref;
+use std::os::raw::c_void;
 
 pub use core_foundation_sys::base::*;
 
 use string::CFString;
+use ConcreteCFType;
 
 pub trait CFIndexConvertible {
     /// Always use this method to construct a `CFIndex` value. It performs bounds checking to
     /// ensure the value is in range.
     fn to_CFIndex(self) -> CFIndex;
 }
 
 impl CFIndexConvertible for usize {
@@ -56,17 +62,17 @@ impl CFType {
     /// assert!(cf_type.downcast::<CFString>().unwrap().to_string() == "FooBar");
     /// // Casting it to some other type will yield `None`
     /// assert!(cf_type.downcast::<CFBoolean>().is_none());
     /// ```
     ///
     /// [`Box::downcast`]: https://doc.rust-lang.org/std/boxed/struct.Box.html#method.downcast
     /// [`CFPropertyList::downcast`]: ../propertylist/struct.CFPropertyList.html#method.downcast
     #[inline]
-    pub fn downcast<T: TCFType>(&self) -> Option<T> {
+    pub fn downcast<T: ConcreteCFType>(&self) -> Option<T> {
         if self.instance_of::<T>() {
             unsafe {
                 let reference = T::Ref::from_void_ptr(self.0);
                 Some(T::wrap_under_get_rule(reference))
             }
         } else {
             None
         }
@@ -231,16 +237,93 @@ impl TCFType for CFType {
 
     #[inline]
     fn type_id() -> CFTypeID {
         // FIXME(pcwalton): Is this right?
         0
     }
 }
 
+/// A reference to an element inside a container
+pub struct ItemRef<'a, T: 'a>(ManuallyDrop<T>, PhantomData<&'a T>);
+
+impl<'a, T> Deref for ItemRef<'a, T> {
+    type Target = T;
+
+    fn deref(&self) -> &T {
+        &self.0
+    }
+}
+
+impl<'a, T: fmt::Debug> fmt::Debug for ItemRef<'a, T> {
+    fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+        self.0.fmt(f)
+    }
+}
+
+impl<'a, T: PartialEq> PartialEq for ItemRef<'a, T> {
+    fn eq(&self, other: &Self) -> bool {
+        self.0.eq(&other.0)
+    }
+}
+
+/// A trait describing how to convert from the stored *const c_void to the desired T
+pub unsafe trait FromVoid {
+    unsafe fn from_void<'a>(x: *const c_void) -> ItemRef<'a, Self> where Self: std::marker::Sized;
+}
+
+unsafe impl FromVoid for u32 {
+    unsafe fn from_void<'a>(x: *const c_void) -> ItemRef<'a, Self> {
+        // Functions like CGFontCopyTableTags treat the void*'s as u32's
+        // so we convert by casting directly
+        ItemRef(ManuallyDrop::new(x as u32), PhantomData)
+    }
+}
+
+unsafe impl FromVoid for *const c_void {
+    unsafe fn from_void<'a>(x: *const c_void) -> ItemRef<'a, Self> {
+        ItemRef(ManuallyDrop::new(x), PhantomData)
+    }
+}
+
+unsafe impl<T: TCFType> FromVoid for T {
+    unsafe fn from_void<'a>(x: *const c_void) -> ItemRef<'a, Self> {
+        ItemRef(ManuallyDrop::new(TCFType::wrap_under_create_rule(T::Ref::from_void_ptr(x))), PhantomData)
+    }
+}
+
+/// A trait describing how to convert from the stored *const c_void to the desired T
+pub unsafe trait ToVoid<T> {
+    fn to_void(&self) -> *const c_void;
+}
+
+unsafe impl ToVoid<*const c_void> for *const c_void {
+    fn to_void(&self) -> *const c_void {
+        *self
+    }
+}
+
+unsafe impl<'a> ToVoid<CFType> for &'a CFType {
+    fn to_void(&self) -> *const ::std::os::raw::c_void {
+        self.as_concrete_TypeRef().as_void_ptr()
+    }
+}
+
+unsafe impl ToVoid<CFType> for CFType {
+    fn to_void(&self) -> *const ::std::os::raw::c_void {
+        self.as_concrete_TypeRef().as_void_ptr()
+    }
+}
+
+unsafe impl ToVoid<CFType> for CFTypeRef {
+    fn to_void(&self) -> *const ::std::os::raw::c_void {
+        self.as_void_ptr()
+    }
+}
+
 
 #[cfg(test)]
 mod tests {
     use super::*;
     use std::mem;
     use boolean::CFBoolean;
 
     #[test]
--- a/third_party/rust/core-foundation/src/bundle.rs
+++ b/third_party/rust/core-foundation/src/bundle.rs
@@ -7,19 +7,20 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
 //! Core Foundation Bundle Type
 
 pub use core_foundation_sys::bundle::*;
 use core_foundation_sys::base::kCFAllocatorDefault;
 
-use base::TCFType;
+use base::{CFType, TCFType};
 use url::CFURL;
 use dictionary::CFDictionary;
+use string::CFString;
 
 
 declare_TCFType!{
     /// A Bundle type.
     CFBundle, CFBundleRef
 }
 impl_TCFType!(CFBundle, CFBundleRef, CFBundleGetTypeID);
 
@@ -37,17 +38,17 @@ impl CFBundle {
 
     pub fn main_bundle() -> CFBundle {
         unsafe {
             let bundle_ref = CFBundleGetMainBundle();
             TCFType::wrap_under_get_rule(bundle_ref)
         }
     }
 
-    pub fn info_dictionary(&self) -> CFDictionary {
+    pub fn info_dictionary(&self) -> CFDictionary<CFString, CFType> {
         unsafe {
             let info_dictionary = CFBundleGetInfoDictionary(self.0);
             TCFType::wrap_under_get_rule(info_dictionary)
         }
     }
 
     pub fn executable_url(&self) -> Option<CFURL> {
         unsafe {
--- a/third_party/rust/core-foundation/src/dictionary.rs
+++ b/third_party/rust/core-foundation/src/dictionary.rs
@@ -6,33 +6,39 @@
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
 //! Dictionaries of key-value pairs.
 
 pub use core_foundation_sys::dictionary::*;
 
-use core_foundation_sys::base::{CFTypeRef, kCFAllocatorDefault};
-use libc::c_void;
+use core_foundation_sys::base::{CFTypeRef, CFRelease, kCFAllocatorDefault};
 use std::mem;
+use std::os::raw::c_void;
 use std::ptr;
+use std::marker::PhantomData;
 
-use base::{CFType, CFIndexConvertible, TCFType, TCFTypeRef};
+use base::{ItemRef, FromVoid, ToVoid};
+use base::{CFIndexConvertible, TCFType};
 
+// consume the type parameters with PhantomDatas
+pub struct CFDictionary<K = *const c_void, V = *const c_void>(CFDictionaryRef, PhantomData<K>, PhantomData<V>);
 
-declare_TCFType!{
-    /// An immutable dictionary of key-value pairs.
-    CFDictionary, CFDictionaryRef
+impl<K, V> Drop for CFDictionary<K, V> {
+    fn drop(&mut self) {
+        unsafe { CFRelease(self.as_CFTypeRef()) }
+    }
 }
-impl_TCFType!(CFDictionary, CFDictionaryRef, CFDictionaryGetTypeID);
+
+impl_TCFType!(CFDictionary<K, V>, CFDictionaryRef, CFDictionaryGetTypeID);
 impl_CFTypeDescription!(CFDictionary);
 
-impl CFDictionary {
-    pub fn from_CFType_pairs<K: TCFType, V: TCFType>(pairs: &[(K, V)]) -> CFDictionary {
+impl<K, V> CFDictionary<K, V> {
+    pub fn from_CFType_pairs(pairs: &[(K, V)]) -> CFDictionary<K, V> where K: TCFType, V: TCFType {
         let (keys, values): (Vec<CFTypeRef>, Vec<CFTypeRef>) = pairs
             .iter()
             .map(|&(ref key, ref value)| (key.as_CFTypeRef(), value.as_CFTypeRef()))
             .unzip();
 
         unsafe {
             let dictionary_ref = CFDictionaryCreate(kCFAllocatorDefault,
                                                     mem::transmute(keys.as_ptr()),
@@ -52,60 +58,40 @@ impl CFDictionary {
     }
 
     #[inline]
     pub fn is_empty(&self) -> bool {
         self.len() == 0
     }
 
     #[inline]
-    pub fn contains_key(&self, key: *const c_void) -> bool {
-        unsafe { CFDictionaryContainsKey(self.0, key) != 0 }
-    }
-
-    /// Similar to `contains_key` but acts on a higher level, automatically converting from any
-    /// `TCFType` to the raw pointer of its concrete TypeRef.
-    #[inline]
-    pub fn contains_key2<K: TCFType>(&self, key: &K) -> bool {
-        self.contains_key(key.as_concrete_TypeRef().as_void_ptr())
+    pub fn contains_key(&self, key: &K) -> bool where K: ToVoid<K> {
+        unsafe { CFDictionaryContainsKey(self.0, key.to_void()) != 0 }
     }
 
     #[inline]
-    pub fn find(&self, key: *const c_void) -> Option<*const c_void> {
+    pub fn find<'a, T: ToVoid<K>>(&'a self, key: T) -> Option<ItemRef<'a, V>> where V: FromVoid, K: ToVoid<K> {
         unsafe {
             let mut value: *const c_void = ptr::null();
-            if CFDictionaryGetValueIfPresent(self.0, key, &mut value) != 0 {
-                Some(value)
+            if CFDictionaryGetValueIfPresent(self.0, key.to_void(), &mut value) != 0 {
+                Some(V::from_void(value))
             } else {
                 None
             }
         }
     }
 
-    /// Similar to `find` but acts on a higher level, automatically converting from any `TCFType`
-    /// to the raw pointer of its concrete TypeRef.
-    #[inline]
-    pub fn find2<K: TCFType>(&self, key: &K) -> Option<*const c_void> {
-        self.find(key.as_concrete_TypeRef().as_void_ptr())
-    }
-
     /// # Panics
     ///
     /// Panics if the key is not present in the dictionary. Use `find` to get an `Option` instead
     /// of panicking.
     #[inline]
-    pub fn get(&self, key: *const c_void) -> *const c_void {
-        self.find(key).expect(&format!("No entry found for key {:p}", key))
-    }
-
-    /// A convenience function to retrieve `CFType` instances.
-    #[inline]
-    pub unsafe fn get_CFType(&self, key: *const c_void) -> CFType {
-        let value: CFTypeRef = mem::transmute(self.get(key));
-        TCFType::wrap_under_get_rule(value)
+    pub fn get<'a, T: ToVoid<K>>(&'a self, key: T) -> ItemRef<'a, V> where V: FromVoid, K: ToVoid<K> {
+        let ptr = key.to_void();
+        self.find(key).expect(&format!("No entry found for key {:p}", ptr))
     }
 
     pub fn get_keys_and_values(&self) -> (Vec<*const c_void>, Vec<*const c_void>) {
         let length = self.len();
         let mut keys = Vec::with_capacity(length);
         let mut values = Vec::with_capacity(length);
 
         unsafe {
@@ -113,25 +99,29 @@ impl CFDictionary {
             keys.set_len(length);
             values.set_len(length);
         }
 
         (keys, values)
     }
 }
 
-declare_TCFType!{
-    /// An mutable dictionary of key-value pairs.
-    CFMutableDictionary, CFMutableDictionaryRef
+// consume the type parameters with PhantomDatas
+pub struct CFMutableDictionary<K = *const c_void, V = *const c_void>(CFMutableDictionaryRef, PhantomData<K>, PhantomData<V>);
+
+impl<K, V> Drop for CFMutableDictionary<K, V> {
+    fn drop(&mut self) {
+        unsafe { CFRelease(self.as_CFTypeRef()) }
+    }
 }
 
-impl_TCFType!(CFMutableDictionary, CFMutableDictionaryRef, CFDictionaryGetTypeID);
+impl_TCFType!(CFMutableDictionary<K, V>, CFMutableDictionaryRef, CFDictionaryGetTypeID);
 impl_CFTypeDescription!(CFMutableDictionary);
 
-impl CFMutableDictionary {
+impl<K, V> CFMutableDictionary<K, V> {
     pub fn new() -> Self {
         Self::with_capacity(0)
     }
 
     pub fn with_capacity(capacity: isize) -> Self {
         unsafe {
             let dictionary_ref = CFDictionaryCreateMutable(kCFAllocatorDefault,
                                                            capacity as _,
@@ -143,22 +133,20 @@ impl CFMutableDictionary {
 
     pub fn copy_with_capacity(&self, capacity: isize) -> Self {
         unsafe {
             let dictionary_ref = CFDictionaryCreateMutableCopy(kCFAllocatorDefault, capacity as _, self.0);
             TCFType::wrap_under_get_rule(dictionary_ref)
         }
     }
 
-    pub fn from_CFType_pairs<K: TCFType, V: TCFType>(pairs: &[(K, V)]) -> CFMutableDictionary {
-        let result = Self::with_capacity(pairs.len() as _);
-        unsafe {
-            for &(ref key, ref value) in pairs {
-                result.add(key.as_CFTypeRef(), value.as_CFTypeRef());
-            }
+    pub fn from_CFType_pairs(pairs: &[(K, V)]) -> CFMutableDictionary<K, V> where K: ToVoid<K>, V: ToVoid<V> {
+        let mut result = Self::with_capacity(pairs.len() as _);
+        for &(ref key, ref value) in pairs {
+            result.add(key, value);
         }
         result
     }
 
     // Immutable interface
 
     #[inline]
     pub fn len(&self) -> usize {
@@ -174,56 +162,36 @@ impl CFMutableDictionary {
 
     #[inline]
     pub fn contains_key(&self, key: *const c_void) -> bool {
         unsafe {
             CFDictionaryContainsKey(self.0, key) != 0
         }
     }
 
-    /// Similar to `contains_key` but acts on a higher level, automatically converting from any
-    /// `TCFType` to the raw pointer of its concrete TypeRef.
     #[inline]
-    pub fn contains_key2<K: TCFType>(&self, key: &K) -> bool {
-        self.contains_key(key.as_concrete_TypeRef().as_void_ptr())
-    }
-
-    #[inline]
-    pub fn find(&self, key: *const c_void) -> Option<*const c_void> {
+    pub fn find<'a>(&'a self, key: &K) -> Option<ItemRef<'a, V>> where V: FromVoid, K: ToVoid<K> {
         unsafe {
             let mut value: *const c_void = ptr::null();
-            if CFDictionaryGetValueIfPresent(self.0, key, &mut value) != 0 {
-                Some(value)
+            if CFDictionaryGetValueIfPresent(self.0, key.to_void(), &mut value) != 0 {
+                Some(V::from_void(value))
             } else {
                 None
             }
         }
     }
 
-    /// Similar to `find` but acts on a higher level, automatically converting from any `TCFType`
-    /// to the raw pointer of its concrete TypeRef.
-    #[inline]
-    pub fn find2<K: TCFType>(&self, key: &K) -> Option<*const c_void> {
-        self.find(key.as_concrete_TypeRef().as_void_ptr())
-    }
-
     /// # Panics
     ///
     /// Panics if the key is not present in the dictionary. Use `find` to get an `Option` instead
     /// of panicking.
     #[inline]
-    pub fn get(&self, key: *const c_void) -> *const c_void {
-        self.find(key).expect(&format!("No entry found for key {:p}", key))
-    }
-
-    /// A convenience function to retrieve `CFType` instances.
-    #[inline]
-    pub unsafe fn get_CFType(&self, key: *const c_void) -> CFType {
-        let value: CFTypeRef = mem::transmute(self.get(key));
-        TCFType::wrap_under_get_rule(value)
+    pub fn get<'a>(&'a self, key: &K) -> ItemRef<'a, V> where V: FromVoid, K: ToVoid<K> {
+        let ptr = key.to_void();
+        self.find(&key).expect(&format!("No entry found for key {:p}", ptr))
     }
 
     pub fn get_keys_and_values(&self) -> (Vec<*const c_void>, Vec<*const c_void>) {
         let length = self.len();
         let mut keys = Vec::with_capacity(length);
         let mut values = Vec::with_capacity(length);
 
         unsafe {
@@ -234,93 +202,50 @@ impl CFMutableDictionary {
 
         (keys, values)
     }
 
     // Mutable interface
 
     /// Adds the key-value pair to the dictionary if no such key already exist.
     #[inline]
-    pub unsafe fn add(&self, key: *const c_void, value: *const c_void) {
-        CFDictionaryAddValue(self.0, key, value)
-    }
-
-    /// Similar to `add` but acts on a higher level, automatically converting from any `TCFType`
-    /// to the raw pointer of its concrete TypeRef.
-    #[inline]
-    pub fn add2<K: TCFType, V: TCFType>(&self, key: &K, value: &V) {
-        unsafe {
-            self.add(
-                key.as_concrete_TypeRef().as_void_ptr(),
-                value.as_concrete_TypeRef().as_void_ptr(),
-            )
-        }
+    pub fn add(&mut self, key: &K, value: &V) where K: ToVoid<K>, V: ToVoid<V> {
+        unsafe { CFDictionaryAddValue(self.0, key.to_void(), value.to_void()) }
     }
 
     /// Sets the value of the key in the dictionary.
     #[inline]
-    pub unsafe fn set(&self, key: *const c_void, value: *const c_void) {
-        CFDictionarySetValue(self.0, key, value)
-    }
-
-    /// Similar to `set` but acts on a higher level, automatically converting from any `TCFType`
-    /// to the raw pointer of its concrete TypeRef.
-    #[inline]
-    pub fn set2<K: TCFType, V: TCFType>(&self, key: &K, value: &V) {
-        unsafe {
-            self.set(
-                key.as_concrete_TypeRef().as_void_ptr(),
-                value.as_concrete_TypeRef().as_void_ptr(),
-            )
-        }
+    pub fn set(&mut self, key: K, value: V) where K: ToVoid<K>, V: ToVoid<V> {
+        unsafe { CFDictionarySetValue(self.0, key.to_void(), value.to_void()) }
     }
 
     /// Replaces the value of the key in the dictionary.
     #[inline]
-    pub unsafe fn replace(&self, key: *const c_void, value: *const c_void) {
-        CFDictionaryReplaceValue(self.0, key, value)
-    }
-
-    /// Similar to `replace` but acts on a higher level, automatically converting from any `TCFType`
-    /// to the raw pointer of its concrete TypeRef.
-    #[inline]
-    pub fn replace2<K: TCFType, V: TCFType>(&self, key: &K, value: &V) {
-        unsafe {
-            self.replace(
-                key.as_concrete_TypeRef().as_void_ptr(),
-                value.as_concrete_TypeRef().as_void_ptr(),
-            )
-        }
+    pub fn replace(&mut self, key: K, value: V) where K: ToVoid<K>, V: ToVoid<V> {
+        unsafe { CFDictionaryReplaceValue(self.0, key.to_void(), value.to_void()) }
     }
 
     /// Removes the value of the key from the dictionary.
     #[inline]
-    pub unsafe fn remove(&self, key: *const c_void) {
-        CFDictionaryRemoveValue(self.0, key);
-    }
-
-    /// Similar to `remove` but acts on a higher level, automatically converting from any `TCFType`
-    /// to the raw pointer of its concrete TypeRef.
-    #[inline]
-    pub fn remove2<K: TCFType>(&self, key: &K) {
-        unsafe { self.remove(key.as_concrete_TypeRef().as_void_ptr()) }
+    pub fn remove(&mut self, key: K) where K: ToVoid<K> {
+        unsafe { CFDictionaryRemoveValue(self.0, key.to_void()) }
     }
 
     #[inline]
-    pub fn remove_all(&self) {
+    pub fn remove_all(&mut self) {
         unsafe { CFDictionaryRemoveAllValues(self.0) }
     }
 }
 
 
 #[cfg(test)]
 pub mod test {
     use super::*;
-    use base::TCFType;
-    use boolean::{CFBoolean, CFBooleanRef};
+    use base::{CFType, TCFType};
+    use boolean::CFBoolean;
     use number::CFNumber;
     use string::CFString;
 
 
     #[test]
     fn dictionary() {
         let bar = CFString::from_static_string("Bar");
         let baz = CFString::from_static_string("Baz");
@@ -344,48 +269,48 @@ pub mod test {
     fn mutable_dictionary() {
         let bar = CFString::from_static_string("Bar");
         let baz = CFString::from_static_string("Baz");
         let boo = CFString::from_static_string("Boo");
         let foo = CFString::from_static_string("Foo");
         let tru = CFBoolean::true_value();
         let n42 = CFNumber::from(42);
 
-        let d = CFMutableDictionary::new();
-        d.add2(&bar, &boo);
-        d.add2(&baz, &tru);
-        d.add2(&foo, &n42);
+        let mut d = CFMutableDictionary::<CFString, CFType>::new();
+        d.add(&bar, &boo.as_CFType());
+        d.add(&baz, &tru.as_CFType());
+        d.add(&foo, &n42.as_CFType());
         assert_eq!(d.len(), 3);
 
         let (v1, v2) = d.get_keys_and_values();
         assert!(v1 == &[bar.as_CFTypeRef(), baz.as_CFTypeRef(), foo.as_CFTypeRef()]);
         assert!(v2 == &[boo.as_CFTypeRef(), tru.as_CFTypeRef(), n42.as_CFTypeRef()]);
 
-        d.remove2(&baz);
+        d.remove(baz);
         assert_eq!(d.len(), 2);
 
         let (v1, v2) = d.get_keys_and_values();
         assert!(v1 == &[bar.as_CFTypeRef(), foo.as_CFTypeRef()]);
         assert!(v2 == &[boo.as_CFTypeRef(), n42.as_CFTypeRef()]);
 
         d.remove_all();
         assert_eq!(d.len(), 0)
     }
 
     #[test]
-    fn dict_find2_and_contains_key2() {
+    fn dict_find_and_contains_key() {
         let dict = CFDictionary::from_CFType_pairs(&[
             (
                 CFString::from_static_string("hello"),
                 CFBoolean::true_value(),
             ),
         ]);
         let key = CFString::from_static_string("hello");
         let invalid_key = CFString::from_static_string("foobar");
 
-        assert!(dict.contains_key2(&key));
-        assert!(!dict.contains_key2(&invalid_key));
+        assert!(dict.contains_key(&key));
+        assert!(!dict.contains_key(&invalid_key));
 
-        let value = unsafe { CFBoolean::wrap_under_get_rule(dict.find2(&key).unwrap() as CFBooleanRef) };
+        let value = dict.find(&key).unwrap().clone();
         assert_eq!(value, CFBoolean::true_value());
-        assert_eq!(dict.find2(&invalid_key), None);
+        assert_eq!(dict.find(&invalid_key), None);
     }
 }
--- a/third_party/rust/core-foundation/src/filedescriptor.rs
+++ b/third_party/rust/core-foundation/src/filedescriptor.rs
@@ -1,8 +1,17 @@
+// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
 pub use core_foundation_sys::filedescriptor::*;
 
 use core_foundation_sys::base::{Boolean, CFIndex};
 use core_foundation_sys::base::{kCFAllocatorDefault, CFOptionFlags};
 
 use base::TCFType;
 use runloop::CFRunLoopSource;
 
@@ -93,19 +102,20 @@ impl AsRawFd for CFFileDescriptor {
 
 
 #[cfg(test)]
 mod test {
     extern crate libc;
 
     use super::*;
     use std::ffi::CString;
-    use libc::{c_void, O_RDWR};
+    use std::os::raw::c_void;
     use core_foundation_sys::base::{CFOptionFlags};
     use core_foundation_sys::runloop::{kCFRunLoopDefaultMode};
+    use libc::O_RDWR;
     use runloop::{CFRunLoop};
 
     #[test]
     fn test_consumed() {
         let path = CString::new("/dev/null").unwrap();
         let raw_fd = unsafe { libc::open(path.as_ptr(), O_RDWR, 0) };
         let cf_fd = CFFileDescriptor::new(raw_fd, true, never_callback, None);
         assert!(cf_fd.is_some());
--- a/third_party/rust/core-foundation/src/lib.rs
+++ b/third_party/rust/core-foundation/src/lib.rs
@@ -9,16 +9,20 @@
 #![allow(non_snake_case)]
 
 extern crate core_foundation_sys;
 extern crate libc;
 
 #[cfg(feature = "with-chrono")]
 extern crate chrono;
 
+use base::TCFType;
+
+pub unsafe trait ConcreteCFType: TCFType {}
+
 #[macro_export]
 macro_rules! declare_TCFType {
     (
         $(#[$doc:meta])*
         $ty:ident, $raw:ident
     ) => {
         $(#[$doc])*
         pub struct $ty($raw);
@@ -29,41 +33,48 @@ macro_rules! declare_TCFType {
             }
         }
     }
 }
 
 #[macro_export]
 macro_rules! impl_TCFType {
     ($ty:ident, $ty_ref:ident, $ty_id:ident) => {
-        impl $crate::base::TCFType for $ty {
+        impl_TCFType!($ty<>, $ty_ref, $ty_id);
+        unsafe impl $crate::ConcreteCFType for $ty { }
+    };
+
+    ($ty:ident<$($p:ident $(: $bound:path)*),*>, $ty_ref:ident, $ty_id:ident) => {
+        impl<$($p $(: $bound)*),*> $crate::base::TCFType for $ty<$($p),*> {
             type Ref = $ty_ref;
 
             #[inline]
             fn as_concrete_TypeRef(&self) -> $ty_ref {
                 self.0
             }
 
             #[inline]
-            unsafe fn wrap_under_get_rule(reference: $ty_ref) -> $ty {
+            unsafe fn wrap_under_get_rule(reference: $ty_ref) -> Self {
                 use std::mem;
                 let reference = mem::transmute($crate::base::CFRetain(mem::transmute(reference)));
                 $crate::base::TCFType::wrap_under_create_rule(reference)
             }
 
             #[inline]
             fn as_CFTypeRef(&self) -> $crate::base::CFTypeRef {
                 unsafe {
                     ::std::mem::transmute(self.as_concrete_TypeRef())
                 }
             }
 
             #[inline]
-            unsafe fn wrap_under_create_rule(reference: $ty_ref) -> $ty {
-                $ty(reference)
+            unsafe fn wrap_under_create_rule(reference: $ty_ref) -> Self {
+                // we need one PhantomData for each type parameter so call ourselves
+                // again with @Phantom $p to produce that
+                $ty(reference $(, impl_TCFType!(@Phantom $p))*)
             }
 
             #[inline]
             fn type_id() -> $crate::base::CFTypeID {
                 unsafe {
                     $ty_id()
                 }
             }
@@ -81,95 +92,52 @@ macro_rules! impl_TCFType {
         impl PartialEq for $ty {
             #[inline]
             fn eq(&self, other: &$ty) -> bool {
                 self.as_CFType().eq(&other.as_CFType())
             }
         }
 
         impl Eq for $ty { }
-    }
-}
 
-// This is basically identical to the implementation above. I can't
-// think of a clean way to have them share code
-#[macro_export]
-macro_rules! impl_TCFTypeGeneric {
-    ($ty:ident, $ty_ref:ident, $ty_id:ident) => {
-        impl<T> $crate::base::TCFType for $ty<T> {
-            type Ref = $ty_ref;
-
-            #[inline]
-            fn as_concrete_TypeRef(&self) -> $ty_ref {
-                self.0
-            }
-
-            #[inline]
-            unsafe fn wrap_under_get_rule(reference: $ty_ref) -> $ty<T> {
-                use std::mem;
-                let reference = mem::transmute($crate::base::CFRetain(mem::transmute(reference)));
-                $crate::base::TCFType::wrap_under_create_rule(reference)
-            }
-
-            #[inline]
-            fn as_CFTypeRef(&self) -> ::core_foundation_sys::base::CFTypeRef {
-                unsafe {
-                    ::std::mem::transmute(self.as_concrete_TypeRef())
-                }
-            }
-
-            #[inline]
-            unsafe fn wrap_under_create_rule(obj: $ty_ref) -> $ty<T> {
-                $ty(obj, PhantomData)
-            }
-
-            #[inline]
-            fn type_id() -> ::core_foundation_sys::base::CFTypeID {
-                unsafe {
-                    $ty_id()
-                }
+        unsafe impl<'a> $crate::base::ToVoid<$ty> for &'a $ty {
+            fn to_void(&self) -> *const ::std::os::raw::c_void {
+            use $crate::base::TCFTypeRef;
+                self.as_concrete_TypeRef().as_void_ptr()
             }
         }
 
-        impl<T> Clone for $ty<T> {
-            #[inline]
-            fn clone(&self) -> $ty<T> {
-                unsafe {
-                    $ty::wrap_under_get_rule(self.0)
-                }
+        unsafe impl $crate::base::ToVoid<$ty> for $ty {
+            fn to_void(&self) -> *const ::std::os::raw::c_void {
+            use $crate::base::TCFTypeRef;
+                self.as_concrete_TypeRef().as_void_ptr()
             }
         }
 
-        impl<T> PartialEq for $ty<T> {
-            #[inline]
-            fn eq(&self, other: &$ty<T>) -> bool {
-                self.as_CFType().eq(&other.as_CFType())
+        unsafe impl $crate::base::ToVoid<$ty> for $ty_ref {
+            fn to_void(&self) -> *const ::std::os::raw::c_void {
+            use $crate::base::TCFTypeRef;
+                self.as_void_ptr()
             }
         }
 
-        impl<T> Eq for $ty<T> { }
-    }
+    };
+
+    (@Phantom $x:ident) => { ::std::marker::PhantomData };
 }
 
+
 #[macro_export]
 macro_rules! impl_CFTypeDescription {
     ($ty:ident) => {
-        impl ::std::fmt::Debug for $ty {
-            fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
-                self.as_CFType().fmt(f)
-            }
-        }
-    }
-}
-
-// The same as impl_CFTypeDescription but with a type parameter
-#[macro_export]
-macro_rules! impl_CFTypeDescriptionGeneric {
-    ($ty:ident) => {
-        impl<T> ::std::fmt::Debug for $ty<T> {
+        // it's fine to use an empty <> list
+        impl_CFTypeDescription!($ty<>);
+    };
+    ($ty:ident<$($p:ident $(: $bound:path)*),*>) => {
+        impl<$($p $(: $bound)*),*> ::std::fmt::Debug for $ty<$($p),*> {
             fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
                 self.as_CFType().fmt(f)
             }
         }
     }
 }
 
 #[macro_export]
--- a/third_party/rust/core-foundation/src/propertylist.rs
+++ b/third_party/rust/core-foundation/src/propertylist.rs
@@ -6,18 +6,17 @@
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
 //! Core Foundation property lists
 
 use std::ptr;
 use std::mem;
-
-use libc::c_void;
+use std::os::raw::c_void;
 
 use error::CFError;
 use data::CFData;
 use base::{CFType, TCFType, TCFTypeRef};
 
 pub use core_foundation_sys::propertylist::*;
 use core_foundation_sys::error::CFErrorRef;
 use core_foundation_sys::base::{CFGetRetainCount, CFGetTypeID, CFIndex, CFRetain,
--- a/third_party/rust/core-foundation/src/runloop.rs
+++ b/third_party/rust/core-foundation/src/runloop.rs
@@ -147,17 +147,17 @@ impl CFRunLoopSource {
 declare_TCFType!(CFRunLoopObserver, CFRunLoopObserverRef);
 impl_TCFType!(CFRunLoopObserver, CFRunLoopObserverRef, CFRunLoopObserverGetTypeID);
 
 #[cfg(test)]
 mod test {
     use super::*;
     use date::{CFDate, CFAbsoluteTime};
     use std::mem;
-    use libc::c_void;
+    use std::os::raw::c_void;
     use std::sync::mpsc;
 
     #[test]
     fn wait_200_milliseconds() {
         let run_loop = CFRunLoop::get_current();
 
         let now = CFDate::now().abs_time();
         let (elapsed_tx, elapsed_rx) = mpsc::channel();
--- a/third_party/rust/core-foundation/src/set.rs
+++ b/third_party/rust/core-foundation/src/set.rs
@@ -5,33 +5,39 @@
 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
 //! An immutable bag of elements.
 
 pub use core_foundation_sys::set::*;
-use core_foundation_sys::base::{CFTypeRef, kCFAllocatorDefault};
+use core_foundation_sys::base::{CFTypeRef, CFRelease, kCFAllocatorDefault};
 
 use base::{CFIndexConvertible, TCFType};
 
 use std::mem;
+use std::os::raw::c_void;
+use std::marker::PhantomData;
 
+/// An immutable bag of elements.
+pub struct CFSet<T = *const c_void>(CFSetRef, PhantomData<T>);
 
-declare_TCFType!{
-    /// An immutable bag of elements.
-    CFSet, CFSetRef
+impl<T> Drop for CFSet<T> {
+    fn drop(&mut self) {
+        unsafe { CFRelease(self.as_CFTypeRef()) }
+    }
 }
-impl_TCFType!(CFSet, CFSetRef, CFSetGetTypeID);
+
+impl_TCFType!(CFSet<T>, CFSetRef, CFSetGetTypeID);
 impl_CFTypeDescription!(CFSet);
 
 impl CFSet {
     /// Creates a new set from a list of `CFType` instances.
-    pub fn from_slice<T>(elems: &[T]) -> CFSet where T: TCFType {
+    pub fn from_slice<T>(elems: &[T]) -> CFSet<T> where T: TCFType {
         unsafe {
             let elems: Vec<CFTypeRef> = elems.iter().map(|elem| elem.as_CFTypeRef()).collect();
             let set_ref = CFSetCreate(kCFAllocatorDefault,
                                       mem::transmute(elems.as_ptr()),
                                       elems.len().to_CFIndex(),
                                       &kCFTypeSetCallBacks);
             TCFType::wrap_under_create_rule(set_ref)
         }
--- a/third_party/rust/core-foundation/tests/use_macro_outside_crate.rs
+++ b/third_party/rust/core-foundation/tests/use_macro_outside_crate.rs
@@ -1,14 +1,13 @@
 #[macro_use]
 extern crate core_foundation;
-extern crate libc;
 
 use core_foundation::base::{CFComparisonResult, TCFType};
-use libc::c_void;
+use std::os::raw::c_void;
 
 // sys equivalent stuff that must be declared
 
 #[repr(C)]
 pub struct __CFFooBar(c_void);
 
 pub type CFFooBarRef = *const __CFFooBar;