<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/rust/macros/vtable.rs, branch v7.0-rc7</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=v7.0-rc7</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=v7.0-rc7'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2026-01-28T12:44:17+00:00</updated>
<entry>
<title>rust: macros: support `#[cfg]` properly in `#[vtable]` macro.</title>
<updated>2026-01-28T12:44:17+00:00</updated>
<author>
<name>Gary Guo</name>
<email>gary@garyguo.net</email>
</author>
<published>2026-01-13T17:05:21+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=779f6e3e1cef07cb0c1241d483ed364e522bd280'/>
<id>urn:sha1:779f6e3e1cef07cb0c1241d483ed364e522bd280</id>
<content type='text'>
Currently, we generate `HAS_` constants as long as the definition exists in
the source, regardless if it is cfg-ed out or not.

Currently, uses of `#[cfg]` present in both trait and impl, so it is not a
problem; however if only the impl side uses `#[cfg]` then `HAS_` constants
will incorrectly be true while it shouldnt't.

With `syn` support, we can now implement `#[cfg]` handling properly by
propagating the `#[cfg]` attributes to the constants.

Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
Reviewed-by: Benno Lossin &lt;lossin@kernel.org&gt;
Link: https://patch.msgid.link/20260113170529.2240744-1-gary@kernel.org
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: macros: convert `#[vtable]` macro to use `syn`</title>
<updated>2026-01-27T23:55:24+00:00</updated>
<author>
<name>Gary Guo</name>
<email>gary@garyguo.net</email>
</author>
<published>2026-01-12T17:07:14+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=5f160950a5cdc36f222299905e09a72f67ebfcd4'/>
<id>urn:sha1:5f160950a5cdc36f222299905e09a72f67ebfcd4</id>
<content type='text'>
`#[vtable]` is converted to use syn. This is more robust than the
previous heuristic-based searching of defined methods and functions.

When doing so, the trait and impl are split into two code paths as the
types are distinct when parsed by `syn`.

Reviewed-by: Tamir Duberstein &lt;tamird@gmail.com&gt;
Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
Reviewed-by: Benno Lossin &lt;lossin@kernel.org&gt;
Link: https://patch.msgid.link/20260112170919.1888584-4-gary@kernel.org
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: macros: use `quote!` from vendored crate</title>
<updated>2026-01-27T23:55:24+00:00</updated>
<author>
<name>Gary Guo</name>
<email>gary@garyguo.net</email>
</author>
<published>2026-01-12T17:07:13+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=f637bafe1ff15fa356c1e0576c32f077b9e6e46a'/>
<id>urn:sha1:f637bafe1ff15fa356c1e0576c32f077b9e6e46a</id>
<content type='text'>
With `quote` crate now vendored in the kernel, we can remove our custom
`quote!` macro implementation and just rely on that crate instead.

The `quote` crate uses types from the `proc-macro2` library so we also
update to use that, and perform conversion in the top-level lib.rs.

Clippy complains about unnecessary `.to_string()` as `proc-macro2`
provides additional `PartialEq` impl, so they are removed.

Reviewed-by: Tamir Duberstein &lt;tamird@gmail.com&gt;
Reviewed-by: Benno Lossin &lt;lossin@kernel.org&gt;
Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
Acked-by: David Gow &lt;davidgow@google.com&gt; # for kunit
Link: https://patch.msgid.link/20260112170919.1888584-3-gary@kernel.org
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: macros: vtable: fix `HAS_*` redefinition (`gen_const_name`)</title>
<updated>2023-08-09T19:15:07+00:00</updated>
<author>
<name>Qingsong Chen</name>
<email>changxian.cqs@antgroup.com</email>
</author>
<published>2023-08-08T02:54:01+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=3fa7187eceee11998f756481e45ce8c4f9d9dc48'/>
<id>urn:sha1:3fa7187eceee11998f756481e45ce8c4f9d9dc48</id>
<content type='text'>
If we define the same function name twice in a trait (using `#[cfg]`),
the `vtable` macro will redefine its `gen_const_name`, e.g. this will
define `HAS_BAR` twice:

    #[vtable]
    pub trait Foo {
        #[cfg(CONFIG_X)]
        fn bar();

        #[cfg(not(CONFIG_X))]
        fn bar(x: usize);
    }

Fixes: b44becc5ee80 ("rust: macros: add `#[vtable]` proc macro")
Signed-off-by: Qingsong Chen &lt;changxian.cqs@antgroup.com&gt;
Reviewed-by: Andreas Hindborg &lt;a.hindborg@samsung.com&gt;
Reviewed-by: Gary Guo &lt;gary@garyguo.net&gt;
Reviewed-by: Sergio González Collado &lt;sergio.collado@gmail.com&gt;
Link: https://lore.kernel.org/r/20230808025404.2053471-1-changxian.cqs@antgroup.com
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: macros: add `#[vtable]` proc macro</title>
<updated>2022-12-04T00:59:15+00:00</updated>
<author>
<name>Gary Guo</name>
<email>gary@garyguo.net</email>
</author>
<published>2022-11-10T16:41:18+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=b44becc5ee808e02bbda0f90ee0584f206693a33'/>
<id>urn:sha1:b44becc5ee808e02bbda0f90ee0584f206693a33</id>
<content type='text'>
This procedural macro attribute provides a simple way to declare
a trait with a set of operations that later users can partially
implement, providing compile-time `HAS_*` boolean associated
constants that indicate whether a particular operation was overridden.

This is useful as the Rust counterpart to structs like
`file_operations` where some pointers may be `NULL`, indicating
an operation is not provided.

For instance:

    #[vtable]
    trait Operations {
        fn read(...) -&gt; Result&lt;usize&gt; {
            Err(EINVAL)
        }

        fn write(...) -&gt; Result&lt;usize&gt; {
            Err(EINVAL)
        }
    }

    #[vtable]
    impl Operations for S {
        fn read(...) -&gt; Result&lt;usize&gt; {
            ...
        }
    }

    assert_eq!(&lt;S as Operations&gt;::HAS_READ, true);
    assert_eq!(&lt;S as Operations&gt;::HAS_WRITE, false);

Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
Reviewed-by: Sergio González Collado &lt;sergio.collado@gmail.com&gt;
[Reworded, adapted for upstream and applied latest changes]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
</feed>
