auto merge of #1947 : saneyuki/servo/cast, r=jdm

follow up https://github.com/mozilla/servo/pull/1864#issuecomment-37109672
This commit is contained in:
bors-servo 2014-03-23 11:46:47 -04:00
commit e67d8a4003

View file

@ -5745,10 +5745,12 @@ class GlobalGenRoots():
derived += [CGGeneric('\n')] derived += [CGGeneric('\n')]
cast = [CGGeneric(string.Template('''pub trait ${castTraitName} { cast = [CGGeneric(string.Template('''pub trait ${castTraitName} {
#[inline(always)]
fn from<T: ${fromBound}>(derived: &JS<T>) -> JS<Self> { fn from<T: ${fromBound}>(derived: &JS<T>) -> JS<Self> {
unsafe { derived.clone().transmute() } unsafe { derived.clone().transmute() }
} }
#[inline(always)]
fn to<T: ${toBound}>(base: &JS<T>) -> Option<JS<Self>> { fn to<T: ${toBound}>(base: &JS<T>) -> Option<JS<Self>> {
match base.get().${checkFn}() { match base.get().${checkFn}() {
true => unsafe { Some(base.clone().transmute()) }, true => unsafe { Some(base.clone().transmute()) },
@ -5756,6 +5758,7 @@ class GlobalGenRoots():
} }
} }
#[inline(always)]
unsafe fn to_unchecked<T: ${toBound}>(base: &JS<T>) -> JS<Self> { unsafe fn to_unchecked<T: ${toBound}>(base: &JS<T>) -> JS<Self> {
assert!(base.get().${checkFn}()); assert!(base.get().${checkFn}());
base.clone().transmute() base.clone().transmute()