diff --git a/CHANGELOG.md b/CHANGELOG.md index 00ff0f4cf8c6..97ab388a08ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -258,7 +258,7 @@ Paolo Borelli: - gio: use `StrV` for the `file_info` API - gio: use `GStr` for the manual extension point implementation - glib: list: mark as transparent and impl TransparentPtr -- glib: Rename `StrVItem` to `GStrPtr` and make it clonable and transparent +- glib: Rename `StrVItem` to `GStrPtr` and make it cloneable and transparent - glib: `key_file`: return `PtrSlice` - glib-macros: further tweak docs - glib: Rename `GStrPtr` to `GStringPtr` diff --git a/gdk-pixbuf/src/subclass/pixbuf_animation.rs b/gdk-pixbuf/src/subclass/pixbuf_animation.rs index 4a014d8be908..ae08ed4ede66 100644 --- a/gdk-pixbuf/src/subclass/pixbuf_animation.rs +++ b/gdk-pixbuf/src/subclass/pixbuf_animation.rs @@ -13,7 +13,11 @@ use glib::{prelude::*, subclass::prelude::*, translate::*}; use crate::{ffi, Pixbuf, PixbufAnimation, PixbufAnimationIter}; -pub trait PixbufAnimationImpl: ObjectImpl { +pub trait PixbufAnimationImpl: ObjectImpl +where + ::Type: IsA, + ::Type: IsA, +{ fn is_static_image(&self) -> bool { self.parent_is_static_image() } @@ -31,12 +35,11 @@ pub trait PixbufAnimationImpl: ObjectImpl { } } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait PixbufAnimationImplExt: sealed::Sealed + ObjectSubclass { +pub trait PixbufAnimationImplExt: ObjectSubclass + PixbufAnimationImpl +where + ::Type: IsA, + ::Type: IsA, +{ fn parent_is_static_image(&self) -> bool { unsafe { let data = Self::type_data(); @@ -116,9 +119,18 @@ pub trait PixbufAnimationImplExt: sealed::Sealed + ObjectSubclass { } } -impl PixbufAnimationImplExt for T {} +impl PixbufAnimationImplExt for T +where + ::Type: IsA, + ::Type: IsA, +{ +} -unsafe impl IsSubclassable for PixbufAnimation { +unsafe impl IsSubclassable for PixbufAnimation +where + ::Type: IsA, + ::Type: IsA, +{ fn class_init(class: &mut ::glib::Class) { Self::parent_class_init::(class); @@ -132,7 +144,11 @@ unsafe impl IsSubclassable for PixbufAnimation { unsafe extern "C" fn animation_is_static_image( ptr: *mut ffi::GdkPixbufAnimation, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -143,7 +159,10 @@ unsafe extern "C" fn animation_get_size( ptr: *mut ffi::GdkPixbufAnimation, width_ptr: *mut libc::c_int, height_ptr: *mut libc::c_int, -) { +) where + ::Type: IsA, + ::Type: IsA, +{ if width_ptr.is_null() && height_ptr.is_null() { return; } @@ -162,7 +181,11 @@ unsafe extern "C" fn animation_get_size( unsafe extern "C" fn animation_get_static_image( ptr: *mut ffi::GdkPixbufAnimation, -) -> *mut ffi::GdkPixbuf { +) -> *mut ffi::GdkPixbuf +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -192,7 +215,11 @@ unsafe extern "C" fn animation_get_static_image( unsafe extern "C" fn animation_get_iter( ptr: *mut ffi::GdkPixbufAnimation, start_time_ptr: *const glib::ffi::GTimeVal, -) -> *mut ffi::GdkPixbufAnimationIter { +) -> *mut ffi::GdkPixbufAnimationIter +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); diff --git a/gdk-pixbuf/src/subclass/pixbuf_animation_iter.rs b/gdk-pixbuf/src/subclass/pixbuf_animation_iter.rs index 99d05ccae3ae..d3a104a2e8b8 100644 --- a/gdk-pixbuf/src/subclass/pixbuf_animation_iter.rs +++ b/gdk-pixbuf/src/subclass/pixbuf_animation_iter.rs @@ -12,7 +12,11 @@ use glib::{prelude::*, subclass::prelude::*, translate::*}; use crate::{ffi, Pixbuf, PixbufAnimationIter}; -pub trait PixbufAnimationIterImpl: ObjectImpl { +pub trait PixbufAnimationIterImpl: ObjectImpl +where + ::Type: IsA, + ::Type: IsA, +{ // rustdoc-stripper-ignore-next /// Time in milliseconds, returning `None` implies showing the same pixbuf forever. fn delay_time(&self) -> Option { @@ -32,12 +36,11 @@ pub trait PixbufAnimationIterImpl: ObjectImpl { } } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait PixbufAnimationIterImplExt: sealed::Sealed + ObjectSubclass { +pub trait PixbufAnimationIterImplExt: ObjectSubclass + PixbufAnimationIterImpl +where + ::Type: IsA, + ::Type: IsA, +{ fn parent_delay_time(&self) -> Option { unsafe { let data = Self::type_data(); @@ -121,9 +124,18 @@ pub trait PixbufAnimationIterImplExt: sealed::Sealed + ObjectSubclass { } } -impl PixbufAnimationIterImplExt for T {} +impl PixbufAnimationIterImplExt for T +where + ::Type: IsA, + ::Type: IsA, +{ +} -unsafe impl IsSubclassable for PixbufAnimationIter { +unsafe impl IsSubclassable for PixbufAnimationIter +where + ::Type: IsA, + ::Type: IsA, +{ fn class_init(class: &mut ::glib::Class) { Self::parent_class_init::(class); @@ -137,7 +149,11 @@ unsafe impl IsSubclassable for PixbufAnimationIte unsafe extern "C" fn animation_iter_get_delay_time( ptr: *mut ffi::GdkPixbufAnimationIter, -) -> i32 { +) -> i32 +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -146,7 +162,11 @@ unsafe extern "C" fn animation_iter_get_delay_time( unsafe extern "C" fn animation_iter_get_pixbuf( ptr: *mut ffi::GdkPixbufAnimationIter, -) -> *mut ffi::GdkPixbuf { +) -> *mut ffi::GdkPixbuf +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -162,7 +182,11 @@ unsafe extern "C" fn animation_iter_get_pixbuf( unsafe extern "C" fn animation_iter_on_currently_loading_frame( ptr: *mut ffi::GdkPixbufAnimationIter, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -172,7 +196,11 @@ unsafe extern "C" fn animation_iter_on_currently_loading_frame( ptr: *mut ffi::GdkPixbufAnimationIter, current_time_ptr: *const glib::ffi::GTimeVal, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); diff --git a/gdk-pixbuf/src/subclass/pixbuf_loader.rs b/gdk-pixbuf/src/subclass/pixbuf_loader.rs index c2d53a7132f5..a1b7b0d12175 100644 --- a/gdk-pixbuf/src/subclass/pixbuf_loader.rs +++ b/gdk-pixbuf/src/subclass/pixbuf_loader.rs @@ -7,7 +7,11 @@ use glib::{prelude::*, subclass::prelude::*, translate::*}; use crate::{ffi, PixbufLoader}; -pub trait PixbufLoaderImpl: ObjectImpl { +pub trait PixbufLoaderImpl: ObjectImpl +where + ::Type: IsA, + ::Type: IsA, +{ fn size_prepared(&self, width: i32, height: i32) { self.parent_size_prepared(width, height) } @@ -25,12 +29,11 @@ pub trait PixbufLoaderImpl: ObjectImpl { } } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait PixbufLoaderImplExt: sealed::Sealed + ObjectSubclass { +pub trait PixbufLoaderImplExt: ObjectSubclass + PixbufLoaderImpl +where + ::Type: IsA, + ::Type: IsA, +{ fn parent_size_prepared(&self, width: i32, height: i32) { unsafe { let data = Self::type_data(); @@ -96,9 +99,18 @@ pub trait PixbufLoaderImplExt: sealed::Sealed + ObjectSubclass { } } -impl PixbufLoaderImplExt for T {} +impl PixbufLoaderImplExt for T +where + ::Type: IsA, + ::Type: IsA, +{ +} -unsafe impl IsSubclassable for PixbufLoader { +unsafe impl IsSubclassable for PixbufLoader +where + ::Type: IsA, + ::Type: IsA, +{ fn class_init(class: &mut ::glib::Class) { Self::parent_class_init::(class); @@ -114,14 +126,21 @@ unsafe extern "C" fn loader_size_prepared( ptr: *mut ffi::GdkPixbufLoader, width: i32, height: i32, -) { +) where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); imp.size_prepared(width, height) } -unsafe extern "C" fn loader_area_prepared(ptr: *mut ffi::GdkPixbufLoader) { +unsafe extern "C" fn loader_area_prepared(ptr: *mut ffi::GdkPixbufLoader) +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -134,14 +153,21 @@ unsafe extern "C" fn loader_area_updated( y: i32, width: i32, height: i32, -) { +) where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); imp.area_updated(x, y, width, height) } -unsafe extern "C" fn loader_closed(ptr: *mut ffi::GdkPixbufLoader) { +unsafe extern "C" fn loader_closed(ptr: *mut ffi::GdkPixbufLoader) +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); diff --git a/gio/src/subclass/action_group.rs b/gio/src/subclass/action_group.rs index 948fb2d318c8..69fd5168ef65 100644 --- a/gio/src/subclass/action_group.rs +++ b/gio/src/subclass/action_group.rs @@ -6,7 +6,11 @@ use glib::{prelude::*, subclass::prelude::*, translate::*, GString, Quark, Varia use crate::{ffi, ActionGroup}; -pub trait ActionGroupImpl: ObjectImpl { +pub trait ActionGroupImpl: ObjectImpl +where + ::Type: IsA, + ::Type: IsA, +{ fn action_added(&self, action_name: &str) { self.parent_action_added(action_name); } @@ -73,12 +77,11 @@ pub trait ActionGroupImpl: ObjectImpl { )>; } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait ActionGroupImplExt: sealed::Sealed + ObjectSubclass { +pub trait ActionGroupImplExt: ObjectSubclass + ActionGroupImpl +where + ::Type: IsA, + ::Type: IsA, +{ fn parent_action_added(&self, action_name: &str) { unsafe { let type_data = Self::type_data(); @@ -341,9 +344,18 @@ pub trait ActionGroupImplExt: sealed::Sealed + ObjectSubclass { } } -impl ActionGroupImplExt for T {} +impl ActionGroupImplExt for T +where + ::Type: IsA, + ::Type: IsA, +{ +} -unsafe impl IsImplementable for ActionGroup { +unsafe impl IsImplementable for ActionGroup +where + ::Type: IsA, + ::Type: IsA, +{ fn interface_init(iface: &mut glib::Interface) { let iface = iface.as_mut(); @@ -367,7 +379,11 @@ unsafe impl IsImplementable for ActionGroup { unsafe extern "C" fn action_group_has_action( action_group: *mut ffi::GActionGroup, action_nameptr: *const libc::c_char, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(action_group as *mut T::Instance); let action_name = GString::from_glib_borrow(action_nameptr); let imp = instance.imp(); @@ -378,7 +394,11 @@ unsafe extern "C" fn action_group_has_action( unsafe extern "C" fn action_group_get_action_enabled( action_group: *mut ffi::GActionGroup, action_nameptr: *const libc::c_char, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(action_group as *mut T::Instance); let imp = instance.imp(); let action_name = GString::from_glib_borrow(action_nameptr); @@ -399,7 +419,11 @@ impl Drop for PtrHolder { unsafe extern "C" fn action_group_get_action_parameter_type( action_group: *mut ffi::GActionGroup, action_nameptr: *const libc::c_char, -) -> *const glib::ffi::GVariantType { +) -> *const glib::ffi::GVariantType +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(action_group as *mut T::Instance); let imp = instance.imp(); let action_name = GString::from_glib_borrow(action_nameptr); @@ -428,7 +452,11 @@ unsafe extern "C" fn action_group_get_action_parameter_type( unsafe extern "C" fn action_group_get_action_state_type( action_group: *mut ffi::GActionGroup, action_nameptr: *const libc::c_char, -) -> *const glib::ffi::GVariantType { +) -> *const glib::ffi::GVariantType +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(action_group as *mut T::Instance); let imp = instance.imp(); let action_name = GString::from_glib_borrow(action_nameptr); @@ -457,7 +485,11 @@ unsafe extern "C" fn action_group_get_action_state_type( unsafe extern "C" fn action_group_get_action_state_hint( action_group: *mut ffi::GActionGroup, action_nameptr: *const libc::c_char, -) -> *mut glib::ffi::GVariant { +) -> *mut glib::ffi::GVariant +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(action_group as *mut T::Instance); let imp = instance.imp(); let action_name = GString::from_glib_borrow(action_nameptr); @@ -485,7 +517,11 @@ unsafe extern "C" fn action_group_get_action_state_hint( unsafe extern "C" fn action_group_get_action_state( action_group: *mut ffi::GActionGroup, action_nameptr: *const libc::c_char, -) -> *mut glib::ffi::GVariant { +) -> *mut glib::ffi::GVariant +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(action_group as *mut T::Instance); let imp = instance.imp(); let action_name = GString::from_glib_borrow(action_nameptr); @@ -512,7 +548,10 @@ unsafe extern "C" fn action_group_change_action_state( action_group: *mut ffi::GActionGroup, action_nameptr: *const libc::c_char, stateptr: *mut glib::ffi::GVariant, -) { +) where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(action_group as *mut T::Instance); let imp = instance.imp(); let action_name = GString::from_glib_borrow(action_nameptr); @@ -525,7 +564,10 @@ unsafe extern "C" fn action_group_activate_action( action_group: *mut ffi::GActionGroup, action_nameptr: *const libc::c_char, parameterptr: *mut glib::ffi::GVariant, -) { +) where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(action_group as *mut T::Instance); let imp = instance.imp(); let action_name = GString::from_glib_borrow(action_nameptr); @@ -537,7 +579,10 @@ unsafe extern "C" fn action_group_activate_action( unsafe extern "C" fn action_group_action_added( action_group: *mut ffi::GActionGroup, action_nameptr: *const libc::c_char, -) { +) where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(action_group as *mut T::Instance); let imp = instance.imp(); let action_name = GString::from_glib_borrow(action_nameptr); @@ -548,7 +593,10 @@ unsafe extern "C" fn action_group_action_added( unsafe extern "C" fn action_group_action_removed( action_group: *mut ffi::GActionGroup, action_nameptr: *const libc::c_char, -) { +) where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(action_group as *mut T::Instance); let imp = instance.imp(); let action_name = GString::from_glib_borrow(action_nameptr); @@ -560,7 +608,10 @@ unsafe extern "C" fn action_group_action_enabled_changed( action_group: *mut ffi::GActionGroup, action_nameptr: *const libc::c_char, enabled: glib::ffi::gboolean, -) { +) where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(action_group as *mut T::Instance); let imp = instance.imp(); let action_name = GString::from_glib_borrow(action_nameptr); @@ -572,7 +623,10 @@ unsafe extern "C" fn action_group_action_state_changed( action_group: *mut ffi::GActionGroup, action_nameptr: *const libc::c_char, stateptr: *mut glib::ffi::GVariant, -) { +) where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(action_group as *mut T::Instance); let imp = instance.imp(); let action_name = GString::from_glib_borrow(action_nameptr); @@ -583,7 +637,11 @@ unsafe extern "C" fn action_group_action_state_changed( unsafe extern "C" fn action_group_list_actions( action_group: *mut ffi::GActionGroup, -) -> *mut *mut libc::c_char { +) -> *mut *mut libc::c_char +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(action_group as *mut T::Instance); let imp = instance.imp(); @@ -609,7 +667,11 @@ unsafe extern "C" fn action_group_query_action( state_type: *mut *const glib::ffi::GVariantType, state_hint: *mut *mut glib::ffi::GVariant, state: *mut *mut glib::ffi::GVariant, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(action_group as *mut T::Instance); let imp = instance.imp(); let action_name = GString::from_glib_borrow(action_nameptr); diff --git a/gio/src/subclass/action_map.rs b/gio/src/subclass/action_map.rs index d7a668ee33e7..6a30d68ec107 100644 --- a/gio/src/subclass/action_map.rs +++ b/gio/src/subclass/action_map.rs @@ -6,18 +6,21 @@ use glib::{prelude::*, subclass::prelude::*, translate::*, GString, Quark}; use crate::{ffi, Action, ActionMap}; -pub trait ActionMapImpl: ObjectImpl { +pub trait ActionMapImpl: ObjectImpl +where + ::Type: IsA, + ::Type: IsA, +{ fn lookup_action(&self, action_name: &str) -> Option; fn add_action(&self, action: &Action); fn remove_action(&self, action_name: &str); } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait ActionMapImplExt: sealed::Sealed + ObjectSubclass { +pub trait ActionMapImplExt: ObjectSubclass + ActionMapImpl +where + ::Type: IsA, + ::Type: IsA, +{ fn parent_lookup_action(&self, name: &str) -> Option { unsafe { let type_data = Self::type_data(); @@ -68,11 +71,17 @@ pub trait ActionMapImplExt: sealed::Sealed + ObjectSubclass { } } -impl ActionMapImplExt for T {} +impl ActionMapImplExt for T +where + ::Type: IsA, + ::Type: IsA, +{ +} unsafe impl IsImplementable for ActionMap where ::Type: IsA, + ::Type: IsA, { fn interface_init(iface: &mut glib::Interface) { let iface = iface.as_mut(); @@ -86,7 +95,11 @@ where unsafe extern "C" fn action_map_lookup_action( action_map: *mut ffi::GActionMap, action_nameptr: *const libc::c_char, -) -> *mut ffi::GAction { +) -> *mut ffi::GAction +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(action_map as *mut T::Instance); let action_name = GString::from_glib_borrow(action_nameptr); let imp = instance.imp(); @@ -116,7 +129,10 @@ unsafe extern "C" fn action_map_lookup_action( unsafe extern "C" fn action_map_add_action( action_map: *mut ffi::GActionMap, actionptr: *mut ffi::GAction, -) { +) where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(action_map as *mut T::Instance); let imp = instance.imp(); let action: Borrowed = from_glib_borrow(actionptr); @@ -127,7 +143,10 @@ unsafe extern "C" fn action_map_add_action( unsafe extern "C" fn action_map_remove_action( action_map: *mut ffi::GActionMap, action_nameptr: *const libc::c_char, -) { +) where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(action_map as *mut T::Instance); let imp = instance.imp(); let action_name = GString::from_glib_borrow(action_nameptr); diff --git a/gio/src/subclass/application.rs b/gio/src/subclass/application.rs index 5a863c388d17..bee49e117bed 100644 --- a/gio/src/subclass/application.rs +++ b/gio/src/subclass/application.rs @@ -64,7 +64,11 @@ impl From for Vec { } } -pub trait ApplicationImpl: ObjectImpl + ApplicationImplExt { +pub trait ApplicationImpl: ObjectImpl +where + ::Type: IsA, + ::Type: IsA, +{ fn activate(&self) { self.parent_activate() } @@ -110,12 +114,11 @@ pub trait ApplicationImpl: ObjectImpl + ApplicationImplExt { } } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait ApplicationImplExt: sealed::Sealed + ObjectSubclass { +pub trait ApplicationImplExt: ObjectSubclass + ApplicationImpl +where + ::Type: IsA, + ::Type: IsA, +{ fn parent_activate(&self) { unsafe { let data = Self::type_data(); @@ -271,9 +274,18 @@ pub trait ApplicationImplExt: sealed::Sealed + ObjectSubclass { } } -impl ApplicationImplExt for T {} +impl ApplicationImplExt for T +where + ::Type: IsA, + ::Type: IsA, +{ +} -unsafe impl IsSubclassable for Application { +unsafe impl IsSubclassable for Application +where + ::Type: IsA, + ::Type: IsA, +{ fn class_init(class: &mut ::glib::Class) { Self::parent_class_init::(class); @@ -292,7 +304,11 @@ unsafe impl IsSubclassable for Application { } } -unsafe extern "C" fn application_activate(ptr: *mut ffi::GApplication) { +unsafe extern "C" fn application_activate(ptr: *mut ffi::GApplication) +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -302,7 +318,10 @@ unsafe extern "C" fn application_activate(ptr: *mut ffi::GAp unsafe extern "C" fn application_after_emit( ptr: *mut ffi::GApplication, platform_data: *mut glib::ffi::GVariant, -) { +) where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -311,7 +330,10 @@ unsafe extern "C" fn application_after_emit( unsafe extern "C" fn application_before_emit( ptr: *mut ffi::GApplication, platform_data: *mut glib::ffi::GVariant, -) { +) where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -320,7 +342,11 @@ unsafe extern "C" fn application_before_emit( unsafe extern "C" fn application_command_line( ptr: *mut ffi::GApplication, command_line: *mut ffi::GApplicationCommandLine, -) -> i32 { +) -> i32 +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -330,7 +356,11 @@ unsafe extern "C" fn application_local_command_line( ptr: *mut ffi::GApplication, arguments: *mut *mut *mut c_char, exit_status: *mut i32, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -351,32 +381,51 @@ unsafe extern "C" fn application_open( files: *mut *mut ffi::GFile, num_files: i32, hint: *const c_char, -) { +) where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); let files: Vec = FromGlibContainer::from_glib_none_num(files, num_files as usize); imp.open(files.as_slice(), &glib::GString::from_glib_borrow(hint)) } -unsafe extern "C" fn application_quit_mainloop(ptr: *mut ffi::GApplication) { +unsafe extern "C" fn application_quit_mainloop(ptr: *mut ffi::GApplication) +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); imp.quit_mainloop() } -unsafe extern "C" fn application_run_mainloop(ptr: *mut ffi::GApplication) { +unsafe extern "C" fn application_run_mainloop(ptr: *mut ffi::GApplication) +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); imp.run_mainloop() } -unsafe extern "C" fn application_shutdown(ptr: *mut ffi::GApplication) { +unsafe extern "C" fn application_shutdown(ptr: *mut ffi::GApplication) +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); imp.shutdown() } -unsafe extern "C" fn application_startup(ptr: *mut ffi::GApplication) { +unsafe extern "C" fn application_startup(ptr: *mut ffi::GApplication) +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -386,7 +435,11 @@ unsafe extern "C" fn application_startup(ptr: *mut ffi::GApp unsafe extern "C" fn application_handle_local_options( ptr: *mut ffi::GApplication, options: *mut glib::ffi::GVariantDict, -) -> c_int { +) -> c_int +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); diff --git a/gio/src/subclass/async_initable.rs b/gio/src/subclass/async_initable.rs index 1c2171bcfa55..07e36151f943 100644 --- a/gio/src/subclass/async_initable.rs +++ b/gio/src/subclass/async_initable.rs @@ -8,7 +8,11 @@ use crate::{ ffi, AsyncInitable, AsyncResult, Cancellable, CancellableFuture, GioFutureResult, LocalTask, }; -pub trait AsyncInitableImpl: ObjectImpl { +pub trait AsyncInitableImpl: ObjectImpl +where + ::Type: IsA, + ::Type: IsA, +{ fn init_future( &self, io_priority: glib::Priority, @@ -17,12 +21,11 @@ pub trait AsyncInitableImpl: ObjectImpl { } } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait AsyncInitableImplExt: sealed::Sealed + AsyncInitableImpl + ObjectSubclass { +pub trait AsyncInitableImplExt: ObjectSubclass + AsyncInitableImpl +where + ::Type: IsA, + ::Type: IsA, +{ fn parent_init_future( &self, io_priority: glib::Priority, @@ -42,6 +45,8 @@ pub trait AsyncInitableImplExt: sealed::Sealed + AsyncInitableImpl + ObjectSubcl user_data: glib::ffi::gpointer, ) where T: AsyncInitableImpl, + ::Type: IsA, + ::Type: IsA, { let type_data = T::type_data(); let parent_iface = type_data.as_ref().parent_interface::() @@ -83,9 +88,18 @@ pub trait AsyncInitableImplExt: sealed::Sealed + AsyncInitableImpl + ObjectSubcl } } -impl AsyncInitableImplExt for T {} +impl AsyncInitableImplExt for T +where + ::Type: IsA, + ::Type: IsA, +{ +} -unsafe impl IsImplementable for AsyncInitable { +unsafe impl IsImplementable for AsyncInitable +where + ::Type: IsA, + ::Type: IsA, +{ fn interface_init(iface: &mut glib::Interface) { let iface = iface.as_mut(); iface.init_async = Some(async_initable_init_async::); @@ -99,7 +113,10 @@ unsafe extern "C" fn async_initable_init_async( cancellable: *mut ffi::GCancellable, callback: ffi::GAsyncReadyCallback, user_data: glib::ffi::gpointer, -) { +) where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(initable as *mut T::Instance); let imp = instance.imp(); let cancellable = Option::::from_glib_none(cancellable); diff --git a/gio/src/subclass/initable.rs b/gio/src/subclass/initable.rs index 23b4beb7fc8e..4c83a6a89667 100644 --- a/gio/src/subclass/initable.rs +++ b/gio/src/subclass/initable.rs @@ -6,18 +6,21 @@ use glib::{prelude::*, subclass::prelude::*, translate::*, Error}; use crate::{ffi, Cancellable, Initable}; -pub trait InitableImpl: ObjectImpl { +pub trait InitableImpl: ObjectImpl +where + ::Type: IsA, + ::Type: IsA, +{ fn init(&self, cancellable: Option<&Cancellable>) -> Result<(), Error> { self.parent_init(cancellable) } } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait InitableImplExt: sealed::Sealed + ObjectSubclass { +pub trait InitableImplExt: ObjectSubclass + InitableImpl +where + ::Type: IsA, + ::Type: IsA, +{ fn parent_init(&self, cancellable: Option<&Cancellable>) -> Result<(), Error> { unsafe { let type_data = Self::type_data(); @@ -44,9 +47,18 @@ pub trait InitableImplExt: sealed::Sealed + ObjectSubclass { } } -impl InitableImplExt for T {} +impl InitableImplExt for T +where + ::Type: IsA, + ::Type: IsA, +{ +} -unsafe impl IsImplementable for Initable { +unsafe impl IsImplementable for Initable +where + ::Type: IsA, + ::Type: IsA, +{ fn interface_init(iface: &mut glib::Interface) { let iface = iface.as_mut(); iface.init = Some(initable_init::); @@ -57,7 +69,11 @@ unsafe extern "C" fn initable_init( initable: *mut ffi::GInitable, cancellable: *mut ffi::GCancellable, error: *mut *mut glib::ffi::GError, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(initable as *mut T::Instance); let imp = instance.imp(); diff --git a/gio/src/subclass/input_stream.rs b/gio/src/subclass/input_stream.rs index e65e27678791..67295120e520 100644 --- a/gio/src/subclass/input_stream.rs +++ b/gio/src/subclass/input_stream.rs @@ -6,7 +6,11 @@ use glib::{prelude::*, subclass::prelude::*, translate::*, Error}; use crate::{ffi, Cancellable, InputStream}; -pub trait InputStreamImpl: ObjectImpl + InputStreamImplExt + Send { +pub trait InputStreamImpl: ObjectImpl + Send +where + ::Type: IsA, + ::Type: IsA, +{ fn read(&self, buffer: &mut [u8], cancellable: Option<&Cancellable>) -> Result { self.parent_read(buffer, cancellable) } @@ -20,12 +24,11 @@ pub trait InputStreamImpl: ObjectImpl + InputStreamImplExt + Send { } } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait InputStreamImplExt: sealed::Sealed + ObjectSubclass { +pub trait InputStreamImplExt: ObjectSubclass + InputStreamImpl +where + ::Type: IsA, + ::Type: IsA, +{ fn parent_read( &self, buffer: &mut [u8], @@ -103,9 +106,18 @@ pub trait InputStreamImplExt: sealed::Sealed + ObjectSubclass { } } -impl InputStreamImplExt for T {} +impl InputStreamImplExt for T +where + ::Type: IsA, + ::Type: IsA, +{ +} -unsafe impl IsSubclassable for InputStream { +unsafe impl IsSubclassable for InputStream +where + ::Type: IsA, + ::Type: IsA, +{ fn class_init(class: &mut ::glib::Class) { Self::parent_class_init::(class); @@ -122,7 +134,11 @@ unsafe extern "C" fn stream_read( count: usize, cancellable: *mut ffi::GCancellable, err: *mut *mut glib::ffi::GError, -) -> isize { +) -> isize +where + ::Type: IsA, + ::Type: IsA, +{ debug_assert!(count <= isize::MAX as usize); let instance = &*(ptr as *mut T::Instance); @@ -156,7 +172,11 @@ unsafe extern "C" fn stream_close( ptr: *mut ffi::GInputStream, cancellable: *mut ffi::GCancellable, err: *mut *mut glib::ffi::GError, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -180,7 +200,11 @@ unsafe extern "C" fn stream_skip( count: usize, cancellable: *mut ffi::GCancellable, err: *mut *mut glib::ffi::GError, -) -> isize { +) -> isize +where + ::Type: IsA, + ::Type: IsA, +{ debug_assert!(count <= isize::MAX as usize); let instance = &*(ptr as *mut T::Instance); @@ -299,7 +323,8 @@ mod tests { glib::wrapper! { pub struct SimpleInputStream(ObjectSubclass) - @extends InputStream; + @extends InputStream, + @implements crate::Seekable; } #[test] diff --git a/gio/src/subclass/io_stream.rs b/gio/src/subclass/io_stream.rs index 6a3b290c7049..193ab49a979e 100644 --- a/gio/src/subclass/io_stream.rs +++ b/gio/src/subclass/io_stream.rs @@ -6,7 +6,11 @@ use glib::{prelude::*, subclass::prelude::*, translate::*, Error}; use crate::{ffi, Cancellable, IOStream, InputStream, OutputStream}; -pub trait IOStreamImpl: ObjectImpl + IOStreamImplExt + Send { +pub trait IOStreamImpl: ObjectImpl + Send +where + ::Type: IsA, + ::Type: IsA, +{ fn input_stream(&self) -> InputStream { self.parent_input_stream() } @@ -20,12 +24,11 @@ pub trait IOStreamImpl: ObjectImpl + IOStreamImplExt + Send { } } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait IOStreamImplExt: sealed::Sealed + ObjectSubclass { +pub trait IOStreamImplExt: ObjectSubclass + IOStreamImpl +where + ::Type: IsA, + ::Type: IsA, +{ fn parent_input_stream(&self) -> InputStream { unsafe { let data = Self::type_data(); @@ -70,9 +73,18 @@ pub trait IOStreamImplExt: sealed::Sealed + ObjectSubclass { } } -impl IOStreamImplExt for T {} +impl IOStreamImplExt for T +where + ::Type: IsA, + ::Type: IsA, +{ +} -unsafe impl IsSubclassable for IOStream { +unsafe impl IsSubclassable for IOStream +where + ::Type: IsA, + ::Type: IsA, +{ fn class_init(class: &mut ::glib::Class) { Self::parent_class_init::(class); @@ -85,7 +97,11 @@ unsafe impl IsSubclassable for IOStream { unsafe extern "C" fn stream_get_input_stream( ptr: *mut ffi::GIOStream, -) -> *mut ffi::GInputStream { +) -> *mut ffi::GInputStream +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -112,7 +128,11 @@ unsafe extern "C" fn stream_get_input_stream( unsafe extern "C" fn stream_get_output_stream( ptr: *mut ffi::GIOStream, -) -> *mut ffi::GOutputStream { +) -> *mut ffi::GOutputStream +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -141,7 +161,11 @@ unsafe extern "C" fn stream_close( ptr: *mut ffi::GIOStream, cancellable: *mut ffi::GCancellable, err: *mut *mut glib::ffi::GError, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); diff --git a/gio/src/subclass/list_model.rs b/gio/src/subclass/list_model.rs index 96a411f3595b..ebe0d4b7f9f5 100644 --- a/gio/src/subclass/list_model.rs +++ b/gio/src/subclass/list_model.rs @@ -6,7 +6,11 @@ use glib::{prelude::*, subclass::prelude::*, translate::*}; use crate::{ffi, ListModel}; -pub trait ListModelImpl: ObjectImpl { +pub trait ListModelImpl: ObjectImpl +where + ::Type: IsA, + ::Type: IsA, +{ #[doc(alias = "get_item_type")] fn item_type(&self) -> glib::Type; #[doc(alias = "get_n_items")] @@ -15,12 +19,11 @@ pub trait ListModelImpl: ObjectImpl { fn item(&self, position: u32) -> Option; } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait ListModelImplExt: sealed::Sealed + ObjectSubclass { +pub trait ListModelImplExt: ObjectSubclass + ListModelImpl +where + ::Type: IsA, + ::Type: IsA, +{ fn parent_item_type(&self) -> glib::Type { unsafe { let type_data = Self::type_data(); @@ -66,11 +69,17 @@ pub trait ListModelImplExt: sealed::Sealed + ObjectSubclass { } } -impl ListModelImplExt for T {} +impl ListModelImplExt for T +where + ::Type: IsA, + ::Type: IsA, +{ +} unsafe impl IsImplementable for ListModel where ::Type: IsA, + ::Type: IsA, { fn interface_init(iface: &mut glib::Interface) { let iface = iface.as_mut(); @@ -86,6 +95,7 @@ unsafe extern "C" fn list_model_get_item_type( ) -> glib::ffi::GType where ::Type: IsA, + ::Type: IsA, { let instance = &*(list_model as *mut T::Instance); let imp = instance.imp(); @@ -118,6 +128,7 @@ unsafe extern "C" fn list_model_get_n_items( ) -> u32 where ::Type: IsA, + ::Type: IsA, { let instance = &*(list_model as *mut T::Instance); let imp = instance.imp(); @@ -131,6 +142,7 @@ unsafe extern "C" fn list_model_get_item( ) -> *mut glib::gobject_ffi::GObject where ::Type: IsA, + ::Type: IsA, { let instance = &*(list_model as *mut T::Instance); let imp = instance.imp(); diff --git a/gio/src/subclass/output_stream.rs b/gio/src/subclass/output_stream.rs index 6f9d8ec86c6c..11e1de18b707 100644 --- a/gio/src/subclass/output_stream.rs +++ b/gio/src/subclass/output_stream.rs @@ -6,7 +6,11 @@ use glib::{prelude::*, subclass::prelude::*, translate::*, Error}; use crate::{ffi, Cancellable, InputStream, OutputStream, OutputStreamSpliceFlags}; -pub trait OutputStreamImpl: ObjectImpl + OutputStreamImplExt + Send { +pub trait OutputStreamImpl: ObjectImpl + Send +where + ::Type: IsA, + ::Type: IsA, +{ fn write(&self, buffer: &[u8], cancellable: Option<&Cancellable>) -> Result { self.parent_write(buffer, cancellable) } @@ -29,12 +33,11 @@ pub trait OutputStreamImpl: ObjectImpl + OutputStreamImplExt + Send { } } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait OutputStreamImplExt: sealed::Sealed + ObjectSubclass { +pub trait OutputStreamImplExt: ObjectSubclass + OutputStreamImpl +where + ::Type: IsA, + ::Type: IsA, +{ fn parent_write( &self, buffer: &[u8], @@ -150,9 +153,18 @@ pub trait OutputStreamImplExt: sealed::Sealed + ObjectSubclass { } } -impl OutputStreamImplExt for T {} +impl OutputStreamImplExt for T +where + ::Type: IsA, + ::Type: IsA, +{ +} -unsafe impl IsSubclassable for OutputStream { +unsafe impl IsSubclassable for OutputStream +where + ::Type: IsA, + ::Type: IsA, +{ fn class_init(class: &mut ::glib::Class) { Self::parent_class_init::(class); @@ -170,7 +182,11 @@ unsafe extern "C" fn stream_write( count: usize, cancellable: *mut ffi::GCancellable, err: *mut *mut glib::ffi::GError, -) -> isize { +) -> isize +where + ::Type: IsA, + ::Type: IsA, +{ debug_assert!(count <= isize::MAX as usize); let instance = &*(ptr as *mut T::Instance); @@ -204,7 +220,11 @@ unsafe extern "C" fn stream_close( ptr: *mut ffi::GOutputStream, cancellable: *mut ffi::GCancellable, err: *mut *mut glib::ffi::GError, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -227,7 +247,11 @@ unsafe extern "C" fn stream_flush( ptr: *mut ffi::GOutputStream, cancellable: *mut ffi::GCancellable, err: *mut *mut glib::ffi::GError, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -252,7 +276,11 @@ unsafe extern "C" fn stream_splice( flags: ffi::GOutputStreamSpliceFlags, cancellable: *mut ffi::GCancellable, err: *mut *mut glib::ffi::GError, -) -> isize { +) -> isize +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); diff --git a/gio/src/subclass/seekable.rs b/gio/src/subclass/seekable.rs index 3d23db1e5a23..d713e20302c0 100644 --- a/gio/src/subclass/seekable.rs +++ b/gio/src/subclass/seekable.rs @@ -6,7 +6,11 @@ use glib::{prelude::*, subclass::prelude::*, translate::*, Error, SeekType}; use crate::{ffi, Cancellable, Seekable}; -pub trait SeekableImpl: ObjectImpl + Send { +pub trait SeekableImpl: ObjectImpl + Send +where + ::Type: IsA, + ::Type: IsA, +{ fn tell(&self) -> i64; fn can_seek(&self) -> bool; fn seek( @@ -19,12 +23,11 @@ pub trait SeekableImpl: ObjectImpl + Send { fn truncate(&self, offset: i64, cancellable: Option<&Cancellable>) -> Result<(), Error>; } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait SeekableImplExt: sealed::Sealed + ObjectSubclass { +pub trait SeekableImplExt: ObjectSubclass + SeekableImpl +where + ::Type: IsA, + ::Type: IsA, +{ fn parent_tell(&self) -> i64 { unsafe { let type_data = Self::type_data(); @@ -125,9 +128,18 @@ pub trait SeekableImplExt: sealed::Sealed + ObjectSubclass { } } -impl SeekableImplExt for T {} +impl SeekableImplExt for T +where + ::Type: IsA, + ::Type: IsA, +{ +} -unsafe impl IsImplementable for Seekable { +unsafe impl IsImplementable for Seekable +where + ::Type: IsA, + ::Type: IsA, +{ fn interface_init(iface: &mut glib::Interface) { let iface = iface.as_mut(); @@ -139,7 +151,11 @@ unsafe impl IsImplementable for Seekable { } } -unsafe extern "C" fn seekable_tell(seekable: *mut ffi::GSeekable) -> i64 { +unsafe extern "C" fn seekable_tell(seekable: *mut ffi::GSeekable) -> i64 +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(seekable as *mut T::Instance); let imp = instance.imp(); @@ -148,7 +164,11 @@ unsafe extern "C" fn seekable_tell(seekable: *mut ffi::GSeekabl unsafe extern "C" fn seekable_can_seek( seekable: *mut ffi::GSeekable, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(seekable as *mut T::Instance); let imp = instance.imp(); @@ -161,7 +181,11 @@ unsafe extern "C" fn seekable_seek( type_: glib::ffi::GSeekType, cancellable: *mut ffi::GCancellable, err: *mut *mut glib::ffi::GError, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(seekable as *mut T::Instance); let imp = instance.imp(); @@ -184,7 +208,11 @@ unsafe extern "C" fn seekable_seek( unsafe extern "C" fn seekable_can_truncate( seekable: *mut ffi::GSeekable, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(seekable as *mut T::Instance); let imp = instance.imp(); @@ -196,7 +224,11 @@ unsafe extern "C" fn seekable_truncate( offset: i64, cancellable: *mut ffi::GCancellable, err: *mut *mut glib::ffi::GError, -) -> glib::ffi::gboolean { +) -> glib::ffi::gboolean +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(seekable as *mut T::Instance); let imp = instance.imp(); diff --git a/gio/src/subclass/socket_control_message.rs b/gio/src/subclass/socket_control_message.rs index 3f43ac1608e1..230604e08a47 100644 --- a/gio/src/subclass/socket_control_message.rs +++ b/gio/src/subclass/socket_control_message.rs @@ -4,7 +4,11 @@ use glib::{prelude::*, subclass::prelude::*, translate::*}; use crate::{ffi, SocketControlMessage}; -pub trait SocketControlMessageImpl: ObjectImpl + SocketControlMessageImplExt { +pub trait SocketControlMessageImpl: ObjectImpl +where + ::Type: IsA, + ::Type: IsA, +{ fn level(&self) -> i32 { self.parent_level() } @@ -26,12 +30,11 @@ pub trait SocketControlMessageImpl: ObjectImpl + SocketControlMessageImplExt { } } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait SocketControlMessageImplExt: sealed::Sealed + ObjectSubclass { +pub trait SocketControlMessageImplExt: ObjectSubclass + SocketControlMessageImpl +where + ::Type: IsA, + ::Type: IsA, +{ fn parent_level(&self) -> i32 { unsafe { let data = Self::type_data(); @@ -113,9 +116,18 @@ pub trait SocketControlMessageImplExt: sealed::Sealed + ObjectSubclass { } } -impl SocketControlMessageImplExt for T {} +impl SocketControlMessageImplExt for T +where + ::Type: IsA, + ::Type: IsA, +{ +} -unsafe impl IsSubclassable for SocketControlMessage { +unsafe impl IsSubclassable for SocketControlMessage +where + ::Type: IsA, + ::Type: IsA, +{ fn class_init(class: &mut ::glib::Class) { Self::parent_class_init::(class); @@ -130,7 +142,11 @@ unsafe impl IsSubclassable for SocketControlMess unsafe extern "C" fn socket_control_message_get_level( ptr: *mut ffi::GSocketControlMessage, -) -> i32 { +) -> i32 +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -139,7 +155,11 @@ unsafe extern "C" fn socket_control_message_get_level( ptr: *mut ffi::GSocketControlMessage, -) -> i32 { +) -> i32 +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -148,7 +168,11 @@ unsafe extern "C" fn socket_control_message_get_type( ptr: *mut ffi::GSocketControlMessage, -) -> usize { +) -> usize +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -158,7 +182,10 @@ unsafe extern "C" fn socket_control_message_get_size( ptr: *mut ffi::GSocketControlMessage, data: glib::ffi::gpointer, -) { +) where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(ptr as *mut T::Instance); let imp = instance.imp(); @@ -172,7 +199,11 @@ unsafe extern "C" fn socket_control_message_deserialize *mut ffi::GSocketControlMessage { +) -> *mut ffi::GSocketControlMessage +where + ::Type: IsA, + ::Type: IsA, +{ let data = std::slice::from_raw_parts(data as *mut u8, size); T::deserialize(level, type_, data).into_glib_ptr() diff --git a/glib-macros/tests/object_subclass_dynamic.rs b/glib-macros/tests/object_subclass_dynamic.rs index 31ad917d215c..2b5a0bae9d8c 100644 --- a/glib-macros/tests/object_subclass_dynamic.rs +++ b/glib-macros/tests/object_subclass_dynamic.rs @@ -28,7 +28,12 @@ mod static_ { type Interface = MyStaticInterfaceClass; } - pub trait MyStaticInterfaceImpl: ObjectImpl + ObjectSubclass {} + pub trait MyStaticInterfaceImpl: ObjectImpl + ObjectSubclass + where + ::Type: IsA, + ::Type: IsA, + { + } // impl for an object subclass to register as a static type and that implements `MyStaticInterface`. #[derive(Default)] @@ -45,7 +50,12 @@ mod static_ { impl MyStaticInterfaceImpl for MyStaticType {} - pub trait MyStaticTypeImpl: ObjectImpl + ObjectSubclass {} + pub trait MyStaticTypeImpl: ObjectImpl + ObjectSubclass + where + ::Type: IsA, + ::Type: IsA, + { + } } // an object interface to register as a static type. @@ -53,14 +63,24 @@ mod static_ { pub struct MyStaticInterface(ObjectInterface); } - unsafe impl IsImplementable for MyStaticInterface {} + unsafe impl IsImplementable for MyStaticInterface + where + ::Type: IsA, + ::Type: IsA, + { + } // an object subclass to register as a static type and that implements `MyStaticInterface`. glib::wrapper! { pub struct MyStaticType(ObjectSubclass) @implements MyStaticInterface; } - unsafe impl IsSubclassable for MyStaticType {} + unsafe impl IsSubclassable for MyStaticType + where + ::Type: IsA, + ::Type: IsA, + { + } } use static_::{ @@ -95,7 +115,11 @@ mod module { type Interface = MyModuleInterfaceClass; } - pub trait MyModuleInterfaceImpl: ObjectImpl + ObjectSubclass {} + pub trait MyModuleInterfaceImpl: ObjectImpl + ObjectSubclass + where + ::Type: IsA, + { + } // impl for an object subclass to register as a dynamic type and that extends `MyStaticType` and that implements `MyStaticInterface` and `MyModuleInterface`. #[derive(Default)] @@ -139,7 +163,12 @@ mod module { type Interface = MyModuleInterfaceLazyClass; } - pub trait MyModuleInterfaceLazyImpl: ObjectImpl + ObjectSubclass {} + pub trait MyModuleInterfaceLazyImpl: ObjectImpl + ObjectSubclass + where + ::Type: IsA, + ::Type: IsA, + { + } // impl for an object subclass to lazy register as a dynamic type and that extends `MyStaticType` and that implements `MyStaticInterface` and `MyModuleInterfaceLazy`. #[derive(Default)] @@ -206,7 +235,12 @@ mod module { pub struct MyModuleInterface(ObjectInterface) @requires MyStaticInterface; } - unsafe impl IsImplementable for MyModuleInterface {} + unsafe impl IsImplementable for MyModuleInterface + where + ::Type: IsA, + ::Type: IsA, + { + } // an object subclass to register as a dynamic type and that extends `MyStaticType` and that implements `MyStaticInterface` and `MyModuleInterface`. glib::wrapper! { @@ -218,7 +252,12 @@ mod module { pub struct MyModuleInterfaceLazy(ObjectInterface) @requires MyStaticInterface; } - unsafe impl IsImplementable for MyModuleInterfaceLazy {} + unsafe impl IsImplementable for MyModuleInterfaceLazy + where + ::Type: IsA, + ::Type: IsA, + { + } // an object subclass to lazy register as a dynamic type and that extends `MyStaticType` that implements `MyStaticInterface` and `MyModuleInterfaceLazy`. glib::wrapper! { @@ -335,7 +374,12 @@ pub mod plugin { type Interface = MyPluginInterfaceClass; } - pub trait MyPluginInterfaceImpl: ObjectImpl + ObjectSubclass {} + pub trait MyPluginInterfaceImpl: ObjectImpl + ObjectSubclass + where + ::Type: IsA, + ::Type: IsA, + { + } // impl for an object subclass to register as a dynamic type and that extends `MyStaticType` and that implements `MyStaticInterface` and `MyPluginInterface`. #[derive(Default)] @@ -379,7 +423,12 @@ pub mod plugin { type Interface = MyPluginInterfaceLazyClass; } - pub trait MyPluginInterfaceLazyImpl: ObjectImpl + ObjectSubclass {} + pub trait MyPluginInterfaceLazyImpl: ObjectImpl + ObjectSubclass + where + ::Type: IsA, + ::Type: IsA, + { + } // impl for an object subclass to lazy register as a dynamic type and that extends `MyStaticType` and that implements `MyStaticInterface` and `MyPluginInterfaceLazy`. #[derive(Default)] @@ -400,7 +449,10 @@ pub mod plugin { impl MyStaticInterfaceImpl for MyPluginTypeLazy {} - impl MyPluginInterfaceLazyImpl for MyPluginTypeLazy {} + impl MyPluginInterfaceLazyImpl for MyPluginTypeLazy where + ::Type: IsA + { + } // impl for a type plugin (must implement `glib::TypePlugin`). #[derive(Default)] @@ -549,11 +601,16 @@ pub mod plugin { pub struct MyPluginInterface(ObjectInterface) @requires MyStaticInterface; } - unsafe impl IsImplementable for MyPluginInterface {} + unsafe impl IsImplementable for MyPluginInterface + where + ::Type: IsA, + ::Type: IsA, + { + } // an object subclass to register as a dynamic type and that extends `MyStaticType` and that implements `MyStaticInterface` and `MyPluginInterface`. glib::wrapper! { - pub struct MyPluginType(ObjectSubclass) @implements MyPluginInterface; + pub struct MyPluginType(ObjectSubclass) @extends MyStaticType, @implements MyPluginInterface, MyStaticInterface; } // an object interface to lazy register as a dynamic type and that extends `MyStaticInterface`. @@ -561,11 +618,16 @@ pub mod plugin { pub struct MyPluginInterfaceLazy(ObjectInterface) @requires MyStaticInterface; } - unsafe impl IsImplementable for MyPluginInterfaceLazy {} + unsafe impl IsImplementable for MyPluginInterfaceLazy + where + ::Type: IsA, + ::Type: IsA, + { + } // an object subclass to lazy register as a dynamic type and that extends `MyStaticType` that implements `MyStaticInterface` and `MyPluginInterfaceLazy`. glib::wrapper! { - pub struct MyPluginTypeLazy(ObjectSubclass) @implements MyPluginInterfaceLazy; + pub struct MyPluginTypeLazy(ObjectSubclass) @extends MyStaticType, @implements MyPluginInterfaceLazy, MyStaticInterface; } // a plugin (must implement `glib::TypePlugin`). diff --git a/glib-macros/tests/properties.rs b/glib-macros/tests/properties.rs index e4ca1da704bd..80d5fb43e913 100644 --- a/glib-macros/tests/properties.rs +++ b/glib-macros/tests/properties.rs @@ -42,7 +42,10 @@ mod base { pub struct Base(ObjectSubclass); } - unsafe impl IsSubclassable for Base {} + unsafe impl IsSubclassable for Base where + ::Type: IsA + { + } } #[cfg(test)] diff --git a/glib/src/gobject/dynamic_object.rs b/glib/src/gobject/dynamic_object.rs index f6e7648046fb..36648b5af720 100644 --- a/glib/src/gobject/dynamic_object.rs +++ b/glib/src/gobject/dynamic_object.rs @@ -4,7 +4,7 @@ use crate::{ enums::{EnumValues, FlagsValues}, prelude::*, subclass::prelude::*, - InterfaceInfo, TypeFlags, TypeInfo, TypeModule, TypePlugin, + InterfaceInfo, Object, TypeFlags, TypeInfo, TypeModule, TypePlugin, }; mod sealed { @@ -44,6 +44,8 @@ pub trait DynamicObjectRegisterExt: AsRef + sealed::Sealed + 'static impl + ObjectSubclassIsExt> DynamicObjectRegisterExt for O where O::Subclass: TypePluginRegisterImpl, + ::Type: IsA, + ::Type: IsA, { fn add_dynamic_interface( &self, diff --git a/glib/src/subclass/object.rs b/glib/src/subclass/object.rs index ae84380a48f7..95f2cbf5f258 100644 --- a/glib/src/subclass/object.rs +++ b/glib/src/subclass/object.rs @@ -19,7 +19,10 @@ use crate::{ /// /// This allows overriding the virtual methods of `glib::Object`. Except for /// `finalize` as implementing `Drop` would allow the same behavior. -pub trait ObjectImpl: ObjectSubclass + ObjectImplExt { +pub trait ObjectImpl: ObjectSubclass +where + ::Type: IsA, +{ // rustdoc-stripper-ignore-next /// Properties installed for this type. fn properties() -> &'static [ParamSpec] { @@ -92,7 +95,9 @@ unsafe extern "C" fn property( id: u32, value: *mut gobject_ffi::GValue, pspec: *mut gobject_ffi::GParamSpec, -) { +) where + ::Type: IsA, +{ let instance = &*(obj as *mut T::Instance); let imp = instance.imp(); @@ -116,7 +121,9 @@ unsafe extern "C" fn set_property( id: u32, value: *mut gobject_ffi::GValue, pspec: *mut gobject_ffi::GParamSpec, -) { +) where + ::Type: IsA, +{ let instance = &*(obj as *mut T::Instance); let imp = instance.imp(); imp.set_property( @@ -126,7 +133,10 @@ unsafe extern "C" fn set_property( ); } -unsafe extern "C" fn constructed(obj: *mut gobject_ffi::GObject) { +unsafe extern "C" fn constructed(obj: *mut gobject_ffi::GObject) +where + ::Type: IsA, +{ let instance = &*(obj as *mut T::Instance); let imp = instance.imp(); @@ -136,7 +146,9 @@ unsafe extern "C" fn constructed(obj: *mut gobject_ffi::GObject) unsafe extern "C" fn notify( obj: *mut gobject_ffi::GObject, pspec: *mut gobject_ffi::GParamSpec, -) { +) where + ::Type: IsA, +{ let instance = &*(obj as *mut T::Instance); let imp = instance.imp(); imp.notify(&from_glib_borrow(pspec)); @@ -146,13 +158,18 @@ unsafe extern "C" fn dispatch_properties_changed( obj: *mut gobject_ffi::GObject, n_pspecs: u32, pspecs: *mut *mut gobject_ffi::GParamSpec, -) { +) where + ::Type: IsA, +{ let instance = &*(obj as *mut T::Instance); let imp = instance.imp(); imp.dispatch_properties_changed(Slice::from_glib_borrow_num(pspecs, n_pspecs as _)); } -unsafe extern "C" fn dispose(obj: *mut gobject_ffi::GObject) { +unsafe extern "C" fn dispose(obj: *mut gobject_ffi::GObject) +where + ::Type: IsA, +{ let instance = &*(obj as *mut T::Instance); let imp = instance.imp(); @@ -213,7 +230,10 @@ pub unsafe trait ObjectClassSubclassExt: Sized + 'static { unsafe impl ObjectClassSubclassExt for crate::Class {} -unsafe impl IsSubclassable for Object { +unsafe impl IsSubclassable for Object +where + ::Type: IsA, +{ fn class_init(class: &mut crate::Class) { let klass = class.as_mut(); klass.set_property = Some(set_property::); @@ -253,12 +273,10 @@ unsafe impl IsSubclassable for Object { fn instance_init(_instance: &mut super::InitializingObject) {} } -mod sealed { - pub trait Sealed {} - impl Sealed for T {} -} - -pub trait ObjectImplExt: sealed::Sealed + ObjectSubclass { +pub trait ObjectImplExt: ObjectSubclass + ObjectImpl +where + ::Type: IsA, +{ // rustdoc-stripper-ignore-next /// Chain up to the parent class' implementation of `glib::Object::constructed()`. #[inline] @@ -321,7 +339,7 @@ pub trait ObjectImplExt: sealed::Sealed + ObjectSubclass { } } -impl ObjectImplExt for T {} +impl ObjectImplExt for T where ::Type: IsA {} #[cfg(test)] mod test { diff --git a/glib/src/subclass/type_module.rs b/glib/src/subclass/type_module.rs index bb0fe6f78ce8..7382957df4ab 100644 --- a/glib/src/subclass/type_module.rs +++ b/glib/src/subclass/type_module.rs @@ -1,8 +1,12 @@ // Take a look at the license at the top of the repository in the LICENSE file. -use crate::{ffi, gobject_ffi, prelude::*, subclass::prelude::*, translate::*, TypeModule}; +use crate::{ffi, gobject_ffi, prelude::*, subclass::prelude::*, translate::*, Object, TypeModule}; -pub trait TypeModuleImpl: ObjectImpl + TypeModuleImplExt { +pub trait TypeModuleImpl: ObjectImpl +where + ::Type: IsA, + ::Type: IsA, +{ // rustdoc-stripper-ignore-next /// Loads the module, registers one or more object subclasses using /// [`register_dynamic_type`] and registers one or more object interfaces @@ -21,12 +25,20 @@ pub trait TypeModuleImpl: ObjectImpl + TypeModuleImplExt { fn unload(&self); } -pub trait TypeModuleImplExt: ObjectSubclass { +pub trait TypeModuleImplExt: ObjectSubclass + TypeModuleImpl +where + ::Type: IsA, + ::Type: IsA, +{ fn parent_load(&self) -> bool; fn parent_unload(&self); } -impl TypeModuleImplExt for T { +impl TypeModuleImplExt for T +where + ::Type: IsA, + ::Type: IsA, +{ fn parent_load(&self) -> bool { unsafe { let data = T::type_data(); @@ -58,7 +70,11 @@ impl TypeModuleImplExt for T { } } -unsafe impl IsSubclassable for TypeModule { +unsafe impl IsSubclassable for TypeModule +where + ::Type: IsA, + ::Type: IsA, +{ fn class_init(class: &mut crate::Class) { Self::parent_class_init::(class); @@ -70,7 +86,11 @@ unsafe impl IsSubclassable for TypeModule { unsafe extern "C" fn load( type_module: *mut gobject_ffi::GTypeModule, -) -> ffi::gboolean { +) -> ffi::gboolean +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(type_module as *mut T::Instance); let imp = instance.imp(); @@ -90,7 +110,11 @@ unsafe extern "C" fn load( res.into_glib() } -unsafe extern "C" fn unload(type_module: *mut gobject_ffi::GTypeModule) { +unsafe extern "C" fn unload(type_module: *mut gobject_ffi::GTypeModule) +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(type_module as *mut T::Instance); let imp = instance.imp(); diff --git a/glib/src/subclass/type_plugin.rs b/glib/src/subclass/type_plugin.rs index bb4d755f8a88..04fd1bb4035d 100644 --- a/glib/src/subclass/type_plugin.rs +++ b/glib/src/subclass/type_plugin.rs @@ -3,10 +3,14 @@ use crate::enums::{EnumValues, FlagsValues}; use crate::{ ffi, gobject_ffi, prelude::*, subclass::prelude::*, translate::*, Interface, InterfaceInfo, - Type, TypeFlags, TypeInfo, TypePlugin, TypeValueTable, + Object, Type, TypeFlags, TypeInfo, TypePlugin, TypeValueTable, }; -pub trait TypePluginImpl: ObjectImpl + TypePluginImplExt { +pub trait TypePluginImpl: ObjectImpl +where + ::Type: IsA, + ::Type: IsA, +{ fn use_plugin(&self) { self.parent_use_plugin(); } @@ -24,7 +28,11 @@ pub trait TypePluginImpl: ObjectImpl + TypePluginImplExt { } } -pub trait TypePluginImplExt: ObjectSubclass { +pub trait TypePluginImplExt: ObjectSubclass + TypePluginImpl +where + ::Type: IsA, + ::Type: IsA, +{ fn parent_use_plugin(&self); fn parent_unuse_plugin(&self); fn parent_complete_type_info(&self, type_: Type) -> (TypeInfo, TypeValueTable); @@ -35,7 +43,11 @@ pub trait TypePluginImplExt: ObjectSubclass { ) -> InterfaceInfo; } -impl TypePluginImplExt for T { +impl TypePluginImplExt for T +where + ::Type: IsA, + ::Type: IsA, +{ fn parent_use_plugin(&self) { unsafe { let type_data = Self::type_data(); @@ -113,7 +125,11 @@ impl TypePluginImplExt for T { } } -unsafe impl IsImplementable for TypePlugin { +unsafe impl IsImplementable for TypePlugin +where + ::Type: IsA, + ::Type: IsA, +{ fn interface_init(iface: &mut Interface) { let iface = iface.as_mut(); @@ -124,14 +140,22 @@ unsafe impl IsImplementable for TypePlugin { } } -unsafe extern "C" fn use_plugin(type_plugin: *mut gobject_ffi::GTypePlugin) { +unsafe extern "C" fn use_plugin(type_plugin: *mut gobject_ffi::GTypePlugin) +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(type_plugin as *mut T::Instance); let imp = instance.imp(); imp.use_plugin(); } -unsafe extern "C" fn unuse_plugin(type_plugin: *mut gobject_ffi::GTypePlugin) { +unsafe extern "C" fn unuse_plugin(type_plugin: *mut gobject_ffi::GTypePlugin) +where + ::Type: IsA, + ::Type: IsA, +{ let instance = &*(type_plugin as *mut T::Instance); let imp = instance.imp(); @@ -143,7 +167,10 @@ unsafe extern "C" fn complete_type_info( gtype: ffi::GType, info_ptr: *mut gobject_ffi::GTypeInfo, value_table_ptr: *mut gobject_ffi::GTypeValueTable, -) { +) where + ::Type: IsA, + ::Type: IsA, +{ assert!(!info_ptr.is_null()); assert!(!value_table_ptr.is_null()); let instance = &*(type_plugin as *mut T::Instance); @@ -163,7 +190,10 @@ unsafe extern "C" fn complete_interface_info( instance_gtype: ffi::GType, interface_gtype: ffi::GType, info_ptr: *mut gobject_ffi::GInterfaceInfo, -) { +) where + ::Type: IsA, + ::Type: IsA, +{ assert!(!info_ptr.is_null()); let instance = &*(type_plugin as *mut T::Instance); let imp = instance.imp(); @@ -175,7 +205,11 @@ unsafe extern "C" fn complete_interface_info( *info = info_; } -pub trait TypePluginRegisterImpl: ObjectImpl + TypePluginImpl { +pub trait TypePluginRegisterImpl: ObjectImpl + TypePluginImpl +where + ::Type: IsA, + ::Type: IsA, +{ fn add_dynamic_interface( &self, _instance_type: Type, diff --git a/glib/tests/subclass_compiletest/04-auto-send-sync-with-send-sync-parent.rs b/glib/tests/subclass_compiletest/04-auto-send-sync-with-send-sync-parent.rs index f3c38aebfe51..22e63f5e4298 100644 --- a/glib/tests/subclass_compiletest/04-auto-send-sync-with-send-sync-parent.rs +++ b/glib/tests/subclass_compiletest/04-auto-send-sync-with-send-sync-parent.rs @@ -19,9 +19,16 @@ glib::wrapper! { pub struct TestParent(ObjectSubclass); } -pub trait TestParentImpl: glib::subclass::prelude::ObjectImpl + Send + Sync {} +pub trait TestParentImpl: glib::subclass::prelude::ObjectImpl + Send + Sync +where + ::Type: glib::prelude::IsA, +{ +} -unsafe impl glib::subclass::prelude::IsSubclassable for TestParent {} +unsafe impl glib::subclass::prelude::IsSubclassable for TestParent where + ::Type: glib::prelude::IsA +{ +} impl Default for TestParent { fn default() -> Self { diff --git a/glib/tests/subclass_compiletest/05-no-auto-send-sync-with-non-send-sync-parent.rs b/glib/tests/subclass_compiletest/05-no-auto-send-sync-with-non-send-sync-parent.rs index 836f225b82d1..72114287d8cb 100644 --- a/glib/tests/subclass_compiletest/05-no-auto-send-sync-with-non-send-sync-parent.rs +++ b/glib/tests/subclass_compiletest/05-no-auto-send-sync-with-non-send-sync-parent.rs @@ -20,9 +20,16 @@ glib::wrapper! { pub struct TestParent(ObjectSubclass); } -pub trait TestParentImpl: glib::subclass::prelude::ObjectImpl {} +pub trait TestParentImpl: glib::subclass::prelude::ObjectImpl +where + ::Type: glib::prelude::IsA, +{ +} -unsafe impl glib::subclass::prelude::IsSubclassable for TestParent {} +unsafe impl glib::subclass::prelude::IsSubclassable for TestParent where + ::Type: glib::prelude::IsA +{ +} impl Default for TestParent { fn default() -> Self { diff --git a/glib/tests/subclass_compiletest/05-no-auto-send-sync-with-non-send-sync-parent.stderr b/glib/tests/subclass_compiletest/05-no-auto-send-sync-with-non-send-sync-parent.stderr index 7a127ed6462b..b51e1bfed782 100644 --- a/glib/tests/subclass_compiletest/05-no-auto-send-sync-with-non-send-sync-parent.stderr +++ b/glib/tests/subclass_compiletest/05-no-auto-send-sync-with-non-send-sync-parent.stderr @@ -1,7 +1,7 @@ error[E0277]: `RefCell` cannot be shared between threads safely - --> tests/subclass_compiletest/05-no-auto-send-sync-with-non-send-sync-parent.rs:66:11 + --> tests/subclass_compiletest/05-no-auto-send-sync-with-non-send-sync-parent.rs:73:11 | -66 | check(&obj); +73 | check(&obj); | ----- ^^^^ `RefCell` cannot be shared between threads safely | | | required by a bound introduced by this call @@ -21,12 +21,12 @@ note: required because it appears within the type `TestParent` | ^^^^^^^^^^ = note: required for `TypedObjectRef` to implement `Send` note: required because it appears within the type `TestObject` - --> tests/subclass_compiletest/05-no-auto-send-sync-with-non-send-sync-parent.rs:53:16 + --> tests/subclass_compiletest/05-no-auto-send-sync-with-non-send-sync-parent.rs:60:16 | -53 | pub struct TestObject(ObjectSubclass) @extends TestParent; +60 | pub struct TestObject(ObjectSubclass) @extends TestParent; | ^^^^^^^^^^ note: required by a bound in `main::check` - --> tests/subclass_compiletest/05-no-auto-send-sync-with-non-send-sync-parent.rs:63:17 + --> tests/subclass_compiletest/05-no-auto-send-sync-with-non-send-sync-parent.rs:70:17 | -63 | fn check(_obj: &T) {} +70 | fn check(_obj: &T) {} | ^^^^ required by this bound in `check` diff --git a/glib/tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs b/glib/tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs index e8e9338efa61..566b8c834907 100644 --- a/glib/tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs +++ b/glib/tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs @@ -7,10 +7,14 @@ glib::wrapper! { } } -pub trait InitiallyUnownedImpl: glib::subclass::prelude::ObjectImpl {} +pub trait InitiallyUnownedImpl: glib::subclass::prelude::ObjectImpl +where + ::Type: glib::prelude::IsA, +{ +} -unsafe impl glib::subclass::prelude::IsSubclassable - for InitiallyUnowned +unsafe impl glib::subclass::prelude::IsSubclassable for InitiallyUnowned where + ::Type: glib::prelude::IsA { } diff --git a/glib/tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.stderr b/glib/tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.stderr index 7a61c3da10c8..78e094d48c35 100644 --- a/glib/tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.stderr +++ b/glib/tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.stderr @@ -1,7 +1,7 @@ error[E0277]: `*mut c_void` cannot be sent between threads safely - --> tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs:50:11 + --> tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs:54:11 | -50 | check(&obj); +54 | check(&obj); | ----- ^^^^ `*mut c_void` cannot be sent between threads safely | | | required by a bound introduced by this call @@ -15,20 +15,20 @@ note: required because it appears within the type `InitiallyUnowned` | ^^^^^^^^^^^^^^^^ = note: required for `TypedObjectRef` to implement `Send` note: required because it appears within the type `TestObject` - --> tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs:37:16 + --> tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs:41:16 | -37 | pub struct TestObject(ObjectSubclass) @extends InitiallyUnowned; +41 | pub struct TestObject(ObjectSubclass) @extends InitiallyUnowned; | ^^^^^^^^^^ note: required by a bound in `main::check` - --> tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs:47:17 + --> tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs:51:17 | -47 | fn check(_obj: &T) {} +51 | fn check(_obj: &T) {} | ^^^^ required by this bound in `check` error[E0277]: `*mut c_void` cannot be shared between threads safely - --> tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs:50:11 + --> tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs:54:11 | -50 | check(&obj); +54 | check(&obj); | ----- ^^^^ `*mut c_void` cannot be shared between threads safely | | | required by a bound introduced by this call @@ -42,12 +42,12 @@ note: required because it appears within the type `InitiallyUnowned` | ^^^^^^^^^^^^^^^^ = note: required for `TypedObjectRef` to implement `Send` note: required because it appears within the type `TestObject` - --> tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs:37:16 + --> tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs:41:16 | -37 | pub struct TestObject(ObjectSubclass) @extends InitiallyUnowned; +41 | pub struct TestObject(ObjectSubclass) @extends InitiallyUnowned; | ^^^^^^^^^^ note: required by a bound in `main::check` - --> tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs:47:17 + --> tests/subclass_compiletest/06-no-auto-send-sync-with-non-send-sync-ffi-parent.rs:51:17 | -47 | fn check(_obj: &T) {} +51 | fn check(_obj: &T) {} | ^^^^ required by this bound in `check`