rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 1/2] rust: Implement Display for Box
       [not found] <20241104140514.877185-1-2407018371@qq.com>
@ 2024-11-04 14:06 ` Guangbo Cui
  2024-11-05  9:49   ` Alice Ryhl
  2024-11-04 14:06 ` [PATCH v4 2/2] rust: align Debug implementation for Box with Display Guangbo Cui
  1 sibling, 1 reply; 5+ messages in thread
From: Guangbo Cui @ 2024-11-04 14:06 UTC (permalink / raw)
  To: Miguel Ojeda, Alex Gaynor
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, rust-for-linux,
	Danilo Krummrich, Guangbo Cui

Currently `impl Display` is missing for `Box<T, A>`, as a result,
things like using `Box<..>` directly as an operand in `pr_info!()`
are impossible, which is less ergonomic compared to `Box` in Rust
std.

Therefore add `impl Display` for `Box`.

Suggested-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://github.com/Rust-for-Linux/linux/issues/1126
Signed-off-by: Guangbo Cui <2407018371@qq.com>
---
 rust/kernel/alloc/kbox.rs | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/rust/kernel/alloc/kbox.rs b/rust/kernel/alloc/kbox.rs
index d69c32496..a496a866d 100644
--- a/rust/kernel/alloc/kbox.rs
+++ b/rust/kernel/alloc/kbox.rs
@@ -427,6 +427,16 @@ fn deref_mut(&mut self) -> &mut T {
     }
 }
 
+impl<T, A> fmt::Display for Box<T, A>
+where
+    T: ?Sized + fmt::Display,
+    A: Allocator,
+{
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        <T as fmt::Display>::fmt(&**self, f)
+    }
+}
+
 impl<T, A> fmt::Debug for Box<T, A>
 where
     T: ?Sized + fmt::Debug,
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v4 2/2] rust: align Debug implementation for Box with Display
       [not found] <20241104140514.877185-1-2407018371@qq.com>
  2024-11-04 14:06 ` [PATCH v4 1/2] rust: Implement Display for Box Guangbo Cui
@ 2024-11-04 14:06 ` Guangbo Cui
  2024-11-05  9:49   ` Alice Ryhl
  2024-11-08 10:40   ` Danilo Krummrich
  1 sibling, 2 replies; 5+ messages in thread
From: Guangbo Cui @ 2024-11-04 14:06 UTC (permalink / raw)
  To: Miguel Ojeda, Alex Gaynor
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, rust-for-linux,
	Danilo Krummrich, Guangbo Cui

Ensure consistency between `Debug` and `Display` for `Box` by
updating `Debug` to match the new `Display` style.

Acked-by: Danilo Krummrich <dakr@kernel.org>
Signed-off-by: Guangbo Cui <2407018371@qq.com>
---
 rust/kernel/alloc/kbox.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/rust/kernel/alloc/kbox.rs b/rust/kernel/alloc/kbox.rs
index a496a866d..49c24727f 100644
--- a/rust/kernel/alloc/kbox.rs
+++ b/rust/kernel/alloc/kbox.rs
@@ -443,7 +443,7 @@ impl<T, A> fmt::Debug for Box<T, A>
     A: Allocator,
 {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        fmt::Debug::fmt(&**self, f)
+        <T as fmt::Debug>::fmt(&**self, f)
     }
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v4 1/2] rust: Implement Display for Box
  2024-11-04 14:06 ` [PATCH v4 1/2] rust: Implement Display for Box Guangbo Cui
@ 2024-11-05  9:49   ` Alice Ryhl
  0 siblings, 0 replies; 5+ messages in thread
From: Alice Ryhl @ 2024-11-05  9:49 UTC (permalink / raw)
  To: Guangbo Cui
  Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Trevor Gross, rust-for-linux, Danilo Krummrich

On Mon, Nov 4, 2024 at 3:06 PM Guangbo Cui <2407018371@qq.com> wrote:
>
> Currently `impl Display` is missing for `Box<T, A>`, as a result,
> things like using `Box<..>` directly as an operand in `pr_info!()`
> are impossible, which is less ergonomic compared to `Box` in Rust
> std.
>
> Therefore add `impl Display` for `Box`.
>
> Suggested-by: Boqun Feng <boqun.feng@gmail.com>
> Link: https://github.com/Rust-for-Linux/linux/issues/1126
> Signed-off-by: Guangbo Cui <2407018371@qq.com>

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v4 2/2] rust: align Debug implementation for Box with Display
  2024-11-04 14:06 ` [PATCH v4 2/2] rust: align Debug implementation for Box with Display Guangbo Cui
@ 2024-11-05  9:49   ` Alice Ryhl
  2024-11-08 10:40   ` Danilo Krummrich
  1 sibling, 0 replies; 5+ messages in thread
From: Alice Ryhl @ 2024-11-05  9:49 UTC (permalink / raw)
  To: Guangbo Cui
  Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Trevor Gross, rust-for-linux, Danilo Krummrich

On Mon, Nov 4, 2024 at 3:07 PM Guangbo Cui <2407018371@qq.com> wrote:
>
> Ensure consistency between `Debug` and `Display` for `Box` by
> updating `Debug` to match the new `Display` style.
>
> Acked-by: Danilo Krummrich <dakr@kernel.org>
> Signed-off-by: Guangbo Cui <2407018371@qq.com>

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v4 2/2] rust: align Debug implementation for Box with Display
  2024-11-04 14:06 ` [PATCH v4 2/2] rust: align Debug implementation for Box with Display Guangbo Cui
  2024-11-05  9:49   ` Alice Ryhl
@ 2024-11-08 10:40   ` Danilo Krummrich
  1 sibling, 0 replies; 5+ messages in thread
From: Danilo Krummrich @ 2024-11-08 10:40 UTC (permalink / raw)
  To: Guangbo Cui
  Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, rust-for-linux

On Mon, Nov 04, 2024 at 10:06:42PM +0800, Guangbo Cui wrote:
> Ensure consistency between `Debug` and `Display` for `Box` by
> updating `Debug` to match the new `Display` style.
> 
> Acked-by: Danilo Krummrich <dakr@kernel.org>

The ACK was for patch 1 -- this patch I haven't seen before obviously.

However, you can keep it. For both:

Acked-by: Danilo Krummrich <dakr@kernel.org>

> Signed-off-by: Guangbo Cui <2407018371@qq.com>
> ---
>  rust/kernel/alloc/kbox.rs | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/rust/kernel/alloc/kbox.rs b/rust/kernel/alloc/kbox.rs
> index a496a866d..49c24727f 100644
> --- a/rust/kernel/alloc/kbox.rs
> +++ b/rust/kernel/alloc/kbox.rs
> @@ -443,7 +443,7 @@ impl<T, A> fmt::Debug for Box<T, A>
>      A: Allocator,
>  {
>      fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
> -        fmt::Debug::fmt(&**self, f)
> +        <T as fmt::Debug>::fmt(&**self, f)
>      }
>  }
>  
> -- 
> 2.34.1
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-11-08 10:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20241104140514.877185-1-2407018371@qq.com>
2024-11-04 14:06 ` [PATCH v4 1/2] rust: Implement Display for Box Guangbo Cui
2024-11-05  9:49   ` Alice Ryhl
2024-11-04 14:06 ` [PATCH v4 2/2] rust: align Debug implementation for Box with Display Guangbo Cui
2024-11-05  9:49   ` Alice Ryhl
2024-11-08 10:40   ` Danilo Krummrich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).