Skip to content

Commit ef7ae2e

Browse files
authored
Merge pull request #153 from Rust-for-Linux/dev/symbol-name
Optimize symbol name length of `InitClosure`
2 parents 81cb317 + c3a3f1e commit ef7ae2e

2 files changed

Lines changed: 32 additions & 32 deletions

File tree

src/__internal.rs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -58,36 +58,6 @@ impl PhantomInvariantLifetime<'_> {
5858
}
5959
}
6060

61-
/// Module-internal type implementing `PinInit` and `Init`.
62-
///
63-
/// It is unsafe to create this type, since the closure needs to fulfill the same safety
64-
/// requirement as the `__pinned_init`/`__init` functions.
65-
pub(crate) struct InitClosure<F, T: ?Sized, E>(pub(crate) F, pub(crate) PhantomInvariant<(E, T)>);
66-
67-
// SAFETY: While constructing the `InitClosure`, the user promised that it upholds the
68-
// `__init` invariants.
69-
unsafe impl<T: ?Sized, F, E> Init<T, E> for InitClosure<F, T, E>
70-
where
71-
F: FnOnce(*mut T) -> Result<(), E>,
72-
{
73-
#[inline]
74-
unsafe fn __init(self, slot: *mut T) -> Result<(), E> {
75-
(self.0)(slot)
76-
}
77-
}
78-
79-
// SAFETY: While constructing the `InitClosure`, the user promised that it upholds the
80-
// `__pinned_init` invariants.
81-
unsafe impl<T: ?Sized, F, E> PinInit<T, E> for InitClosure<F, T, E>
82-
where
83-
F: FnOnce(*mut T) -> Result<(), E>,
84-
{
85-
#[inline]
86-
unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E> {
87-
(self.0)(slot)
88-
}
89-
}
90-
9161
/// Token type to signify successful initialization.
9262
///
9363
/// Can only be constructed via the unsafe [`Self::new`] function. The initializer macros use this

src/lib.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,36 @@ where
10921092
}
10931093
}
10941094

1095+
/// Implement `PinInit` and `Init` for closures.
1096+
///
1097+
/// It is unsafe to create this type, since the closure needs to fulfill the same safety
1098+
/// requirement as the `__pinned_init`/`__init` functions.
1099+
struct InitClosure<F, T: ?Sized>(F, __internal::PhantomInvariant<T>);
1100+
1101+
// SAFETY: While constructing the `InitClosure`, the user promised that it upholds the
1102+
// `__init` invariants.
1103+
unsafe impl<T: ?Sized, F, E> Init<T, E> for InitClosure<F, T>
1104+
where
1105+
F: FnOnce(*mut T) -> Result<(), E>,
1106+
{
1107+
#[inline]
1108+
unsafe fn __init(self, slot: *mut T) -> Result<(), E> {
1109+
(self.0)(slot)
1110+
}
1111+
}
1112+
1113+
// SAFETY: While constructing the `InitClosure`, the user promised that it upholds the
1114+
// `__pinned_init` invariants.
1115+
unsafe impl<T: ?Sized, F, E> PinInit<T, E> for InitClosure<F, T>
1116+
where
1117+
F: FnOnce(*mut T) -> Result<(), E>,
1118+
{
1119+
#[inline]
1120+
unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E> {
1121+
(self.0)(slot)
1122+
}
1123+
}
1124+
10951125
/// Creates a new [`PinInit<T, E>`] from the given closure.
10961126
///
10971127
/// # Safety
@@ -1108,7 +1138,7 @@ where
11081138
pub const unsafe fn pin_init_from_closure<T: ?Sized, E>(
11091139
f: impl FnOnce(*mut T) -> Result<(), E>,
11101140
) -> impl PinInit<T, E> {
1111-
__internal::InitClosure(f, __internal::PhantomInvariant::new())
1141+
InitClosure(f, __internal::PhantomInvariant::new())
11121142
}
11131143

11141144
/// Creates a new [`Init<T, E>`] from the given closure.
@@ -1127,7 +1157,7 @@ pub const unsafe fn pin_init_from_closure<T: ?Sized, E>(
11271157
pub const unsafe fn init_from_closure<T: ?Sized, E>(
11281158
f: impl FnOnce(*mut T) -> Result<(), E>,
11291159
) -> impl Init<T, E> {
1130-
__internal::InitClosure(f, __internal::PhantomInvariant::new())
1160+
InitClosure(f, __internal::PhantomInvariant::new())
11311161
}
11321162

11331163
/// Changes the to be initialized type.

0 commit comments

Comments
 (0)