From: JX <1239989762@qq.com>
To: Miguel Ojeda <ojeda@kernel.org>, Danilo Krummrich <dakr@kernel.org>
Cc: "Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Lorenzo Stoakes" <ljs@kernel.org>,
"Vlastimil Babka" <vbabka@kernel.org>,
"Liam R . Howlett" <liam@infradead.org>,
"Uladzislau Rezki" <urezki@gmail.com>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 0/2] rust: add unsafe precondition assertions to Vec length helpers
Date: Tue, 8 Sep 2026 17:26:22 +0800 [thread overview]
Message-ID: <tencent_1D199D902D0238FCF62DF8ED4FEDA3FDBA05@qq.com> (raw)
In-Reply-To: <20260908080604.34070-1-1239989762@qq.com>
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.
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
Changes in v2:
- Use a fixed diagnostic literal instead of concatenating the stringified
condition into a format string, since conditions may contain braces.
- Add a const-context documentation example with a block expression.
Link: https://lore.kernel.org/r/20260908080604.34070-1-1239989762@qq.com
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 | 11 ++++++++++-
2 files changed, 14 insertions(+), 4 deletions(-)
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
--
2.54.0
next prev parent reply other threads:[~2026-09-08 9:26 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260908080604.34070-1-1239989762@qq.com>
2026-09-08 8:06 ` [PATCH 1/2] rust: make unsafe_precondition_assert! const compatible JX
2026-09-08 8:06 ` [PATCH 2/2] rust: alloc: use unsafe_precondition_assert! in Vec length helpers JX
2026-09-08 9:26 ` JX [this message]
[not found] ` <20260908092624.63350-1-1239989762@qq.com>
2026-09-08 9:26 ` [PATCH v2 1/2] rust: make unsafe_precondition_assert! const compatible JX
2026-09-08 19:59 ` Miguel Ojeda
2026-09-08 9:26 ` [PATCH v2 2/2] rust: alloc: use unsafe_precondition_assert! in Vec length helpers JX
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tencent_1D199D902D0238FCF62DF8ED4FEDA3FDBA05@qq.com \
--to=1239989762@qq.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ljs@kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=urezki@gmail.com \
--cc=vbabka@kernel.org \
--cc=work@onurozkan.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®