linux/rust/kernel
Xiangfei Ding 47cb6bf786 rust: use derive(CoercePointee) on rustc >= 1.84.0
The `kernel` crate relies on both `coerce_unsized` and `dispatch_from_dyn`
unstable features.

Alice Ryhl has proposed [1] the introduction of the unstable macro
`SmartPointer` to reduce such dependence, along with a RFC patch [2].
Since Rust 1.81.0 this macro, later renamed to `CoercePointee` in
Rust 1.84.0 [3], has been fully implemented with the naming discussion
resolved.

This feature is now on track to stabilization in the language.
In order to do so, we shall start using this macro in the `kernel` crate
to prove the functionality and utility of the macro as the justification
of its stabilization.

This patch makes this switch in such a way that the crate remains
backward compatible with older Rust compiler versions,
via the new Kconfig option `RUSTC_HAS_COERCE_POINTEE`.

A minimal demonstration example is added to the
`samples/rust/rust_print_main.rs` module.

Link: https://rust-lang.github.io/rfcs/3621-derive-smart-pointer.html [1]
Link: https://lore.kernel.org/all/20240823-derive-smart-pointer-v1-1-53769cd37239@google.com/ [2]
Link: https://github.com/rust-lang/rust/pull/131284 [3]
Signed-off-by: Xiangfei Ding <dingxiangfei2009@gmail.com>
Reviewed-by: Fiona Behrens <me@kloenk.dev>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20241203205050.679106-2-dingxiangfei2009@gmail.com
[ Fixed version to 1.84. Renamed option to `RUSTC_HAS_COERCE_POINTEE`
  to match `CC_HAS_*` ones. Moved up new config option, closer to the
  `CC_HAS_*` ones. Simplified Kconfig line. Fixed typos and slightly
  reworded example and commit. Added Link to PR. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2025-01-13 23:45:30 +01:00
..
alloc rust: alloc: add doctest for `ArrayLayout::new()` 2025-01-13 23:45:30 +01:00
block rust: add `build_error!` to the prelude 2025-01-10 00:19:09 +01:00
fs rust: file: add `FileDescriptorReservation` 2024-09-30 13:02:29 +02:00
init rust: treewide: switch to our kernel `Box` type 2024-10-15 22:56:59 +02:00
list rust: use derive(CoercePointee) on rustc >= 1.84.0 2025-01-13 23:45:30 +01:00
net rust: add `build_error!` to the prelude 2025-01-10 00:19:09 +01:00
sync rust: use derive(CoercePointee) on rustc >= 1.84.0 2025-01-13 23:45:30 +01:00
.gitignore rust: jump_label: skip formatting generated file 2024-11-20 13:32:42 -05:00
alloc.rs rust: use derive(CoercePointee) on rustc >= 1.84.0 2025-01-13 23:45:30 +01:00
block.rs rust: block: introduce `kernel::block::mq` module 2024-06-14 07:45:04 -06:00
build_assert.rs rust: add `build_error!` to the prelude 2025-01-10 00:19:09 +01:00
cred.rs rust: file: add `Kuid` wrapper 2024-09-30 13:02:29 +02:00
device.rs rust: finish using custom FFI integer types 2024-12-16 21:48:45 +01:00
error.rs rust: error: import `kernel`'s `LayoutError` instead of `core`'s 2025-01-13 23:45:13 +01:00
firmware.rs rust: map `long` to `isize` and `char` to `u8` 2024-12-16 21:49:33 +01:00
fs.rs rust: file: add Rust abstraction for `struct file` 2024-09-30 13:02:28 +02:00
generated_arch_static_branch_asm.rs.S rust: jump_label: skip formatting generated file 2024-11-20 13:32:42 -05:00
init.rs rust: init: update `stack_try_pin_init` examples 2025-01-13 23:45:13 +01:00
ioctl.rs rust: start using the `#[expect(...)]` attribute 2024-10-07 21:39:57 +02:00
jump_label.rs rust: jump_label: skip formatting generated file 2024-11-20 13:32:42 -05:00
kunit.rs rust: kunit: use C-string literals to clean warning 2024-10-01 23:46:42 +02:00
lib.rs rust: use derive(CoercePointee) on rustc >= 1.84.0 2025-01-13 23:45:30 +01:00
list.rs rust: enable `clippy::undocumented_unsafe_blocks` lint 2024-10-07 21:39:05 +02:00
miscdevice.rs rust: add `build_error!` to the prelude 2025-01-10 00:19:09 +01:00
net.rs rust: core abstractions for network PHY drivers 2023-12-15 09:35:50 +00:00
page.rs rust: page: remove unnecessary helper function from doctest 2025-01-13 23:44:55 +01:00
pid_namespace.rs rust: add PidNamespace 2024-10-08 15:44:36 +02:00
prelude.rs rust: add `build_error!` to the prelude 2025-01-10 00:19:09 +01:00
print.rs rust: cleanup unnecessary casts 2024-12-16 21:49:33 +01:00
rbtree.rs rust: rbtree: remove unwrap in asserts 2025-01-13 23:44:29 +01:00
security.rs rust: finish using custom FFI integer types 2024-12-16 21:48:45 +01:00
seq_file.rs rust: finish using custom FFI integer types 2024-12-16 21:48:45 +01:00
sizes.rs rust: sizes: add commonly used constants 2024-08-30 10:27:34 +01:00
static_assert.rs rust: static_assert: add `static_assert!` macro 2022-12-04 01:59:16 +01:00
std_vendor.rs rust: std_vendor: update dbg macro from Rust upstream 2024-10-10 00:33:42 +02:00
str.rs rust: str: replace unwraps with question mark operators 2025-01-13 23:45:05 +01:00
sync.rs Rust changes for v6.13 2024-11-26 14:00:26 -08:00
task.rs rust: fix up formatting after merge 2024-11-26 17:54:58 -08:00
time.rs rust: use custom FFI integer types 2024-11-10 23:58:00 +01:00
tracepoint.rs rust: add tracepoint support 2024-11-04 16:21:44 -05:00
transmute.rs rust: kernel: move `FromBytes` and `AsBytes` traits to a new `transmute` module 2024-10-10 00:33:42 +02:00
types.rs Char/Misc/IIO/Whatever driver subsystem updates for 6.13-rc1 2024-11-29 11:58:27 -08:00
uaccess.rs rust: map `long` to `isize` and `char` to `u8` 2024-12-16 21:49:33 +01:00
workqueue.rs rust: workqueue: Enable execution of doctests 2024-12-18 00:37:21 +01:00