Re: [PATCH] rust: device_id: rename IdTable::as_ptr to as_raw_id_table()
From: Alice Ryhl
Date: Thu Jul 02 2026 - 10:01:25 EST
On Thu, Jul 2, 2026 at 3:48 PM Gary Guo <gary@xxxxxxxxxxx> wrote:
>
> On Thu Jul 2, 2026 at 1:30 PM BST, Alice Ryhl wrote:
> > The current name of `as_ptr` is very generic, and if you attempt to
> > invoke `foo.as_ptr()` on a type for which this method is missing, then
> > an error along these lines will be printed:
> >
> > error[E0599]: no method named `as_ptr` found for reference `&DmaBuf` in the current scope
> > --> linux/rust/kernel/dma_buf/buf.rs:54:38
> > |
> > 54 | ptr::eq(self.as_ptr(), other.as_ptr())
> > | ^^^^^^ method not found in `&DmaBuf`
> > |
> > = help: items from traits can only be used if the trait is implemented and in scope
> > note: `device_id::IdTable` defines an item `as_ptr`, perhaps you need to implement it
> > --> linux/rust/kernel/device_id.rs:165:1
> > |
> > 165 | pub trait IdTable<T: RawDeviceId, U> {
> > | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> >
> > Suggesting the IdTable trait when an as_ptr() method is missing is not
> > useful. Renaming it to `as_raw_id_table` makes the method name unique to
> > this trait and avoids these bad suggestions.
>
> I think the name is fine. Functions of this sort is named `as_ptr()` and I don't
> see why it should differ just because it's on traits.
>
> I'd rather say this is a Rust deficiency. Perhaps there needs to be a
> improvement of `#[diagnostic::do_not_recommend]` so it can be sticked to methods
> or traits as well.
I had a similar thought:
https://internals.rust-lang.org/t/do-not-recommend-for-traits-themselves/24431
Alice