<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/rust/macros/vtable.rs, branch v6.6.131</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=v6.6.131</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=v6.6.131'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2023-08-09T19:15:07+00:00</updated>
<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>
