From b8d423d931d54aaa07601f4344b2b028a78f5962 Mon Sep 17 00:00:00 2001 From: Cameron Zwarich Date: Wed, 14 May 2014 13:58:06 -0700 Subject: [PATCH] Switch to using ContravariantLifetime in JSRef<'a, T>. Since ContravariantLifetime doesn't take up any storage space, this means that JSRef will be a single word. This fixes #2333. --- src/components/script/dom/bindings/js.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/components/script/dom/bindings/js.rs b/src/components/script/dom/bindings/js.rs index da84c85eeb7..8ed125f74ee 100644 --- a/src/components/script/dom/bindings/js.rs +++ b/src/components/script/dom/bindings/js.rs @@ -47,6 +47,7 @@ use script_task::StackRoots; use std::cast; use std::cell::RefCell; +use std::kinds::marker::ContravariantLifetime; use std::local_data; /// A type that represents a JS-owned value that is rooted for the lifetime of this value. @@ -402,7 +403,7 @@ impl<'a, 'b, T: Reflectable> Root<'a, 'b, T> { root_list: roots, jsref: JSRef { ptr: unrooted.ptr.clone(), - chain: unsafe { cast::transmute_region(&()) }, + chain: ContravariantLifetime, }, ptr: unrooted.ptr.clone(), js_ptr: unrooted.reflector().get_jsobject(), @@ -458,14 +459,14 @@ impl<'a, T: Reflectable> DerefMut for JSRef<'a, T> { /// Encapsulates a reference to something that is guaranteed to be alive. This is freely copyable. pub struct JSRef<'a, T> { ptr: RefCell<*mut T>, - chain: &'a (), + chain: ContravariantLifetime<'a>, } impl<'a, T> Clone for JSRef<'a, T> { fn clone(&self) -> JSRef<'a, T> { JSRef { ptr: self.ptr.clone(), - chain: self.chain + chain: self.chain, } } }