Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: remove `RUSTC_HAS_COERCE_POINTEE` and simplify code

With the Rust version bump in place, the `RUSTC_HAS_COERCE_POINTEE`
Kconfig (automatic) option is always true.

Thus remove the option and simplify the code.

In particular, this includes removing our use of the predecessor unstable
features we used with Rust < 1.84.0 (`coerce_unsized`, `dispatch_from_dyn`
and `unsize`).

Reviewed-by: Tamir Duberstein <tamird@kernel.org>
Acked-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
Link: https://patch.msgid.link/20260405235309.418950-11-ojeda@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

+6 -77
-3
init/Kconfig
··· 178 178 # https://github.com/llvm/llvm-project/pull/130661 179 179 def_bool LD_IS_BFD || LLD_VERSION >= 210000 180 180 181 - config RUSTC_HAS_COERCE_POINTEE 182 - def_bool RUSTC_VERSION >= 108400 183 - 184 181 config RUSTC_HAS_SPAN_FILE 185 182 def_bool RUSTC_VERSION >= 108800 186 183
+2 -27
rust/kernel/alloc/kbox.rs
··· 77 77 /// `self.0` is always properly aligned and either points to memory allocated with `A` or, for 78 78 /// zero-sized types, is a dangling, well aligned pointer. 79 79 #[repr(transparent)] 80 - #[cfg_attr(CONFIG_RUSTC_HAS_COERCE_POINTEE, derive(core::marker::CoercePointee))] 81 - pub struct Box<#[cfg_attr(CONFIG_RUSTC_HAS_COERCE_POINTEE, pointee)] T: ?Sized, A: Allocator>( 82 - NonNull<T>, 83 - PhantomData<A>, 84 - ); 85 - 86 - // This is to allow coercion from `Box<T, A>` to `Box<U, A>` if `T` can be converted to the 87 - // dynamically-sized type (DST) `U`. 88 - #[cfg(not(CONFIG_RUSTC_HAS_COERCE_POINTEE))] 89 - impl<T, U, A> core::ops::CoerceUnsized<Box<U, A>> for Box<T, A> 90 - where 91 - T: ?Sized + core::marker::Unsize<U>, 92 - U: ?Sized, 93 - A: Allocator, 94 - { 95 - } 96 - 97 - // This is to allow `Box<U, A>` to be dispatched on when `Box<T, A>` can be coerced into `Box<U, 98 - // A>`. 99 - #[cfg(not(CONFIG_RUSTC_HAS_COERCE_POINTEE))] 100 - impl<T, U, A> core::ops::DispatchFromDyn<Box<U, A>> for Box<T, A> 101 - where 102 - T: ?Sized + core::marker::Unsize<U>, 103 - U: ?Sized, 104 - A: Allocator, 105 - { 106 - } 80 + #[derive(core::marker::CoercePointee)] 81 + pub struct Box<#[pointee] T: ?Sized, A: Allocator>(NonNull<T>, PhantomData<A>); 107 82 108 83 /// Type alias for [`Box`] with a [`Kmalloc`] allocator. 109 84 ///
+1 -7
rust/kernel/lib.rs
··· 39 39 // 40 40 // Expected to become stable. 41 41 #![feature(arbitrary_self_types)] 42 + #![feature(derive_coerce_pointee)] 42 43 // 43 44 // To be determined. 44 45 #![feature(used_with_arg)] 45 - // 46 - // `feature(derive_coerce_pointee)` is expected to become stable. Before Rust 47 - // 1.84.0, it did not exist, so enable the predecessor features. 48 - #![cfg_attr(CONFIG_RUSTC_HAS_COERCE_POINTEE, feature(derive_coerce_pointee))] 49 - #![cfg_attr(not(CONFIG_RUSTC_HAS_COERCE_POINTEE), feature(coerce_unsized))] 50 - #![cfg_attr(not(CONFIG_RUSTC_HAS_COERCE_POINTEE), feature(dispatch_from_dyn))] 51 - #![cfg_attr(not(CONFIG_RUSTC_HAS_COERCE_POINTEE), feature(unsize))] 52 46 // 53 47 // `feature(file_with_nul)` is expected to become stable. Before Rust 1.89.0, it did not exist, so 54 48 // enable it conditionally.
+1 -21
rust/kernel/list/arc.rs
··· 160 160 /// 161 161 /// [`List`]: crate::list::List 162 162 #[repr(transparent)] 163 - #[cfg_attr(CONFIG_RUSTC_HAS_COERCE_POINTEE, derive(core::marker::CoercePointee))] 163 + #[derive(core::marker::CoercePointee)] 164 164 pub struct ListArc<T, const ID: u64 = 0> 165 165 where 166 166 T: ListArcSafe<ID> + ?Sized, ··· 441 441 fn as_ref(&self) -> &Arc<T> { 442 442 self.as_arc() 443 443 } 444 - } 445 - 446 - // This is to allow coercion from `ListArc<T>` to `ListArc<U>` if `T` can be converted to the 447 - // dynamically-sized type (DST) `U`. 448 - #[cfg(not(CONFIG_RUSTC_HAS_COERCE_POINTEE))] 449 - impl<T, U, const ID: u64> core::ops::CoerceUnsized<ListArc<U, ID>> for ListArc<T, ID> 450 - where 451 - T: ListArcSafe<ID> + core::marker::Unsize<U> + ?Sized, 452 - U: ListArcSafe<ID> + ?Sized, 453 - { 454 - } 455 - 456 - // This is to allow `ListArc<U>` to be dispatched on when `ListArc<T>` can be coerced into 457 - // `ListArc<U>`. 458 - #[cfg(not(CONFIG_RUSTC_HAS_COERCE_POINTEE))] 459 - impl<T, U, const ID: u64> core::ops::DispatchFromDyn<ListArc<U, ID>> for ListArc<T, ID> 460 - where 461 - T: ListArcSafe<ID> + core::marker::Unsize<U> + ?Sized, 462 - U: ListArcSafe<ID> + ?Sized, 463 - { 464 444 } 465 445 466 446 /// A utility for tracking whether a [`ListArc`] exists using an atomic.
+2 -19
rust/kernel/sync/arc.rs
··· 128 128 /// # Ok::<(), Error>(()) 129 129 /// ``` 130 130 #[repr(transparent)] 131 - #[cfg_attr(CONFIG_RUSTC_HAS_COERCE_POINTEE, derive(core::marker::CoercePointee))] 131 + #[derive(core::marker::CoercePointee)] 132 132 pub struct Arc<T: ?Sized> { 133 133 ptr: NonNull<ArcInner<T>>, 134 134 // NB: this informs dropck that objects of type `ArcInner<T>` may be used in `<Arc<T> as ··· 181 181 unsafe { NonNull::new_unchecked(ptr.cast_mut()) } 182 182 } 183 183 } 184 - 185 - // This is to allow coercion from `Arc<T>` to `Arc<U>` if `T` can be converted to the 186 - // dynamically-sized type (DST) `U`. 187 - #[cfg(not(CONFIG_RUSTC_HAS_COERCE_POINTEE))] 188 - impl<T: ?Sized + core::marker::Unsize<U>, U: ?Sized> core::ops::CoerceUnsized<Arc<U>> for Arc<T> {} 189 - 190 - // This is to allow `Arc<U>` to be dispatched on when `Arc<T>` can be coerced into `Arc<U>`. 191 - #[cfg(not(CONFIG_RUSTC_HAS_COERCE_POINTEE))] 192 - impl<T: ?Sized + core::marker::Unsize<U>, U: ?Sized> core::ops::DispatchFromDyn<Arc<U>> for Arc<T> {} 193 184 194 185 // SAFETY: It is safe to send `Arc<T>` to another thread when the underlying `T` is `Sync` because 195 186 // it effectively means sharing `&T` (which is safe because `T` is `Sync`); additionally, it needs ··· 538 547 /// # Ok::<(), Error>(()) 539 548 /// ``` 540 549 #[repr(transparent)] 541 - #[cfg_attr(CONFIG_RUSTC_HAS_COERCE_POINTEE, derive(core::marker::CoercePointee))] 550 + #[derive(core::marker::CoercePointee)] 542 551 pub struct ArcBorrow<'a, T: ?Sized + 'a> { 543 552 inner: NonNull<ArcInner<T>>, 544 553 _p: PhantomData<&'a ()>, 545 - } 546 - 547 - // This is to allow `ArcBorrow<U>` to be dispatched on when `ArcBorrow<T>` can be coerced into 548 - // `ArcBorrow<U>`. 549 - #[cfg(not(CONFIG_RUSTC_HAS_COERCE_POINTEE))] 550 - impl<T: ?Sized + core::marker::Unsize<U>, U: ?Sized> core::ops::DispatchFromDyn<ArcBorrow<'_, U>> 551 - for ArcBorrow<'_, T> 552 - { 553 554 } 554 555 555 556 impl<T: ?Sized> Clone for ArcBorrow<'_, T> {