From: FUJITA Tomonori <fujita.tomonori@gmail.com>
To: miguel.ojeda.sandonis@gmail.com, aliceryhl@google.com
Cc: fujita.tomonori@gmail.com, a.hindborg@kernel.org,
alex.gaynor@gmail.com, ojeda@kernel.org,
anna-maria@linutronix.de, bjorn3_gh@protonmail.com,
boqun.feng@gmail.com, dakr@kernel.org, frederic@kernel.org,
gary@garyguo.net, jstultz@google.com,
linux-kernel@vger.kernel.org, lossin@kernel.org,
lyude@redhat.com, rust-for-linux@vger.kernel.org,
sboyd@kernel.org, tglx@linutronix.de, tmgross@umich.edu
Subject: Re: [PATCH v1 1/2] rust: time: Rename Delta's methods as_micros_ceil and as_millis
Date: Thu, 19 Jun 2025 16:08:44 +0900 (JST) [thread overview]
Message-ID: <20250619.160844.1477802332578239775.fujita.tomonori@gmail.com> (raw)
In-Reply-To: <CANiq72mBfTr0cdj_4Cpdk62h2k+Y5K3NSs54_1-9jiszMZ6AuA@mail.gmail.com>
On Wed, 18 Jun 2025 17:47:27 +0200
Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> wrote:
> On Wed, Jun 18, 2025 at 3:17 PM Alice Ryhl <aliceryhl@google.com> wrote:
>>
>> There are also methods such as Duration::as_millis(). Yes, those take
>> &self but &self is equivalent to self for Copy types, so there is no
>> difference. And even if we did treat them differently,
>> Duration::as_millis() is actually borrowed->owned as the return type
>> is not a reference, so ...
>
> In most cases it may not matter, but even if taking either was exactly
> the same, the point of the discussion(s) was what is more idiomatic,
> i.e. how to spell those signatures.
>
> I understand you are saying that `Duration::as_millis()` is already a
> stable example from the standard library of something that is not
> borrowed -> borrowed, and thus the guidelines should be understood as
> implying it is fine either way. It is still confusing, as shown by
> these repeated discussions, and on the parameter's side of things,
> they still seem to prefer `&self`, including in the equivalent methods
> of this patch.
>
> Personally, I would use `self`, and clarify the guidelines.
So would the function be defined like this?
fn as_nanos(self) -> i64;
If that's the case, then we've come full circle back to the original
problem; Clippy warns against using as_* names for trait methods that
take self as follows:
warning: methods called `as_*` usually take `self` by reference or `self` by mutable reference
--> /home/fujita/git/linux-rust/rust/kernel/time/hrtimer.rs:430:17
|
430 | fn as_nanos(self) -> i64;
| ^^^^
|
= help: consider choosing a less ambiguous name
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#wrong_self_convention
= note: `-W clippy::wrong-self-convention` implied by `-W clippy::all`
= help: to override `-W clippy::all` add `#[allow(clippy::wrong_self_convention)]`
https://lore.kernel.org/rust-for-linux/20250610132823.3457263-2-fujita.tomonori@gmail.com/
HrTimerExpires trait needs as_nanos() method and Instant and Delta
need to implement HrTimerExpires trait.
We need a consistent definition of as_nanos() across the
HrTimerExpires trait, and the Instant and Delta structures.
And it would be better if the definition of as_nanos were consistent
with the other as_* methods.
It looks like the conversion from Delta to i64 doesn’t quite fit any
of the categories in the API guidelines. How should it be defined?
next prev parent reply other threads:[~2025-06-19 7:08 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-17 14:41 [PATCH v1 0/2] rust: time: Add fsleep() FUJITA Tomonori
2025-06-17 14:41 ` [PATCH v1 1/2] rust: time: Rename Delta's methods as_micros_ceil and as_millis FUJITA Tomonori
2025-06-18 8:05 ` Alice Ryhl
2025-06-18 9:29 ` Miguel Ojeda
2025-06-18 9:52 ` Alice Ryhl
2025-06-18 11:03 ` Miguel Ojeda
2025-06-18 13:17 ` Alice Ryhl
2025-06-18 15:47 ` Miguel Ojeda
2025-06-19 7:08 ` FUJITA Tomonori [this message]
2025-06-19 7:23 ` Miguel Ojeda
2025-06-19 9:28 ` Andreas Hindborg
2025-06-19 11:44 ` Miguel Ojeda
2025-06-19 12:51 ` Andreas Hindborg
2025-06-19 19:03 ` Miguel Ojeda
2025-06-24 12:15 ` Alice Ryhl
2025-06-24 13:49 ` FUJITA Tomonori
2025-06-24 13:54 ` Alice Ryhl
2025-06-24 14:14 ` FUJITA Tomonori
2025-06-24 14:45 ` Alice Ryhl
2025-06-24 16:39 ` FUJITA Tomonori
2025-06-19 9:12 ` Andreas Hindborg
2025-06-19 11:25 ` FUJITA Tomonori
2025-06-17 14:41 ` [PATCH v1 2/2] rust: time: Add wrapper for fsleep() function FUJITA Tomonori
2025-06-30 12:07 ` Andreas Hindborg
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=20250619.160844.1477802332578239775.fujita.tomonori@gmail.com \
--to=fujita.tomonori@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=anna-maria@linutronix.de \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=frederic@kernel.org \
--cc=gary@garyguo.net \
--cc=jstultz@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=lyude@redhat.com \
--cc=miguel.ojeda.sandonis@gmail.com \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sboyd@kernel.org \
--cc=tglx@linutronix.de \
--cc=tmgross@umich.edu \
/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;
as well as URLs for NNTP newsgroup(s).