[PATCH 0/2] rust: add unsafe precondition assertions to Vec length helpers

From: JX

Date: Tue Sep 08 2026 - 04:14:16 EST


The safety requirements of `Vec::inc_len` and `Vec::dec_len` are
currently checked with `debug_assert!`. Convert them to
`unsafe_precondition_assert!` so violations are reported consistently
with other unsafe precondition failures.

The first patch makes the no-message form of
`unsafe_precondition_assert!` usable from const functions. This is
needed by `Vec::inc_len`, which is const, and avoids runtime formatting
when the diagnostic consists only of the stringified condition.

The second patch converts both Vec length helpers.

The series has been checked with:

make rustfmtcheck
make CLIPPY=1 rust/kernel.o
make rusttest
make rustdoc

JX (2):
rust: make unsafe_precondition_assert! const compatible
rust: alloc: use unsafe_precondition_assert! in Vec length helpers

rust/kernel/alloc/kvec.rs | 7 ++++---
rust/kernel/safety.rs | 10 +++++++++-
2 files changed, 13 insertions(+), 4 deletions(-)


base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
--
2.54.0