[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DB36PVASJ5G9.2TMRXNIXYI9UO@kernel.org>
Date: Fri, 04 Jul 2025 12:05:26 +0200
From: "Benno Lossin" <lossin@...nel.org>
To: "Tamir Duberstein" <tamird@...il.com>
Cc: "Michal Rostecki" <vadorovsky@...tonmail.com>, "Miguel Ojeda"
<ojeda@...nel.org>, "Alex Gaynor" <alex.gaynor@...il.com>, "Boqun Feng"
<boqun.feng@...il.com>, "Gary Guo" <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>, "Andreas
Hindborg" <a.hindborg@...nel.org>, "Alice Ryhl" <aliceryhl@...gle.com>,
"Trevor Gross" <tmgross@...ch.edu>, "Brendan Higgins"
<brendan.higgins@...ux.dev>, "David Gow" <davidgow@...gle.com>, "Rae Moar"
<rmoar@...gle.com>, "Danilo Krummrich" <dakr@...nel.org>, "Maarten
Lankhorst" <maarten.lankhorst@...ux.intel.com>, "Maxime Ripard"
<mripard@...nel.org>, "Thomas Zimmermann" <tzimmermann@...e.de>, "David
Airlie" <airlied@...il.com>, "Simona Vetter" <simona@...ll.ch>, "Greg
Kroah-Hartman" <gregkh@...uxfoundation.org>, "Rafael J. Wysocki"
<rafael@...nel.org>, "Luis Chamberlain" <mcgrof@...nel.org>, "Russ Weight"
<russ.weight@...ux.dev>, "FUJITA Tomonori" <fujita.tomonori@...il.com>,
"Rob Herring" <robh@...nel.org>, "Saravana Kannan" <saravanak@...gle.com>,
"Peter Zijlstra" <peterz@...radead.org>, "Ingo Molnar" <mingo@...hat.com>,
"Will Deacon" <will@...nel.org>, "Waiman Long" <longman@...hat.com>,
"Nathan Chancellor" <nathan@...nel.org>, "Nick Desaulniers"
<nick.desaulniers+lkml@...il.com>, "Bill Wendling" <morbo@...gle.com>,
"Justin Stitt" <justinstitt@...gle.com>, "Andrew Lunn" <andrew@...n.ch>,
"Heiner Kallweit" <hkallweit1@...il.com>, "Russell King"
<linux@...linux.org.uk>, "David S. Miller" <davem@...emloft.net>, "Eric
Dumazet" <edumazet@...gle.com>, "Jakub Kicinski" <kuba@...nel.org>, "Paolo
Abeni" <pabeni@...hat.com>, "Bjorn Helgaas" <bhelgaas@...gle.com>, "Arnd
Bergmann" <arnd@...db.de>, "Jens Axboe" <axboe@...nel.dk>,
Krzysztof Wilczyński <kwilczynski@...nel.org>, "Dave
Ertman" <david.m.ertman@...el.com>, "Ira Weiny" <ira.weiny@...el.com>,
"Leon Romanovsky" <leon@...nel.org>, "Breno Leitao" <leitao@...ian.org>,
"Viresh Kumar" <viresh.kumar@...aro.org>, "Michael Turquette"
<mturquette@...libre.com>, "Stephen Boyd" <sboyd@...nel.org>,
<rust-for-linux@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<linux-kselftest@...r.kernel.org>, <kunit-dev@...glegroups.com>,
<dri-devel@...ts.freedesktop.org>, <netdev@...r.kernel.org>,
<devicetree@...r.kernel.org>, <llvm@...ts.linux.dev>,
<linux-pci@...r.kernel.org>, <nouveau@...ts.freedesktop.org>,
<linux-block@...r.kernel.org>, <linux-pm@...r.kernel.org>,
<linux-clk@...r.kernel.org>
Subject: Re: [PATCH v13 2/5] rust: support formatting of foreign types
On Fri Jul 4, 2025 at 12:41 AM CEST, Tamir Duberstein wrote:
> On Thu, Jul 3, 2025 at 4:36 PM Benno Lossin <lossin@...nel.org> wrote:
>> On Thu Jul 3, 2025 at 8:55 PM CEST, Tamir Duberstein wrote:
>> > On Thu, Jul 3, 2025 at 11:08 AM Benno Lossin <lossin@...nel.org> wrote:
>> >> On Thu Jul 3, 2025 at 3:55 PM CEST, Tamir Duberstein wrote:
>> >> > On Thu, Jul 3, 2025 at 5:32 AM Benno Lossin <lossin@...nel.org> wrote:
>> >> >> On Tue Jul 1, 2025 at 6:49 PM CEST, Tamir Duberstein wrote:
>> >> >> > +impl<T: ?Sized + Display> fmt::Display for Adapter<&T> {
>> >> >> > + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
>> >> >> > + let Self(t) = self;
>> >> >> > + Display::fmt(t, f)
>> >> >>
>> >> >> Why not `Display::fmt(&self.0, f)`?
>> >> >
>> >> > I like destructuring because it shows me that there's only one field.
>> >> > With `self.0` I don't see that.
>> >>
>> >> And what is the benefit here?
>> >
>> > In general the benefit is that the method does not ignore some portion
>> > of `Self`. A method that uses `self.0` would not provoke a compiler
>> > error in case another field is added, while this form would.
>>
>> Yeah, but why would that change happen here? And even if it got another
>> field, why would that invalidate the impl of `fn fmt`?
>
> I don't know, but I would rather force a person to make that decision
> when they add another field rather than assume that such an addition
> wouldn't require changes here.
I don't think so. If this were in another file, then destructuring
might make sense if the struct could conceivably get more fields in the
future **and** it if the other file relied on there only being one
field (or if it *had* to be changed when there was a field added). This
isn't the case here so it's just unnecessary noise.
---
Cheers,
Benno
Powered by blists - more mailing lists