Skip to content

Commit eadff1a

Browse files
authored
Merge pull request #569 from ranfdev/shared_wrapper_no_phantom
remove problematic phantom in glib_shared_wrapper
2 parents 575d3ef + 8d309f7 commit eadff1a

File tree

3 files changed

+22
-35
lines changed

3 files changed

+22
-35
lines changed

glib/src/boxed.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,13 @@ macro_rules! glib_boxed_wrapper {
3333
#[repr(transparent)]
3434
$visibility struct $name $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? {
3535
inner: $crate::boxed::Boxed<$ffi_name, Self>,
36-
phantom: std::marker::PhantomData<($($($generic),+)?)>,
3736
}
3837

3938
impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? std::clone::Clone for $name $(<$($generic),+>)? {
4039
#[inline]
4140
fn clone(&self) -> Self {
4241
Self {
4342
inner: std::clone::Clone::clone(&self.inner),
44-
phantom: std::marker::PhantomData,
4543
}
4644
}
4745
}
@@ -145,7 +143,6 @@ macro_rules! glib_boxed_wrapper {
145143
unsafe fn from_glib_none(ptr: *mut $ffi_name) -> Self {
146144
Self {
147145
inner: $crate::translate::from_glib_none(ptr),
148-
phantom: std::marker::PhantomData,
149146
}
150147
}
151148
}
@@ -156,7 +153,6 @@ macro_rules! glib_boxed_wrapper {
156153
unsafe fn from_glib_none(ptr: *const $ffi_name) -> Self {
157154
Self {
158155
inner: $crate::translate::from_glib_none(ptr),
159-
phantom: std::marker::PhantomData,
160156
}
161157
}
162158
}
@@ -167,7 +163,6 @@ macro_rules! glib_boxed_wrapper {
167163
unsafe fn from_glib_full(ptr: *mut $ffi_name) -> Self {
168164
Self {
169165
inner: $crate::translate::from_glib_full(ptr),
170-
phantom: std::marker::PhantomData,
171166
}
172167
}
173168
}
@@ -178,7 +173,6 @@ macro_rules! glib_boxed_wrapper {
178173
unsafe fn from_glib_full(ptr: *const $ffi_name) -> Self {
179174
Self {
180175
inner: $crate::translate::from_glib_full(ptr),
181-
phantom: std::marker::PhantomData,
182176
}
183177
}
184178
}
@@ -190,7 +184,6 @@ macro_rules! glib_boxed_wrapper {
190184
$crate::translate::Borrowed::new(
191185
Self {
192186
inner: $crate::translate::from_glib_borrow::<_, $crate::boxed::Boxed<_, _>>(ptr).into_inner(),
193-
phantom: std::marker::PhantomData,
194187
}
195188
)
196189
}

glib/src/boxed_inline.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ macro_rules! glib_boxed_inline_wrapper {
1313
#[repr(transparent)]
1414
$visibility struct $name $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? {
1515
pub(crate) inner: $ffi_name,
16-
pub(crate) phantom: std::marker::PhantomData<($($($generic),+)?)>,
16+
$(pub(crate) phantom: std::marker::PhantomData<$($generic),+>,)?
1717
}
1818

1919
impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? std::clone::Clone for $name $(<$($generic),+>)? {
2020
#[inline]
2121
fn clone(&self) -> Self {
2222
Self {
2323
inner: std::clone::Clone::clone(&self.inner),
24-
phantom: std::marker::PhantomData,
24+
$(phantom: std::marker::PhantomData::<$($generic),+>)?
2525
}
2626
}
2727
}
@@ -45,15 +45,15 @@ macro_rules! glib_boxed_inline_wrapper {
4545
#[repr(transparent)]
4646
$visibility struct $name $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? {
4747
pub(crate) inner: $ffi_name,
48-
pub(crate) phantom: std::marker::PhantomData<($($($generic),+)?)>,
48+
$(pub(crate) phantom: std::marker::PhantomData<$($generic),+>,)?
4949
}
5050

5151
impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? std::clone::Clone for $name $(<$($generic),+>)? {
5252
#[inline]
5353
fn clone(&self) -> Self {
5454
Self {
5555
inner: std::clone::Clone::clone(&self.inner),
56-
phantom: std::marker::PhantomData,
56+
$(phantom: std::marker::PhantomData::<$($generic),+>)?
5757
}
5858
}
5959
}
@@ -76,7 +76,7 @@ macro_rules! glib_boxed_inline_wrapper {
7676
#[repr(transparent)]
7777
$visibility struct $name $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? {
7878
pub(crate) inner: $ffi_name,
79-
pub(crate) phantom: std::marker::PhantomData<($($($generic),+)?)>,
79+
$(pub(crate) phantom: std::marker::PhantomData<$($generic),+>,)?
8080
}
8181

8282
impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? std::clone::Clone for $name $(<$($generic),+>)? {
@@ -116,7 +116,7 @@ macro_rules! glib_boxed_inline_wrapper {
116116
#[repr(transparent)]
117117
$visibility struct $name $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? {
118118
pub(crate) inner: $ffi_name,
119-
pub(crate) phantom: std::marker::PhantomData<($($($generic),+)?)>,
119+
$(pub(crate) phantom: std::marker::PhantomData<$($generic),+>,)?
120120
}
121121

122122
impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? std::clone::Clone for $name $(<$($generic),+>)? {
@@ -164,7 +164,7 @@ macro_rules! glib_boxed_inline_wrapper {
164164
init(v.as_mut_ptr());
165165
Self {
166166
inner: v.assume_init(),
167-
phantom: std::marker::PhantomData,
167+
$(phantom: std::marker::PhantomData::<$($generic),+>)?
168168
}
169169
}
170170
}
@@ -174,13 +174,13 @@ macro_rules! glib_boxed_inline_wrapper {
174174
unsafe fn unsafe_from(t: $ffi_name) -> Self {
175175
Self {
176176
inner: t,
177-
phantom: std::marker::PhantomData,
177+
$(phantom: std::marker::PhantomData::<$($generic),+>)?
178178
}
179179
}
180180
}
181181

182182
#[doc(hidden)]
183-
impl<'a $(, $($generic $(: $bound $(+ $bound2)*)?),+)?> $crate::translate::ToGlibPtr<'a, *const $ffi_name> for $name $(<$($generic),+>)? {
183+
impl<'a $(, $($generic: 'a + $($bound $(+ $bound2)*)?),+)?> $crate::translate::ToGlibPtr<'a, *const $ffi_name> for $name $(<$($generic),+>)? {
184184
type Storage = &'a Self;
185185

186186
#[inline]
@@ -198,7 +198,7 @@ macro_rules! glib_boxed_inline_wrapper {
198198
}
199199

200200
#[doc(hidden)]
201-
impl<'a $(, $($generic $(: $bound $(+ $bound2)*)?),+)?> $crate::translate::ToGlibPtrMut<'a, *mut $ffi_name> for $name $(<$($generic),+>)? {
201+
impl<'a $(, $($generic: 'a + $($bound $(+ $bound2)*)?),+)?> $crate::translate::ToGlibPtrMut<'a, *mut $ffi_name> for $name $(<$($generic),+>)? {
202202
type Storage = &'a mut Self;
203203

204204
#[inline]
@@ -209,7 +209,7 @@ macro_rules! glib_boxed_inline_wrapper {
209209
}
210210

211211
#[doc(hidden)]
212-
impl<'a $(, $($generic $(: $bound $(+ $bound2)*)?),+)?> $crate::translate::ToGlibContainerFromSlice<'a, *mut *const $ffi_name> for $name $(<$($generic),+>)? {
212+
impl<'a $(, $($generic: 'a + $($bound $(+ $bound2)*)?),+)?> $crate::translate::ToGlibContainerFromSlice<'a, *mut *const $ffi_name> for $name $(<$($generic),+>)? {
213213
type Storage = Option<Vec<*const $ffi_name>>;
214214

215215
fn to_glib_none_from_slice(t: &'a [Self]) -> (*mut *const $ffi_name, Self::Storage) {
@@ -247,7 +247,7 @@ macro_rules! glib_boxed_inline_wrapper {
247247
}
248248

249249
#[doc(hidden)]
250-
impl<'a $(, $($generic $(: $bound $(+ $bound2)*)?),+)?> $crate::translate::ToGlibContainerFromSlice<'a, *const *const $ffi_name> for $name $(<$($generic),+>)? {
250+
impl<'a $(, $($generic: 'a + $($bound $(+ $bound2)*)?),+)?> $crate::translate::ToGlibContainerFromSlice<'a, *const *const $ffi_name> for $name $(<$($generic),+>)? {
251251
type Storage = Option<Vec<*const $ffi_name>>;
252252

253253
fn to_glib_none_from_slice(t: &'a [Self]) -> (*const *const $ffi_name, Self::Storage) {
@@ -267,7 +267,7 @@ macro_rules! glib_boxed_inline_wrapper {
267267
}
268268

269269
#[doc(hidden)]
270-
impl<'a $(, $($generic $(: $bound $(+ $bound2)*)?),+)?> $crate::translate::ToGlibContainerFromSlice<'a, *mut $ffi_name> for $name $(<$($generic),+>)? {
270+
impl<'a $(, $($generic: 'a + $($bound $(+ $bound2)*)?),+)?> $crate::translate::ToGlibContainerFromSlice<'a, *mut $ffi_name> for $name $(<$($generic),+>)? {
271271
type Storage = Option<&'a [Self]>;
272272

273273
fn to_glib_none_from_slice(t: &'a [Self]) -> (*mut $ffi_name, Self::Storage) {
@@ -298,7 +298,7 @@ macro_rules! glib_boxed_inline_wrapper {
298298
}
299299

300300
#[doc(hidden)]
301-
impl<'a $(, $($generic $(: $bound $(+ $bound2)*)?),+)?> $crate::translate::ToGlibContainerFromSlice<'a, *const $ffi_name> for $name $(<$($generic),+>)? {
301+
impl<'a $(, $($generic: 'a $($bound $(+ $bound2)*)?),+)?> $crate::translate::ToGlibContainerFromSlice<'a, *const $ffi_name> for $name $(<$($generic),+>)? {
302302
type Storage = Option<&'a [Self]>;
303303

304304
fn to_glib_none_from_slice(t: &'a [Self]) -> (*const $ffi_name, Self::Storage) {
@@ -372,7 +372,7 @@ macro_rules! glib_boxed_inline_wrapper {
372372

373373
$crate::translate::Borrowed::new(Self {
374374
inner: std::ptr::read(ptr),
375-
phantom: std::marker::PhantomData,
375+
$(phantom: std::marker::PhantomData::<$($generic),+>)?
376376
})
377377
}
378378
}
@@ -427,7 +427,7 @@ macro_rules! glib_boxed_inline_wrapper {
427427

428428
let mut res = Vec::with_capacity(num);
429429
for i in 0..num {
430-
res.push(std::ptr::read(ptr.add(i) as *const $name));
430+
res.push(std::ptr::read(ptr.add(i) as *const $name $(<$($generic),+>)?));
431431
}
432432
$crate::ffi::g_free(ptr as *mut _);
433433
res
@@ -495,26 +495,26 @@ macro_rules! glib_boxed_inline_wrapper {
495495
}
496496

497497
#[doc(hidden)]
498-
impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? $crate::value::ValueType for $name $(<$($generic),+>)? {
498+
impl$(<$($generic: 'static + $($bound $(+ $bound2)*)?),+>)? $crate::value::ValueType for $name $(<$($generic),+>)? {
499499
type Type = Self;
500500
}
501501

502502
#[doc(hidden)]
503-
unsafe impl<'a> $crate::value::FromValue<'a> for $name $(<$($generic),+>)? {
503+
unsafe impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? $crate::value::FromValue<'_> for $name $(<$($generic),+>)? {
504504
type Checker = $crate::value::GenericValueTypeOrNoneChecker<Self>;
505505

506-
unsafe fn from_value(value: &'a $crate::Value) -> Self {
506+
unsafe fn from_value(value: &'_ $crate::Value) -> Self {
507507
let ptr = $crate::gobject_ffi::g_value_get_boxed($crate::translate::ToGlibPtr::to_glib_none(value).0);
508508
assert!(!ptr.is_null());
509509
<Self as $crate::translate::FromGlibPtrNone<*const $ffi_name>>::from_glib_none(ptr as *const $ffi_name)
510510
}
511511
}
512512

513513
#[doc(hidden)]
514-
unsafe impl<'a> $crate::value::FromValue<'a> for &'a $name $(<$($generic),+>)? {
514+
unsafe impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? $crate::value::FromValue<'_> for &'_ $name $(<$($generic),+>)? {
515515
type Checker = $crate::value::GenericValueTypeOrNoneChecker<Self>;
516516

517-
unsafe fn from_value(value: &'a $crate::Value) -> Self {
517+
unsafe fn from_value(value: &'_ $crate::Value) -> Self {
518518
let ptr = $crate::gobject_ffi::g_value_get_boxed($crate::translate::ToGlibPtr::to_glib_none(value).0);
519519
assert!(!ptr.is_null());
520520
&*(ptr as *const $ffi_name as *const $name $(<$($generic),+>)?)
@@ -540,7 +540,7 @@ macro_rules! glib_boxed_inline_wrapper {
540540
}
541541

542542
#[doc(hidden)]
543-
impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? $crate::value::ToValueOptional for $name $(<$($generic),+>)? {
543+
impl $(<$($generic: 'static + $($bound $(+ $bound2)*)?),+>)? $crate::value::ToValueOptional for $name $(<$($generic),+>)? {
544544
fn to_value_optional(s: Option<&Self>) -> $crate::Value {
545545
let mut value = $crate::Value::for_value_type::<Self>();
546546
unsafe {

glib/src/shared.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,13 @@ macro_rules! glib_shared_wrapper {
3131
#[repr(transparent)]
3232
$visibility struct $name $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? {
3333
inner: $crate::shared::Shared<$ffi_name, Self>,
34-
phantom: std::marker::PhantomData<($($($generic),+)?)>,
3534
}
3635

3736
impl $(<$($generic $(: $bound $(+ $bound2)*)?),+>)? std::clone::Clone for $name $(<$($generic),+>)? {
3837
#[inline]
3938
fn clone(&self) -> Self {
4039
Self {
4140
inner: std::clone::Clone::clone(&self.inner),
42-
phantom: std::marker::PhantomData,
4341
}
4442
}
4543
}
@@ -146,7 +144,6 @@ macro_rules! glib_shared_wrapper {
146144
unsafe fn from_glib_none(ptr: *mut $ffi_name) -> Self {
147145
Self {
148146
inner: $crate::translate::from_glib_none(ptr),
149-
phantom: std::marker::PhantomData,
150147
}
151148
}
152149
}
@@ -157,7 +154,6 @@ macro_rules! glib_shared_wrapper {
157154
unsafe fn from_glib_none(ptr: *const $ffi_name) -> Self {
158155
Self {
159156
inner: $crate::translate::from_glib_none(ptr),
160-
phantom: std::marker::PhantomData,
161157
}
162158
}
163159
}
@@ -168,7 +164,6 @@ macro_rules! glib_shared_wrapper {
168164
unsafe fn from_glib_full(ptr: *mut $ffi_name) -> Self {
169165
Self {
170166
inner: $crate::translate::from_glib_full(ptr),
171-
phantom: std::marker::PhantomData,
172167
}
173168
}
174169
}
@@ -180,7 +175,6 @@ macro_rules! glib_shared_wrapper {
180175
$crate::translate::Borrowed::new(
181176
Self {
182177
inner: $crate::translate::from_glib_borrow::<_, $crate::shared::Shared<_, _>>(ptr).into_inner(),
183-
phantom: std::marker::PhantomData,
184178
}
185179
)
186180
}

0 commit comments

Comments
 (0)