Skip to content

Commit 846c1cf

Browse files
cqs21fbq
authored andcommitted
rust: macros: fix redefine const_name in vtable
If the trait has same function name, the `vtable` macro will redefine its `gen_const_name`, e.g.: ```rust #[vtable] pub trait Foo { #[cfg(CONFIG_X)] fn bar(); #[cfg(not(CONFIG_X))] fn bar(x: usize); } ``` Use `HashSet` to avoid this. Signed-off-by: Qingsong Chen <changxian.cqs@antgroup.com> Reviewed-by: Gary Guo <gary@garyguo.net> Reviewed-by: Benno Lossin <benno.lossin@proton.me> Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com> Link: https://lore.kernel.org/r/20230626074242.3945398-2-changxian.cqs@antgroup.com
1 parent 3138aa3 commit 846c1cf

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

rust/macros/vtable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub(crate) fn vtable(_attr: TokenStream, ts: TokenStream) -> TokenStream {
2727
};
2828

2929
let mut body_it = body.stream().into_iter();
30-
let mut functions = Vec::new();
30+
let mut functions = HashSet::new();
3131
let mut consts = HashSet::new();
3232
while let Some(token) = body_it.next() {
3333
match token {
@@ -37,7 +37,7 @@ pub(crate) fn vtable(_attr: TokenStream, ts: TokenStream) -> TokenStream {
3737
// Possibly we've encountered a fn pointer type instead.
3838
_ => continue,
3939
};
40-
functions.push(fn_name);
40+
functions.insert(fn_name);
4141
}
4242
TokenTree::Ident(ident) if ident.to_string() == "const" => {
4343
let const_name = match body_it.next() {

0 commit comments

Comments
 (0)