[PATCH] rust: str: make NullTerminatedFormatter public

Alexandre Courbot posted 1 patch 1 month, 1 week ago
rust/kernel/str.rs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] rust: str: make NullTerminatedFormatter public
Posted by Alexandre Courbot 1 month, 1 week ago
If `CONFIG_BLOCK` is disabled, the following warnings are displayed
during build:

  warning: struct `NullTerminatedFormatter` is never constructed
    --> ../rust/kernel/str.rs:667:19
      |
  667 | pub(crate) struct NullTerminatedFormatter<'a> {
      |                   ^^^^^^^^^^^^^^^^^^^^^^^
      |
      = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

  warning: associated function `new` is never used
    --> ../rust/kernel/str.rs:673:19
      |
  671 | impl<'a> NullTerminatedFormatter<'a> {
      | ------------------------------------ associated function in this implementation
  672 |     /// Create a new [`Self`] instance.
  673 |     pub(crate) fn new(buffer: &'a mut [u8]) -> Option<NullTerminatedFormatter<'a>> {

Fix them by making `NullTerminatedFormatter` public, as it could be
useful for drivers anyway.

Fixes: cdde7a1951ff ("rust: str: introduce `NullTerminatedFormatter`")
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 rust/kernel/str.rs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs
index fa87779d2253..3f8918764640 100644
--- a/rust/kernel/str.rs
+++ b/rust/kernel/str.rs
@@ -664,13 +664,13 @@ fn write_str(&mut self, s: &str) -> fmt::Result {
 ///
 /// * The first byte of `buffer` is always zero.
 /// * The length of `buffer` is at least 1.
-pub(crate) struct NullTerminatedFormatter<'a> {
+pub struct NullTerminatedFormatter<'a> {
     buffer: &'a mut [u8],
 }
 
 impl<'a> NullTerminatedFormatter<'a> {
     /// Create a new [`Self`] instance.
-    pub(crate) fn new(buffer: &'a mut [u8]) -> Option<NullTerminatedFormatter<'a>> {
+    pub fn new(buffer: &'a mut [u8]) -> Option<NullTerminatedFormatter<'a>> {
         *(buffer.first_mut()?) = 0;
 
         // INVARIANT:

---
base-commit: 6de23f81a5e08be8fbf5e8d7e9febc72a5b5f27f
change-id: 20260224-nullterminatedformatter-d06c3733c3bc

Best regards,
-- 
Alexandre Courbot <acourbot@nvidia.com>
Re: [PATCH] rust: str: make NullTerminatedFormatter public
Posted by Miguel Ojeda 1 month ago
On Tue, Feb 24, 2026 at 3:25 AM Alexandre Courbot <acourbot@nvidia.com> wrote:
>
> If `CONFIG_BLOCK` is disabled, the following warnings are displayed
> during build:
>
>   warning: struct `NullTerminatedFormatter` is never constructed
>     --> ../rust/kernel/str.rs:667:19
>       |
>   667 | pub(crate) struct NullTerminatedFormatter<'a> {
>       |                   ^^^^^^^^^^^^^^^^^^^^^^^
>       |
>       = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default
>
>   warning: associated function `new` is never used
>     --> ../rust/kernel/str.rs:673:19
>       |
>   671 | impl<'a> NullTerminatedFormatter<'a> {
>       | ------------------------------------ associated function in this implementation
>   672 |     /// Create a new [`Self`] instance.
>   673 |     pub(crate) fn new(buffer: &'a mut [u8]) -> Option<NullTerminatedFormatter<'a>> {
>
> Fix them by making `NullTerminatedFormatter` public, as it could be
> useful for drivers anyway.
>
> Fixes: cdde7a1951ff ("rust: str: introduce `NullTerminatedFormatter`")
> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>

Applied to `rust-fixes` -- thanks everyone!

Also Cc: stable@vger.kernel.org

Cheers,
Miguel
Re: [PATCH] rust: str: make NullTerminatedFormatter public
Posted by Andreas Hindborg 1 month, 1 week ago
"Alexandre Courbot" <acourbot@nvidia.com> writes:

> If `CONFIG_BLOCK` is disabled, the following warnings are displayed
> during build:
>
>   warning: struct `NullTerminatedFormatter` is never constructed
>     --> ../rust/kernel/str.rs:667:19
>       |
>   667 | pub(crate) struct NullTerminatedFormatter<'a> {
>       |                   ^^^^^^^^^^^^^^^^^^^^^^^
>       |
>       = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default
>
>   warning: associated function `new` is never used
>     --> ../rust/kernel/str.rs:673:19
>       |
>   671 | impl<'a> NullTerminatedFormatter<'a> {
>       | ------------------------------------ associated function in this implementation
>   672 |     /// Create a new [`Self`] instance.
>   673 |     pub(crate) fn new(buffer: &'a mut [u8]) -> Option<NullTerminatedFormatter<'a>> {
>
> Fix them by making `NullTerminatedFormatter` public, as it could be
> useful for drivers anyway.
>
> Fixes: cdde7a1951ff ("rust: str: introduce `NullTerminatedFormatter`")
> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>

Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>

Best regards,
Andreas Hindborg
Re: [PATCH] rust: str: make NullTerminatedFormatter public
Posted by Alice Ryhl 1 month, 1 week ago
On Tue, Feb 24, 2026 at 11:25:34AM +0900, Alexandre Courbot wrote:
> If `CONFIG_BLOCK` is disabled, the following warnings are displayed
> during build:
> 
>   warning: struct `NullTerminatedFormatter` is never constructed
>     --> ../rust/kernel/str.rs:667:19
>       |
>   667 | pub(crate) struct NullTerminatedFormatter<'a> {
>       |                   ^^^^^^^^^^^^^^^^^^^^^^^
>       |
>       = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default
> 
>   warning: associated function `new` is never used
>     --> ../rust/kernel/str.rs:673:19
>       |
>   671 | impl<'a> NullTerminatedFormatter<'a> {
>       | ------------------------------------ associated function in this implementation
>   672 |     /// Create a new [`Self`] instance.
>   673 |     pub(crate) fn new(buffer: &'a mut [u8]) -> Option<NullTerminatedFormatter<'a>> {
> 
> Fix them by making `NullTerminatedFormatter` public, as it could be
> useful for drivers anyway.
> 
> Fixes: cdde7a1951ff ("rust: str: introduce `NullTerminatedFormatter`")
> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>

Reviewed-by: Alice Ryhl <aliceryhl@google.com>