try_specialize/
lifetime_free.rs

1#![expect(
2    clippy::undocumented_unsafe_blocks,
3    reason = "safety comment for all unsafe implementation specified for the `LifetimeFree` trait"
4)]
5
6/// A marker trait for types that do not contain any lifetime parameters.
7///
8/// Such types are safe to specialize from non-static type parameters if their
9/// types are equal. This trait is used to determine safe specialization methods
10/// in [`TrySpecialize`] trait and safe constructor for [`Specialization`]. The
11/// `LifetimeFree` bound is stricter than `'static` bound. All `LifetimeFree`
12/// types are also `'static`, but the reverse is not true.
13///
14/// This trait is **not** automatically generated for all lifetime free types.
15/// Use [`Specialization::rev`] to specialize from a `LifetimeFree`
16/// type to an unconstrained type.
17///
18/// # Safety
19///
20/// When implementing this trait for a `struct`, `enum`, or `union` type, you
21/// must ensure that the type does **not** contain any lifetime parameters.
22/// When implementing this trait for a type alias, you must ensure that the
23/// underlying `struct`, `enum`, or `union` type does **not** contain any
24/// lifetime parameters.
25///
26/// Note, however, that the use of `'static` values in type fields is allowed.
27/// So:
28/// - `struct First<'a, T>( /* ... */ )` is not a lifetime free type.
29/// - `type Second<T> = First<'static, T>` is not a lifetime free type.
30/// - `type Third = Second<u32>` is not a lifetime free type, because the
31///   underlying type is still `First<'static, T>`.
32///
33/// Whereas for `T: LifetimeFree` the
34/// `struct Fourth<T>(&'static str, Cow<'static, T>)` and its aliases can be
35/// considered as lifetime free types, since the underlying struct has no
36/// lifetime parameters. It only has fields with lifetimes, which is allowed.
37/// Therefore, it is safe to
38/// `impl LifetimeFree<T> for Fourth<T> where T: LifetimeFree {}`.
39///
40/// Implementing this trait for types which uses lifetimes may result in
41/// *[undefined behavior]*.
42///
43/// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
44///
45/// # Examples
46///
47/// ```rust
48/// use try_specialize::LifetimeFree;
49///
50/// struct MarkerType;
51/// struct U32Pair(u32, u32);
52/// struct CustomVec<T> {
53///     ptr: *mut T,
54///     cap: usize,
55///     len: usize,
56/// }
57/// struct Data {
58///     // ...
59/// }
60/// enum Either<T1, T2> {
61///     Left(T1),
62///     Right(T2),
63/// }
64///
65/// unsafe impl LifetimeFree for MarkerType {}
66/// unsafe impl LifetimeFree for U32Pair {}
67/// unsafe impl<T: LifetimeFree> LifetimeFree for CustomVec<T> {}
68/// unsafe impl LifetimeFree for Data {}
69/// unsafe impl<T1, T2> LifetimeFree for Either<T1, T2>
70/// where
71///     T1: LifetimeFree,
72///     T2: LifetimeFree,
73/// {
74/// }
75/// ```
76///
77/// Safe examples with `'static` used in fields:
78/// ```rust
79/// use std::borrow::Cow;
80///
81/// use try_specialize::LifetimeFree;
82///
83/// // Original type must not implement `LifetimeFree` because it has lifetime parameters.
84/// // However its wrapper without lifetime parameters can implement `LifetimeFree`.
85/// struct WithLifetimes<'a, 'b, T, U>(&'a str, &'b [u8], T, U);
86///
87/// struct StaticStrWrapper(pub &'static str);
88/// struct StaticRefWrapper<T: LifetimeFree>(pub &'static T);
89/// struct StaticCowWrapper<T: LifetimeFree + ToOwned>(pub Cow<'static, T>);
90/// struct WithLifetimesWrapper<T, U>(pub WithLifetimes<'static, 'static, T, U>);
91///
92/// unsafe impl LifetimeFree for StaticStrWrapper {}
93/// unsafe impl<T: LifetimeFree> LifetimeFree for StaticRefWrapper<T> {}
94/// unsafe impl<T: LifetimeFree + ToOwned> LifetimeFree for StaticCowWrapper<T> {}
95/// unsafe impl<T: LifetimeFree, U: LifetimeFree> LifetimeFree for WithLifetimesWrapper<T, U> {}
96/// ```
97///
98/// Invalid usage examples with explicit or implicit `'static` parameters:
99/// ```rust,compile_fail
100/// # macro_rules UB! { ( $( $tt:tt )* ) => { $( $tt )* } };
101/// #
102/// use std::borrow::Cow;
103///
104/// use try_specialize::LifetimeFree;
105///
106/// struct WithLifetimes<'a, 'b, T, U>(&'a str, &'b [u8], T, U);
107///
108/// type StaticStrAlias = &'static str;
109/// type StaticRefAlias<T> = &'static T;
110/// type StaticCowAlias<T> = Cow<'static, T>;
111/// type WithLifetimesAlias<T, U> = WithLifetimes<'static, 'static, T, U>;
112///
113/// // Do not implement use it!
114/// // Any implementation below may result to undefined behavior!
115/// UB!{ unsafe impl LifetimeFree for StaticStrAlias {} }
116/// UB!{ unsafe impl<T: LifetimeFree> LifetimeFree for StaticRefAlias<T> {} }
117/// UB!{ unsafe impl<T: LifetimeFree> LifetimeFree for StaticCowAlias<T> {} }
118/// UB!{
119///     unsafe impl<T: LifetimeFree, U: LifetimeFree> LifetimeFree
120///         for WithLifetimes<'static, 'static, T, U> {}
121/// }
122/// UB!{
123///     unsafe impl<T: LifetimeFree, U: LifetimeFree> LifetimeFree
124///         for WithLifetimesAlias<T, U> {}
125/// }
126/// ```
127///
128/// [`TrySpecialize`]: crate::TrySpecialize
129/// [`Specialization`]: crate::Specialization
130/// [`Specialization::rev`]: crate::Specialization::rev
131/// [`Specialization::map`]: crate::Specialization::map
132pub unsafe trait LifetimeFree: 'static {}
133
134unsafe impl LifetimeFree for bool {}
135unsafe impl LifetimeFree for char {}
136unsafe impl LifetimeFree for u8 {}
137unsafe impl LifetimeFree for u16 {}
138unsafe impl LifetimeFree for u32 {}
139unsafe impl LifetimeFree for u64 {}
140unsafe impl LifetimeFree for u128 {}
141unsafe impl LifetimeFree for usize {}
142unsafe impl LifetimeFree for i8 {}
143unsafe impl LifetimeFree for i16 {}
144unsafe impl LifetimeFree for i32 {}
145unsafe impl LifetimeFree for i64 {}
146unsafe impl LifetimeFree for i128 {}
147unsafe impl LifetimeFree for isize {}
148unsafe impl LifetimeFree for f32 {}
149unsafe impl LifetimeFree for f64 {}
150
151unsafe impl LifetimeFree for ::core::num::NonZeroU8 {}
152unsafe impl LifetimeFree for ::core::num::NonZeroU16 {}
153unsafe impl LifetimeFree for ::core::num::NonZeroU32 {}
154unsafe impl LifetimeFree for ::core::num::NonZeroU64 {}
155unsafe impl LifetimeFree for ::core::num::NonZeroU128 {}
156unsafe impl LifetimeFree for ::core::num::NonZeroUsize {}
157unsafe impl LifetimeFree for ::core::num::NonZeroI8 {}
158unsafe impl LifetimeFree for ::core::num::NonZeroI16 {}
159unsafe impl LifetimeFree for ::core::num::NonZeroI32 {}
160unsafe impl LifetimeFree for ::core::num::NonZeroI64 {}
161unsafe impl LifetimeFree for ::core::num::NonZeroI128 {}
162unsafe impl LifetimeFree for ::core::num::NonZeroIsize {}
163
164#[cfg(target_has_atomic = "8")]
165unsafe impl LifetimeFree for core::sync::atomic::AtomicBool {}
166#[cfg(target_has_atomic = "8")]
167unsafe impl LifetimeFree for core::sync::atomic::AtomicI8 {}
168#[cfg(target_has_atomic = "16")]
169unsafe impl LifetimeFree for core::sync::atomic::AtomicI16 {}
170#[cfg(target_has_atomic = "32")]
171unsafe impl LifetimeFree for core::sync::atomic::AtomicI32 {}
172#[cfg(target_has_atomic = "64")]
173unsafe impl LifetimeFree for core::sync::atomic::AtomicI64 {}
174#[cfg(target_has_atomic = "ptr")]
175unsafe impl LifetimeFree for core::sync::atomic::AtomicIsize {}
176#[cfg(target_has_atomic = "8")]
177unsafe impl LifetimeFree for core::sync::atomic::AtomicU8 {}
178#[cfg(target_has_atomic = "16")]
179unsafe impl LifetimeFree for core::sync::atomic::AtomicU16 {}
180#[cfg(target_has_atomic = "32")]
181unsafe impl LifetimeFree for core::sync::atomic::AtomicU32 {}
182#[cfg(target_has_atomic = "64")]
183unsafe impl LifetimeFree for core::sync::atomic::AtomicU64 {}
184#[cfg(target_has_atomic = "ptr")]
185unsafe impl LifetimeFree for core::sync::atomic::AtomicUsize {}
186unsafe impl LifetimeFree for core::sync::atomic::Ordering {}
187
188unsafe impl<T> LifetimeFree for core::num::Saturating<T> where T: LifetimeFree {}
189unsafe impl<T> LifetimeFree for core::num::Wrapping<T> where T: LifetimeFree {}
190
191unsafe impl<T> LifetimeFree for Option<T> where T: LifetimeFree {}
192unsafe impl<T, E> LifetimeFree for Result<T, E>
193where
194    T: LifetimeFree,
195    E: LifetimeFree,
196{
197}
198
199unsafe impl LifetimeFree for str {}
200unsafe impl LifetimeFree for core::ffi::CStr {}
201unsafe impl<T> LifetimeFree for [T] where T: LifetimeFree {}
202
203unsafe impl<T, const N: usize> LifetimeFree for [T; N] where T: LifetimeFree {}
204
205unsafe impl<T> LifetimeFree for *const T where T: ?Sized + LifetimeFree {}
206unsafe impl<T> LifetimeFree for *mut T where T: ?Sized + LifetimeFree {}
207unsafe impl<T> LifetimeFree for core::ptr::NonNull<T> where T: ?Sized + LifetimeFree {}
208
209unsafe impl LifetimeFree for core::convert::Infallible {}
210unsafe impl LifetimeFree for core::marker::PhantomPinned {}
211unsafe impl<T> LifetimeFree for core::marker::PhantomData<T> where T: ?Sized + LifetimeFree {}
212unsafe impl<T> LifetimeFree for core::cell::Cell<T> where T: ?Sized + LifetimeFree {}
213unsafe impl<T> LifetimeFree for core::cell::RefCell<T> where T: ?Sized + LifetimeFree {}
214unsafe impl<T> LifetimeFree for core::cell::OnceCell<T> where T: LifetimeFree {}
215unsafe impl<T> LifetimeFree for core::cell::UnsafeCell<T> where T: LifetimeFree {}
216unsafe impl<T, F> LifetimeFree for core::cell::LazyCell<T, F>
217where
218    T: LifetimeFree,
219    F: LifetimeFree,
220{
221}
222
223unsafe impl LifetimeFree for core::time::Duration {}
224unsafe impl LifetimeFree for core::net::IpAddr {}
225unsafe impl LifetimeFree for core::net::Ipv4Addr {}
226unsafe impl LifetimeFree for core::net::Ipv6Addr {}
227unsafe impl LifetimeFree for core::net::SocketAddr {}
228unsafe impl LifetimeFree for core::net::SocketAddrV4 {}
229unsafe impl LifetimeFree for core::net::SocketAddrV6 {}
230unsafe impl LifetimeFree for core::cmp::Ordering {}
231unsafe impl LifetimeFree for core::ops::RangeFull {}
232
233unsafe impl<T> LifetimeFree for core::pin::Pin<T> where T: LifetimeFree {}
234unsafe impl<T> LifetimeFree for core::task::Poll<T> where T: LifetimeFree {}
235unsafe impl<T> LifetimeFree for core::ops::Bound<T> where T: LifetimeFree {}
236unsafe impl<T> LifetimeFree for core::ops::Range<T> where T: LifetimeFree {}
237unsafe impl<T> LifetimeFree for core::ops::RangeFrom<T> where T: LifetimeFree {}
238unsafe impl<T> LifetimeFree for core::ops::RangeInclusive<T> where T: LifetimeFree {}
239unsafe impl<T> LifetimeFree for core::ops::RangeTo<T> where T: LifetimeFree {}
240unsafe impl<T> LifetimeFree for core::ops::RangeToInclusive<T> where T: LifetimeFree {}
241unsafe impl<B, C> LifetimeFree for core::ops::ControlFlow<B, C>
242where
243    B: LifetimeFree,
244    C: LifetimeFree,
245{
246}
247
248unsafe impl LifetimeFree for core::alloc::Layout {}
249unsafe impl LifetimeFree for core::alloc::LayoutError {}
250unsafe impl LifetimeFree for core::any::TypeId {}
251unsafe impl<T, const N: usize> LifetimeFree for core::array::IntoIter<T, N> where T: LifetimeFree {}
252unsafe impl LifetimeFree for core::array::TryFromSliceError {}
253unsafe impl LifetimeFree for core::ascii::EscapeDefault {}
254unsafe impl LifetimeFree for core::cell::BorrowError {}
255unsafe impl LifetimeFree for core::cell::BorrowMutError {}
256unsafe impl LifetimeFree for core::char::CharTryFromError {}
257unsafe impl<I> LifetimeFree for core::char::DecodeUtf16<I> where
258    I: LifetimeFree + Iterator<Item = u16>
259{
260}
261unsafe impl LifetimeFree for core::char::DecodeUtf16Error {}
262unsafe impl LifetimeFree for core::char::EscapeDebug {}
263unsafe impl LifetimeFree for core::char::EscapeDefault {}
264unsafe impl LifetimeFree for core::char::EscapeUnicode {}
265unsafe impl LifetimeFree for core::char::ParseCharError {}
266unsafe impl LifetimeFree for core::char::ToLowercase {}
267unsafe impl LifetimeFree for core::char::ToUppercase {}
268unsafe impl LifetimeFree for core::char::TryFromCharError {}
269unsafe impl<T> LifetimeFree for core::cmp::Reverse<T> where T: LifetimeFree {}
270
271unsafe impl LifetimeFree for core::ffi::c_void {}
272unsafe impl LifetimeFree for core::fmt::Error {}
273unsafe impl LifetimeFree for core::fmt::Alignment {}
274
275unsafe impl<T> LifetimeFree for core::future::Pending<T> where T: LifetimeFree {}
276unsafe impl<F> LifetimeFree for core::future::PollFn<F> where F: LifetimeFree {}
277unsafe impl<T> LifetimeFree for core::future::Ready<T> where T: LifetimeFree {}
278
279unsafe impl<H> LifetimeFree for core::hash::BuildHasherDefault<H> where H: LifetimeFree {}
280
281unsafe impl<A, B> LifetimeFree for core::iter::Chain<A, B>
282where
283    A: LifetimeFree,
284    B: LifetimeFree,
285{
286}
287unsafe impl<I> LifetimeFree for core::iter::Cloned<I> where I: LifetimeFree {}
288unsafe impl<I> LifetimeFree for core::iter::Copied<I> where I: LifetimeFree {}
289unsafe impl<I> LifetimeFree for core::iter::Cycle<I> where I: LifetimeFree {}
290unsafe impl<T> LifetimeFree for core::iter::Empty<T> where T: LifetimeFree {}
291unsafe impl<I> LifetimeFree for core::iter::Enumerate<I> where I: LifetimeFree {}
292unsafe impl<I, P> LifetimeFree for core::iter::Filter<I, P>
293where
294    I: LifetimeFree,
295    P: LifetimeFree,
296{
297}
298unsafe impl<I, F> LifetimeFree for core::iter::FilterMap<I, F>
299where
300    I: LifetimeFree,
301    F: LifetimeFree,
302{
303}
304unsafe impl<I, U, F> LifetimeFree for core::iter::FlatMap<I, U, F>
305where
306    I: LifetimeFree,
307    U: LifetimeFree + IntoIterator,
308    F: LifetimeFree,
309{
310}
311unsafe impl<I> LifetimeFree for core::iter::Flatten<I>
312where
313    I: LifetimeFree + Iterator,
314    <I as Iterator>::Item: IntoIterator,
315{
316}
317unsafe impl<F> LifetimeFree for core::iter::FromFn<F> where F: LifetimeFree {}
318unsafe impl<I> LifetimeFree for core::iter::Fuse<I> where I: LifetimeFree {}
319unsafe impl<I, F> LifetimeFree for core::iter::Inspect<I, F>
320where
321    I: LifetimeFree,
322    F: LifetimeFree,
323{
324}
325unsafe impl<I, F> LifetimeFree for core::iter::Map<I, F>
326where
327    I: LifetimeFree,
328    F: LifetimeFree,
329{
330}
331unsafe impl<I, F> LifetimeFree for core::iter::MapWhile<I, F>
332where
333    I: LifetimeFree,
334    F: LifetimeFree,
335{
336}
337unsafe impl<F> LifetimeFree for core::iter::OnceWith<F> where F: LifetimeFree {}
338unsafe impl<I> LifetimeFree for core::iter::Peekable<I> where I: LifetimeFree + Iterator {}
339unsafe impl<A> LifetimeFree for core::iter::Repeat<A> where A: LifetimeFree {}
340unsafe impl<F> LifetimeFree for core::iter::RepeatWith<F> where F: LifetimeFree {}
341unsafe impl<T> LifetimeFree for core::iter::Rev<T> where T: LifetimeFree {}
342unsafe impl<I, St, F> LifetimeFree for core::iter::Scan<I, St, F>
343where
344    I: LifetimeFree,
345    St: LifetimeFree,
346    F: LifetimeFree,
347{
348}
349unsafe impl<I> LifetimeFree for core::iter::Skip<I> where I: LifetimeFree {}
350unsafe impl<I, P> LifetimeFree for core::iter::SkipWhile<I, P>
351where
352    I: LifetimeFree,
353    P: LifetimeFree,
354{
355}
356unsafe impl<I> LifetimeFree for core::iter::StepBy<I> where I: LifetimeFree {}
357unsafe impl<T, F> LifetimeFree for core::iter::Successors<T, F>
358where
359    T: LifetimeFree,
360    F: LifetimeFree,
361{
362}
363unsafe impl<I> LifetimeFree for core::iter::Take<I> where I: LifetimeFree {}
364unsafe impl<I, P> LifetimeFree for core::iter::TakeWhile<I, P>
365where
366    I: LifetimeFree,
367    P: LifetimeFree,
368{
369}
370unsafe impl<A, B> LifetimeFree for core::iter::Zip<A, B>
371where
372    A: LifetimeFree,
373    B: LifetimeFree,
374{
375}
376
377unsafe impl<T> LifetimeFree for core::mem::Discriminant<T> where T: LifetimeFree {}
378unsafe impl<T> LifetimeFree for core::mem::ManuallyDrop<T> where T: LifetimeFree {}
379
380unsafe impl LifetimeFree for core::net::AddrParseError {}
381
382unsafe impl LifetimeFree for core::num::ParseFloatError {}
383unsafe impl LifetimeFree for core::num::ParseIntError {}
384unsafe impl LifetimeFree for core::num::TryFromIntError {}
385unsafe impl LifetimeFree for core::num::FpCategory {}
386unsafe impl LifetimeFree for core::num::IntErrorKind {}
387
388unsafe impl<A> LifetimeFree for core::option::IntoIter<A> where A: LifetimeFree {}
389unsafe impl<T> LifetimeFree for core::result::IntoIter<T> where T: LifetimeFree {}
390unsafe impl<T> LifetimeFree for core::panic::AssertUnwindSafe<T> where T: LifetimeFree {}
391
392unsafe impl LifetimeFree for core::str::ParseBoolError {}
393unsafe impl LifetimeFree for core::str::Utf8Error {}
394
395unsafe impl LifetimeFree for core::task::RawWaker {}
396unsafe impl LifetimeFree for core::task::RawWakerVTable {}
397unsafe impl LifetimeFree for core::task::Waker {}
398
399unsafe impl LifetimeFree for core::time::TryFromFloatSecsError {}
400
401macro_rules! impl_for_tuples {
402    ( $( $args:ident ),* $(,)? ) => {
403        impl_for_tuples!( @impl [] [ $( $args ),* ] );
404    };
405    ( @impl [ $( $args:ident ),* ] [ $next:ident $(, $rest:ident )* ] ) => {
406        impl_for_tuples!( @impl [ $( $args ),* ] [] );
407        impl_for_tuples!( @impl [ $( $args, )* $next ] [ $( $rest ),* ] );
408    };
409    ( @impl [ $( $args:ident ),* ] [] ) => {
410        unsafe impl<$( $args ),*> LifetimeFree for ( $( $args, )* )
411        where
412            $( $args: LifetimeFree, )*
413        {
414        }
415    };
416}
417
418impl_for_tuples! { T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12 }
419
420macro_rules! impl_for_fn_ptrs {
421    ( $abi:literal, $( $args:ident ),* $(,)? ) => {
422        impl_for_fn_ptrs!( @impl $abi [] [ $( $args ),* ] );
423    };
424    ( @impl $abi:literal [ $( $args:ident ),* ] [ $next:ident $(, $rest:ident )* ] ) => {
425        impl_for_fn_ptrs!( @impl $abi [ $( $args ),* ] [] );
426        impl_for_fn_ptrs!( @impl $abi [ $( $args, )* $next ] [ $( $rest ),* ] );
427    };
428    ( @impl $abi:literal [ $( $args:ident ),* ] [] ) => {
429        unsafe impl<$( $args, )* R> LifetimeFree for extern $abi fn( $( $args, )* ) -> R
430        where
431            $( $args: LifetimeFree, )*
432            R: LifetimeFree,
433        {
434        }
435    };
436}
437
438impl_for_fn_ptrs! { "Rust", T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12 }
439impl_for_fn_ptrs! { "C", T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12 }
440impl_for_fn_ptrs! { "system", T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12 }
441
442#[cfg(feature = "alloc")]
443#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
444mod alloc_impls {
445    use crate::LifetimeFree;
446
447    unsafe impl<T> LifetimeFree for alloc::boxed::Box<T> where T: ?Sized + LifetimeFree {}
448    unsafe impl<T> LifetimeFree for alloc::rc::Rc<T> where T: ?Sized + LifetimeFree {}
449    unsafe impl<T> LifetimeFree for alloc::rc::Weak<T> where T: ?Sized + LifetimeFree {}
450    #[cfg(target_has_atomic = "ptr")]
451    unsafe impl<T> LifetimeFree for alloc::sync::Arc<T> where T: ?Sized + LifetimeFree {}
452    #[cfg(target_has_atomic = "ptr")]
453    unsafe impl<T> LifetimeFree for alloc::sync::Weak<T> where T: ?Sized + LifetimeFree {}
454
455    unsafe impl LifetimeFree for alloc::string::String {}
456    unsafe impl LifetimeFree for alloc::ffi::CString {}
457
458    unsafe impl<T> LifetimeFree for alloc::vec::Vec<T> where T: LifetimeFree {}
459    unsafe impl<T> LifetimeFree for alloc::collections::VecDeque<T> where T: LifetimeFree {}
460    unsafe impl<T> LifetimeFree for alloc::collections::LinkedList<T> where T: LifetimeFree {}
461    unsafe impl<T> LifetimeFree for alloc::collections::BinaryHeap<T> where T: LifetimeFree {}
462    unsafe impl<T> LifetimeFree for alloc::collections::BTreeSet<T> where T: LifetimeFree {}
463
464    unsafe impl<K, V> LifetimeFree for alloc::collections::BTreeMap<K, V>
465    where
466        K: LifetimeFree,
467        V: LifetimeFree,
468    {
469    }
470
471    unsafe impl LifetimeFree for alloc::string::FromUtf8Error {}
472    unsafe impl LifetimeFree for alloc::string::FromUtf16Error {}
473
474    unsafe impl LifetimeFree for alloc::collections::TryReserveError {}
475    unsafe impl<T> LifetimeFree for alloc::collections::binary_heap::IntoIter<T> where T: LifetimeFree {}
476    unsafe impl<K, V> LifetimeFree for alloc::collections::btree_map::IntoIter<K, V>
477    where
478        K: LifetimeFree,
479        V: LifetimeFree,
480    {
481    }
482    unsafe impl<K, V> LifetimeFree for alloc::collections::btree_map::IntoKeys<K, V>
483    where
484        K: LifetimeFree,
485        V: LifetimeFree,
486    {
487    }
488    unsafe impl<K, V> LifetimeFree for alloc::collections::btree_map::IntoValues<K, V>
489    where
490        K: LifetimeFree,
491        V: LifetimeFree,
492    {
493    }
494    unsafe impl<T> LifetimeFree for alloc::collections::btree_set::IntoIter<T> where T: LifetimeFree {}
495    unsafe impl<T> LifetimeFree for alloc::vec::IntoIter<T> where T: LifetimeFree {}
496}
497
498#[cfg(feature = "std")]
499#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
500mod std_impls {
501    use crate::LifetimeFree;
502
503    unsafe impl LifetimeFree for std::ffi::OsStr {}
504    unsafe impl LifetimeFree for std::path::Path {}
505
506    unsafe impl LifetimeFree for std::ffi::OsString {}
507    unsafe impl LifetimeFree for std::path::PathBuf {}
508    unsafe impl LifetimeFree for std::time::Instant {}
509    unsafe impl LifetimeFree for std::time::SystemTime {}
510
511    unsafe impl LifetimeFree for std::hash::DefaultHasher {}
512    unsafe impl LifetimeFree for std::hash::RandomState {}
513
514    unsafe impl<T, S> LifetimeFree for std::collections::HashSet<T, S>
515    where
516        T: LifetimeFree,
517        S: LifetimeFree,
518    {
519    }
520
521    unsafe impl<K, V, S> LifetimeFree for std::collections::HashMap<K, V, S>
522    where
523        K: LifetimeFree,
524        V: LifetimeFree,
525        S: LifetimeFree,
526    {
527    }
528
529    unsafe impl LifetimeFree for std::alloc::System {}
530    unsafe impl LifetimeFree for std::backtrace::Backtrace {}
531    unsafe impl LifetimeFree for std::backtrace::BacktraceStatus {}
532
533    unsafe impl<K, V> LifetimeFree for std::collections::hash_map::IntoIter<K, V>
534    where
535        K: LifetimeFree,
536        V: LifetimeFree,
537    {
538    }
539    unsafe impl<K, V> LifetimeFree for std::collections::hash_map::IntoKeys<K, V>
540    where
541        K: LifetimeFree,
542        V: LifetimeFree,
543    {
544    }
545    unsafe impl<K, V> LifetimeFree for std::collections::hash_map::IntoValues<K, V>
546    where
547        K: LifetimeFree,
548        V: LifetimeFree,
549    {
550    }
551    unsafe impl<T> LifetimeFree for std::collections::hash_set::IntoIter<T> where T: LifetimeFree {}
552
553    unsafe impl<T> LifetimeFree for std::collections::vec_deque::IntoIter<T> where T: LifetimeFree {}
554
555    unsafe impl LifetimeFree for std::env::Args {}
556    unsafe impl LifetimeFree for std::env::ArgsOs {}
557    unsafe impl LifetimeFree for std::env::JoinPathsError {}
558    unsafe impl LifetimeFree for std::env::Vars {}
559    unsafe impl LifetimeFree for std::env::VarsOs {}
560    unsafe impl LifetimeFree for std::env::VarError {}
561
562    unsafe impl LifetimeFree for std::fs::DirBuilder {}
563    unsafe impl LifetimeFree for std::fs::DirEntry {}
564    unsafe impl LifetimeFree for std::fs::File {}
565    unsafe impl LifetimeFree for std::fs::FileTimes {}
566    unsafe impl LifetimeFree for std::fs::FileType {}
567    unsafe impl LifetimeFree for std::fs::Metadata {}
568    unsafe impl LifetimeFree for std::fs::OpenOptions {}
569    unsafe impl LifetimeFree for std::fs::Permissions {}
570    unsafe impl LifetimeFree for std::fs::ReadDir {}
571
572    unsafe impl<R> LifetimeFree for std::io::BufReader<R> where R: ?Sized + LifetimeFree {}
573    unsafe impl<W> LifetimeFree for std::io::BufWriter<W> where W: ?Sized + LifetimeFree + std::io::Write
574    {}
575    unsafe impl<R> LifetimeFree for std::io::Bytes<R> where R: LifetimeFree {}
576    unsafe impl<T, U> LifetimeFree for std::io::Chain<T, U>
577    where
578        T: LifetimeFree,
579        U: LifetimeFree,
580    {
581    }
582    unsafe impl<T> LifetimeFree for std::io::Cursor<T> where T: LifetimeFree {}
583    unsafe impl LifetimeFree for std::io::Empty {}
584    unsafe impl LifetimeFree for std::io::Error {}
585    unsafe impl<W> LifetimeFree for std::io::IntoInnerError<W> where W: LifetimeFree {}
586    unsafe impl<W> LifetimeFree for std::io::LineWriter<W> where
587        W: ?Sized + LifetimeFree + std::io::Write
588    {
589    }
590    unsafe impl<B> LifetimeFree for std::io::Lines<B> where B: LifetimeFree {}
591    unsafe impl LifetimeFree for std::io::Repeat {}
592    unsafe impl LifetimeFree for std::io::Sink {}
593    unsafe impl<B> LifetimeFree for std::io::Split<B> where B: LifetimeFree {}
594    unsafe impl LifetimeFree for std::io::Stderr {}
595    unsafe impl LifetimeFree for std::io::Stdin {}
596    unsafe impl LifetimeFree for std::io::Stdout {}
597    unsafe impl<T> LifetimeFree for std::io::Take<T> where T: LifetimeFree {}
598    unsafe impl LifetimeFree for std::io::WriterPanicked {}
599    unsafe impl LifetimeFree for std::io::ErrorKind {}
600    unsafe impl LifetimeFree for std::io::SeekFrom {}
601
602    unsafe impl LifetimeFree for std::net::TcpListener {}
603    unsafe impl LifetimeFree for std::net::TcpStream {}
604    unsafe impl LifetimeFree for std::net::UdpSocket {}
605    unsafe impl LifetimeFree for std::net::Shutdown {}
606
607    unsafe impl LifetimeFree for std::path::StripPrefixError {}
608
609    unsafe impl LifetimeFree for std::process::Child {}
610    unsafe impl LifetimeFree for std::process::ChildStderr {}
611    unsafe impl LifetimeFree for std::process::ChildStdin {}
612    unsafe impl LifetimeFree for std::process::ChildStdout {}
613    unsafe impl LifetimeFree for std::process::Command {}
614    unsafe impl LifetimeFree for std::process::ExitCode {}
615    unsafe impl LifetimeFree for std::process::ExitStatus {}
616    unsafe impl LifetimeFree for std::process::Output {}
617    unsafe impl LifetimeFree for std::process::Stdio {}
618
619    unsafe impl LifetimeFree for std::sync::Barrier {}
620    unsafe impl LifetimeFree for std::sync::BarrierWaitResult {}
621    unsafe impl LifetimeFree for std::sync::Condvar {}
622    unsafe impl<T, F> LifetimeFree for std::sync::LazyLock<T, F>
623    where
624        T: LifetimeFree,
625        F: LifetimeFree,
626    {
627    }
628    unsafe impl<T> LifetimeFree for std::sync::Mutex<T> where T: ?Sized + LifetimeFree {}
629    unsafe impl LifetimeFree for std::sync::Once {}
630    unsafe impl<T> LifetimeFree for std::sync::OnceLock<T> where T: LifetimeFree {}
631    unsafe impl LifetimeFree for std::sync::OnceState {}
632    unsafe impl<T> LifetimeFree for std::sync::PoisonError<T> where T: LifetimeFree {}
633    unsafe impl<T> LifetimeFree for std::sync::RwLock<T> where T: ?Sized + LifetimeFree {}
634    unsafe impl LifetimeFree for std::sync::WaitTimeoutResult {}
635    unsafe impl<T> LifetimeFree for std::sync::TryLockError<T> where T: LifetimeFree {}
636
637    unsafe impl<T> LifetimeFree for std::sync::mpsc::IntoIter<T> where T: LifetimeFree {}
638    unsafe impl<T> LifetimeFree for std::sync::mpsc::Receiver<T> where T: LifetimeFree {}
639    unsafe impl LifetimeFree for std::sync::mpsc::RecvError {}
640    unsafe impl<T> LifetimeFree for std::sync::mpsc::SendError<T> where T: LifetimeFree {}
641    unsafe impl<T> LifetimeFree for std::sync::mpsc::Sender<T> where T: LifetimeFree {}
642    unsafe impl<T> LifetimeFree for std::sync::mpsc::SyncSender<T> where T: LifetimeFree {}
643    unsafe impl LifetimeFree for std::sync::mpsc::RecvTimeoutError {}
644    unsafe impl LifetimeFree for std::sync::mpsc::TryRecvError {}
645    unsafe impl<T> LifetimeFree for std::sync::mpsc::TrySendError<T> where T: LifetimeFree {}
646
647    unsafe impl LifetimeFree for std::thread::AccessError {}
648    unsafe impl LifetimeFree for std::thread::Builder {}
649    unsafe impl<T> LifetimeFree for std::thread::JoinHandle<T> where T: LifetimeFree {}
650    unsafe impl LifetimeFree for std::thread::Thread {}
651    unsafe impl LifetimeFree for std::thread::ThreadId {}
652
653    unsafe impl LifetimeFree for std::time::SystemTimeError {}
654}
655
656#[cfg(target_arch = "x86")]
657#[cfg_attr(docsrs, doc(cfg(target_arch = "x86")))]
658mod x86_impls {
659    use crate::LifetimeFree;
660
661    unsafe impl LifetimeFree for core::arch::x86::CpuidResult {}
662    unsafe impl LifetimeFree for core::arch::x86::__m128 {}
663    unsafe impl LifetimeFree for core::arch::x86::__m256 {}
664    unsafe impl LifetimeFree for core::arch::x86::__m512 {}
665    unsafe impl LifetimeFree for core::arch::x86::__m128d {}
666    unsafe impl LifetimeFree for core::arch::x86::__m128i {}
667    unsafe impl LifetimeFree for core::arch::x86::__m256d {}
668    unsafe impl LifetimeFree for core::arch::x86::__m256i {}
669    unsafe impl LifetimeFree for core::arch::x86::__m512d {}
670    unsafe impl LifetimeFree for core::arch::x86::__m512i {}
671}
672
673#[cfg(target_arch = "x86_64")]
674#[cfg_attr(docsrs, doc(cfg(target_arch = "x86_64")))]
675mod x86_64_impls {
676    use crate::LifetimeFree;
677
678    unsafe impl LifetimeFree for core::arch::x86_64::CpuidResult {}
679    unsafe impl LifetimeFree for core::arch::x86_64::__m128 {}
680    unsafe impl LifetimeFree for core::arch::x86_64::__m256 {}
681    unsafe impl LifetimeFree for core::arch::x86_64::__m512 {}
682    unsafe impl LifetimeFree for core::arch::x86_64::__m128d {}
683    unsafe impl LifetimeFree for core::arch::x86_64::__m128i {}
684    unsafe impl LifetimeFree for core::arch::x86_64::__m256d {}
685    unsafe impl LifetimeFree for core::arch::x86_64::__m256i {}
686    unsafe impl LifetimeFree for core::arch::x86_64::__m512d {}
687    unsafe impl LifetimeFree for core::arch::x86_64::__m512i {}
688}
689
690#[cfg(any(target_arch = "aarch64", target_arch = "arm64ec"))]
691#[cfg_attr(
692    docsrs,
693    doc(cfg(any(target_arch = "aarch64", target_arch = "arm64ec")))
694)]
695mod aarch64_impls {
696    use crate::LifetimeFree;
697
698    unsafe impl LifetimeFree for core::arch::aarch64::float32x2_t {}
699    unsafe impl LifetimeFree for core::arch::aarch64::float32x2x2_t {}
700    unsafe impl LifetimeFree for core::arch::aarch64::float32x2x3_t {}
701    unsafe impl LifetimeFree for core::arch::aarch64::float32x2x4_t {}
702    unsafe impl LifetimeFree for core::arch::aarch64::float32x4_t {}
703    unsafe impl LifetimeFree for core::arch::aarch64::float32x4x2_t {}
704    unsafe impl LifetimeFree for core::arch::aarch64::float32x4x3_t {}
705    unsafe impl LifetimeFree for core::arch::aarch64::float32x4x4_t {}
706    unsafe impl LifetimeFree for core::arch::aarch64::float64x1_t {}
707    unsafe impl LifetimeFree for core::arch::aarch64::float64x1x2_t {}
708    unsafe impl LifetimeFree for core::arch::aarch64::float64x1x3_t {}
709    unsafe impl LifetimeFree for core::arch::aarch64::float64x1x4_t {}
710    unsafe impl LifetimeFree for core::arch::aarch64::float64x2_t {}
711    unsafe impl LifetimeFree for core::arch::aarch64::float64x2x2_t {}
712    unsafe impl LifetimeFree for core::arch::aarch64::float64x2x3_t {}
713    unsafe impl LifetimeFree for core::arch::aarch64::float64x2x4_t {}
714    unsafe impl LifetimeFree for core::arch::aarch64::int8x8_t {}
715    unsafe impl LifetimeFree for core::arch::aarch64::int8x8x2_t {}
716    unsafe impl LifetimeFree for core::arch::aarch64::int8x8x3_t {}
717    unsafe impl LifetimeFree for core::arch::aarch64::int8x8x4_t {}
718    unsafe impl LifetimeFree for core::arch::aarch64::int8x16_t {}
719    unsafe impl LifetimeFree for core::arch::aarch64::int8x16x2_t {}
720    unsafe impl LifetimeFree for core::arch::aarch64::int8x16x3_t {}
721    unsafe impl LifetimeFree for core::arch::aarch64::int8x16x4_t {}
722    unsafe impl LifetimeFree for core::arch::aarch64::int16x4_t {}
723    unsafe impl LifetimeFree for core::arch::aarch64::int16x4x2_t {}
724    unsafe impl LifetimeFree for core::arch::aarch64::int16x4x3_t {}
725    unsafe impl LifetimeFree for core::arch::aarch64::int16x4x4_t {}
726    unsafe impl LifetimeFree for core::arch::aarch64::int16x8_t {}
727    unsafe impl LifetimeFree for core::arch::aarch64::int16x8x2_t {}
728    unsafe impl LifetimeFree for core::arch::aarch64::int16x8x3_t {}
729    unsafe impl LifetimeFree for core::arch::aarch64::int16x8x4_t {}
730    unsafe impl LifetimeFree for core::arch::aarch64::int32x2_t {}
731    unsafe impl LifetimeFree for core::arch::aarch64::int32x2x2_t {}
732    unsafe impl LifetimeFree for core::arch::aarch64::int32x2x3_t {}
733    unsafe impl LifetimeFree for core::arch::aarch64::int32x2x4_t {}
734    unsafe impl LifetimeFree for core::arch::aarch64::int32x4_t {}
735    unsafe impl LifetimeFree for core::arch::aarch64::int32x4x2_t {}
736    unsafe impl LifetimeFree for core::arch::aarch64::int32x4x3_t {}
737    unsafe impl LifetimeFree for core::arch::aarch64::int32x4x4_t {}
738    unsafe impl LifetimeFree for core::arch::aarch64::int64x1_t {}
739    unsafe impl LifetimeFree for core::arch::aarch64::int64x1x2_t {}
740    unsafe impl LifetimeFree for core::arch::aarch64::int64x1x3_t {}
741    unsafe impl LifetimeFree for core::arch::aarch64::int64x1x4_t {}
742    unsafe impl LifetimeFree for core::arch::aarch64::int64x2_t {}
743    unsafe impl LifetimeFree for core::arch::aarch64::int64x2x2_t {}
744    unsafe impl LifetimeFree for core::arch::aarch64::int64x2x3_t {}
745    unsafe impl LifetimeFree for core::arch::aarch64::int64x2x4_t {}
746    unsafe impl LifetimeFree for core::arch::aarch64::poly8x8_t {}
747    unsafe impl LifetimeFree for core::arch::aarch64::poly8x8x2_t {}
748    unsafe impl LifetimeFree for core::arch::aarch64::poly8x8x3_t {}
749    unsafe impl LifetimeFree for core::arch::aarch64::poly8x8x4_t {}
750    unsafe impl LifetimeFree for core::arch::aarch64::poly8x16_t {}
751    unsafe impl LifetimeFree for core::arch::aarch64::poly8x16x2_t {}
752    unsafe impl LifetimeFree for core::arch::aarch64::poly8x16x3_t {}
753    unsafe impl LifetimeFree for core::arch::aarch64::poly8x16x4_t {}
754    unsafe impl LifetimeFree for core::arch::aarch64::poly16x4_t {}
755    unsafe impl LifetimeFree for core::arch::aarch64::poly16x4x2_t {}
756    unsafe impl LifetimeFree for core::arch::aarch64::poly16x4x3_t {}
757    unsafe impl LifetimeFree for core::arch::aarch64::poly16x4x4_t {}
758    unsafe impl LifetimeFree for core::arch::aarch64::poly16x8_t {}
759    unsafe impl LifetimeFree for core::arch::aarch64::poly16x8x2_t {}
760    unsafe impl LifetimeFree for core::arch::aarch64::poly16x8x3_t {}
761    unsafe impl LifetimeFree for core::arch::aarch64::poly16x8x4_t {}
762    unsafe impl LifetimeFree for core::arch::aarch64::poly64x1_t {}
763    unsafe impl LifetimeFree for core::arch::aarch64::poly64x1x2_t {}
764    unsafe impl LifetimeFree for core::arch::aarch64::poly64x1x3_t {}
765    unsafe impl LifetimeFree for core::arch::aarch64::poly64x1x4_t {}
766    unsafe impl LifetimeFree for core::arch::aarch64::poly64x2_t {}
767    unsafe impl LifetimeFree for core::arch::aarch64::poly64x2x2_t {}
768    unsafe impl LifetimeFree for core::arch::aarch64::poly64x2x3_t {}
769    unsafe impl LifetimeFree for core::arch::aarch64::poly64x2x4_t {}
770    unsafe impl LifetimeFree for core::arch::aarch64::uint8x8_t {}
771    unsafe impl LifetimeFree for core::arch::aarch64::uint8x8x2_t {}
772    unsafe impl LifetimeFree for core::arch::aarch64::uint8x8x3_t {}
773    unsafe impl LifetimeFree for core::arch::aarch64::uint8x8x4_t {}
774    unsafe impl LifetimeFree for core::arch::aarch64::uint8x16_t {}
775    unsafe impl LifetimeFree for core::arch::aarch64::uint8x16x2_t {}
776    unsafe impl LifetimeFree for core::arch::aarch64::uint8x16x3_t {}
777    unsafe impl LifetimeFree for core::arch::aarch64::uint8x16x4_t {}
778    unsafe impl LifetimeFree for core::arch::aarch64::uint16x4_t {}
779    unsafe impl LifetimeFree for core::arch::aarch64::uint16x4x2_t {}
780    unsafe impl LifetimeFree for core::arch::aarch64::uint16x4x3_t {}
781    unsafe impl LifetimeFree for core::arch::aarch64::uint16x4x4_t {}
782    unsafe impl LifetimeFree for core::arch::aarch64::uint16x8_t {}
783    unsafe impl LifetimeFree for core::arch::aarch64::uint16x8x2_t {}
784    unsafe impl LifetimeFree for core::arch::aarch64::uint16x8x3_t {}
785    unsafe impl LifetimeFree for core::arch::aarch64::uint16x8x4_t {}
786    unsafe impl LifetimeFree for core::arch::aarch64::uint32x2_t {}
787    unsafe impl LifetimeFree for core::arch::aarch64::uint32x2x2_t {}
788    unsafe impl LifetimeFree for core::arch::aarch64::uint32x2x3_t {}
789    unsafe impl LifetimeFree for core::arch::aarch64::uint32x2x4_t {}
790    unsafe impl LifetimeFree for core::arch::aarch64::uint32x4_t {}
791    unsafe impl LifetimeFree for core::arch::aarch64::uint32x4x2_t {}
792    unsafe impl LifetimeFree for core::arch::aarch64::uint32x4x3_t {}
793    unsafe impl LifetimeFree for core::arch::aarch64::uint32x4x4_t {}
794    unsafe impl LifetimeFree for core::arch::aarch64::uint64x1_t {}
795    unsafe impl LifetimeFree for core::arch::aarch64::uint64x1x2_t {}
796    unsafe impl LifetimeFree for core::arch::aarch64::uint64x1x3_t {}
797    unsafe impl LifetimeFree for core::arch::aarch64::uint64x1x4_t {}
798    unsafe impl LifetimeFree for core::arch::aarch64::uint64x2_t {}
799    unsafe impl LifetimeFree for core::arch::aarch64::uint64x2x2_t {}
800    unsafe impl LifetimeFree for core::arch::aarch64::uint64x2x3_t {}
801    unsafe impl LifetimeFree for core::arch::aarch64::uint64x2x4_t {}
802}
803
804#[cfg(target_arch = "wasm32")]
805#[cfg_attr(docsrs, doc(cfg(target_arch = "wasm32")))]
806mod aarch64_impls {
807    use crate::LifetimeFree;
808
809    unsafe impl LifetimeFree for core::arch::wasm32::v128 {}
810}
811
812#[cfg(all(feature = "std", any(unix, target_os = "hermit", target_os = "wasi")))]
813#[cfg_attr(
814    docsrs,
815    doc(cfg(all(feature = "std", any(unix, target_os = "hermit", target_os = "wasi"))))
816)]
817mod fd_impls {
818    use crate::LifetimeFree;
819
820    unsafe impl LifetimeFree for std::os::fd::OwnedFd {}
821}
822
823// First `cfg` is copied from stdlib sources.
824#[cfg(not(any(
825    all(target_arch = "wasm32", not(target_os = "wasi")),
826    all(target_vendor = "fortanix", target_env = "sgx")
827)))]
828#[cfg(all(feature = "std", not(target_os = "hermit"), unix))]
829#[cfg_attr(docsrs, doc(cfg(all(feature = "std", unix))))]
830mod unix_impls {
831    use crate::LifetimeFree;
832
833    unsafe impl LifetimeFree for std::os::unix::net::SocketAddr {}
834    unsafe impl LifetimeFree for std::os::unix::net::UnixDatagram {}
835    unsafe impl LifetimeFree for std::os::unix::net::UnixListener {}
836    unsafe impl LifetimeFree for std::os::unix::net::UnixStream {}
837}
838
839// First `cfg` is copied from stdlib sources.
840#[cfg(not(any(
841    all(target_arch = "wasm32", not(target_os = "wasi")),
842    all(target_vendor = "fortanix", target_env = "sgx")
843)))]
844#[cfg(all(feature = "std", windows))]
845#[cfg_attr(docsrs, doc(cfg(all(feature = "std", windows))))]
846mod windows_impls {
847    use crate::LifetimeFree;
848
849    unsafe impl LifetimeFree for std::os::windows::io::HandleOrInvalid {}
850    unsafe impl LifetimeFree for std::os::windows::io::HandleOrNull {}
851    unsafe impl LifetimeFree for std::os::windows::io::InvalidHandleError {}
852    unsafe impl LifetimeFree for std::os::windows::io::NullHandleError {}
853    unsafe impl LifetimeFree for std::os::windows::io::OwnedHandle {}
854    unsafe impl LifetimeFree for std::os::windows::io::OwnedSocket {}
855}