Make AttrHelpersForLayout methods be safe

The unsafety isn't there, it's in the creation of the LayoutDom<T> values.
This commit is contained in:
Anthony Ramine 2020-03-31 13:54:52 +02:00
parent f9e7c6b9dc
commit 4c16729a01

View file

@ -234,26 +234,26 @@ impl Attr {
#[allow(unsafe_code)]
pub trait AttrHelpersForLayout<'dom> {
unsafe fn value(self) -> &'dom AttrValue;
unsafe fn value_ref_forever(self) -> &'dom str;
unsafe fn value_tokens(self) -> Option<&'dom [Atom]>;
unsafe fn local_name_atom(self) -> LocalName;
fn value(self) -> &'dom AttrValue;
fn value_ref_forever(self) -> &'dom str;
fn value_tokens(self) -> Option<&'dom [Atom]>;
fn local_name_atom(self) -> LocalName;
}
#[allow(unsafe_code)]
impl<'dom> AttrHelpersForLayout<'dom> for LayoutDom<'dom, Attr> {
#[inline]
unsafe fn value(self) -> &'dom AttrValue {
(*self.unsafe_get()).value.borrow_for_layout()
fn value(self) -> &'dom AttrValue {
unsafe { self.unsafe_get().value.borrow_for_layout() }
}
#[inline]
unsafe fn value_ref_forever(self) -> &'dom str {
fn value_ref_forever(self) -> &'dom str {
&**self.value()
}
#[inline]
unsafe fn value_tokens(self) -> Option<&'dom [Atom]> {
fn value_tokens(self) -> Option<&'dom [Atom]> {
// This transmute is used to cheat the lifetime restriction.
match *self.value() {
AttrValue::TokenList(_, ref tokens) => Some(tokens),
@ -262,7 +262,7 @@ impl<'dom> AttrHelpersForLayout<'dom> for LayoutDom<'dom, Attr> {
}
#[inline]
unsafe fn local_name_atom(self) -> LocalName {
(*self.unsafe_get()).identifier.local_name.clone()
fn local_name_atom(self) -> LocalName {
unsafe { self.unsafe_get().identifier.local_name.clone() }
}
}