diff --git a/components/style/build_gecko.rs b/components/style/build_gecko.rs index 52dc5f51e24..6b536c4122b 100644 --- a/components/style/build_gecko.rs +++ b/components/style/build_gecko.rs @@ -258,13 +258,6 @@ mod bindings { .collect() } - fn get_boxed_types() -> Vec { - get_types("ServoBoxedTypeList.h", "SERVO_BOXED_TYPE") - .into_iter() - .map(|(_, type_name)| type_name) - .collect() - } - struct BuilderWithConfig<'a> { builder: Builder, config: &'a Table, @@ -453,22 +446,6 @@ mod bindings { ty )); } - for ty in get_boxed_types().iter() { - builder = builder - .blacklist_type(format!("{}Owned", ty)) - .raw_line(format!( - "pub type {0}Owned = ::gecko_bindings::sugar::ownership::Owned<{0}>;", - ty - )) - .blacklist_type(format!("{}OwnedOrNull", ty)) - .raw_line(format!( - concat!( - "pub type {0}OwnedOrNull = ", - "::gecko_bindings::sugar::ownership::OwnedOrNull<{0}>;" - ), - ty - )); - } write_binding_file(builder, BINDINGS_FILE, &fixups); } diff --git a/components/style/cbindgen.toml b/components/style/cbindgen.toml index 54288dff7ad..41da88bbb35 100644 --- a/components/style/cbindgen.toml +++ b/components/style/cbindgen.toml @@ -109,6 +109,8 @@ include = [ "WillChangeBits", "TextDecorationLine", "MozListReversed", + "Owned", + "OwnedOrNull", ] item_types = ["enums", "structs", "typedefs"] @@ -208,3 +210,21 @@ item_types = ["enums", "structs", "typedefs"] static inline StyleRestyleHint RecascadeSubtree(); static inline StyleRestyleHint ForAnimations(); """ + +# TODO(emilio): Add hooks to cbindgen to be able to generate MOZ_MUST_USE_TYPE +# or MOZ_MUST_USE on the functions. +"Owned" = """ + UniquePtr Consume() { + UniquePtr ret(ptr); + ptr = nullptr; + return ret; + } +""" + +"OwnedOrNull" = """ + UniquePtr Consume() { + UniquePtr ret(ptr); + ptr = nullptr; + return ret; + } +""" diff --git a/components/style/gecko_bindings/sugar/ownership.rs b/components/style/gecko_bindings/sugar/ownership.rs index 3f1f1315eda..33f5b39553b 100644 --- a/components/style/gecko_bindings/sugar/ownership.rs +++ b/components/style/gecko_bindings/sugar/ownership.rs @@ -320,27 +320,6 @@ impl OwnedOrNull { self.ptr.is_null() } - /// Returns an owned pointer if this is non-null, and `None` otherwise. - pub fn into_box_opt(self) -> Option> - where - ServoType: HasBoxFFI, - { - if self.is_null() { - None - } else { - Some(unsafe { transmute(self) }) - } - } - - /// Returns an `Owned` if non-null, `None` otherwise. - pub fn into_owned_opt(self) -> Option> { - if self.is_null() { - None - } else { - Some(unsafe { transmute(self) }) - } - } - /// Gets a immutable reference to the underlying Gecko type, or `None` if /// null. pub fn borrow(&self) -> Option<&GeckoType> {