Skip to content

rust: const_eval: add a mechanism to do const trait calls

Gary Guo lkml rust-for-linux 2 versions – In review

Get series with b4
b4 am [email protected] change-id 20260828-cv-acaf3400d16c

Versions newest first

  1. v2 Latest3 patches 7 repliesIn review
  2. v12 patches 4 repliesSuperseded

Changes in v2 from the cover letter

- Split from cv!() alt series, and become a general infra instead.
- Link to v1: https://patch.msgid.link/[email protected]

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3rust: const_eval: add `#[const_eval_only]` attributerust/build_error.rs rust/kernel/const_eval.rs rust/kernel/device_id.rs +3 more+66 -02 replies
2/3rust: const_eval: allow const trait method invocation in some contextsrust/kernel/const_eval.rs rust/kernel/prelude.rs rust/macros/const_eval.rs +1 more+146 -30 replies
3/3rust: str: convert `as_char_ptr` to work with `const_call!`rust/kernel/configfs.rs rust/kernel/drm/device.rs rust/kernel/drm/ioctl.rs +6 more+28 -200 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/3] rust: const_eval: add a mechanism to do const trait calls

Add a mechanism to perform const trait method calls, with the same type inference capabilities. This would only work for concrete types (not inside generic functions).

As an example, convert as_char_ptr_in_const_context, so instead of

kernel::str::as_char_ptr_in_const_context(c_str)

one may write

    const_call!(c_str.as_char_ptr())

instead.

---
Changes in v2:
- Split from cv!() alt series, and become a general infra instead.
- Link to v1: https://patch.msgid.link/[email protected]

---
Gary Guo (3):
rust: const_eval: add #[const_eval_only] attribute
rust: const_eval: allow const trait method invocation in some contexts
rust: str: convert as_char_ptr to work with const_call!

 rust/build_error.rs       |   7 +++
 rust/kernel/configfs.rs   |   2 +-
 rust/kernel/const_eval.rs | 115 ++++++++++++++++++++++++++++++++++++++++++++++
 rust/kernel/device_id.rs  |   4 ++
 rust/kernel/drm/device.rs |   4 +-
 rust/kernel/drm/ioctl.rs  |   4 +-
 rust/kernel/kunit.rs      |   6 +--
 rust/kernel/lib.rs        |   1 +
 rust/kernel/miscdevice.rs |   2 +-
 rust/kernel/net/phy.rs    |   2 +-
 rust/kernel/prelude.rs    |   1 +
 rust/kernel/str.rs        |  15 +++---
 rust/macros/const_eval.rs |  51 ++++++++++++++++++++
 rust/macros/lib.rs        |  39 ++++++++++++++++
 rust/macros/module.rs     |   4 +-
 15 files changed, 237 insertions(+), 20 deletions(-)

---
base-commit: 89c07d98716a13454ec3fd9f97689e812cc71bd4
change-id: 20260828-cv-acaf3400d16c

Best regards,

Signature · 1 line
Gary Guo <[email protected]>