This is an automated email from the ASF dual-hosted git repository.

tqchen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm-ffi.git


The following commit(s) were added to refs/heads/main by this push:
     new 45053ea6 [FIX][Rust] Fix clippy warnings in tvm-ffi-macros (#826)
45053ea6 is described below

commit 45053ea6fbea90d896adf8691e7f989e74055d3e
Author: Gabriel Wu <[email protected]>
AuthorDate: Mon Sep 28 22:21:09 2026 +0800

    [FIX][Rust] Fix clippy warnings in tvm-ffi-macros (#826)
    
    ## Why
    
    `cargo clippy -p tvm-ffi-macros --all-targets -- -D warnings` fails on
    `main` with four warnings, all in `tvm-ffi-macros`. CI runs only `cargo
    test` for the Rust crates, so they go unnoticed, but they fail anyone
    who lints the crate. This follows #496, which fixed deny-level lints in
    the same crates.
    
    ## What
    
    - `lib.rs` (`useless_conversion`, 2 warnings): `derive_object` and
    `derive_object_ref` wrapped values that already are
    `proc_macro::TokenStream` in `TokenStream::from`; the wrapper is
    removed.
    - `object_macros.rs` (`bind_instead_of_map`): `Option::and_then(|f|
    Some(quote! { .. }))` becomes `Option::map(|f| quote! { .. })`.
    - `match_any.rs` (`too_many_arguments`): `expand_direct_leaf_selection`
    takes nine arguments, six of which are the hygienic identifiers that the
    generated code shares with its caller. Grouping them in a struct would
    mean changing the neighbouring expanders too, so the lint is allowed on
    this function, as the crate already does elsewhere
    (`#[allow(clippy::wrong_self_convention)]` in `tensor.rs`).
    
    Generated code is unchanged.
    
    ## Scope
    
    - This covers only `tvm-ffi-macros`. `tvm-ffi` has about 70 clippy
    warnings under default lints; many of them, such as missing `# Safety`
    sections or `Default` implementations, need decisions on public items,
    so they are left for separate changes.
    - `rustfmt` also reports differences on `main` in
    `tvm-ffi-macros/src/dispatch.rs` and
    `tvm-ffi/tests/test_structural_visit.rs`. They are not touched here.
---
 rust/tvm-ffi-macros/src/lib.rs           | 4 ++--
 rust/tvm-ffi-macros/src/match_any.rs     | 3 +++
 rust/tvm-ffi-macros/src/object_macros.rs | 6 +++---
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/rust/tvm-ffi-macros/src/lib.rs b/rust/tvm-ffi-macros/src/lib.rs
index 7cb3805d..054836b8 100644
--- a/rust/tvm-ffi-macros/src/lib.rs
+++ b/rust/tvm-ffi-macros/src/lib.rs
@@ -52,11 +52,11 @@ pub fn match_any(input: TokenStream) -> TokenStream {
 #[proc_macro_error]
 #[proc_macro_derive(Object, attributes(type_key, type_index, type_final))]
 pub fn derive_object(input: TokenStream) -> TokenStream {
-    TokenStream::from(object_macros::derive_object(input))
+    object_macros::derive_object(input)
 }
 
 #[proc_macro_error]
 #[proc_macro_derive(ObjectRef, attributes(type_key, type_index))]
 pub fn derive_object_ref(input: TokenStream) -> TokenStream {
-    TokenStream::from(object_macros::derive_object_ref(input))
+    object_macros::derive_object_ref(input)
 }
diff --git a/rust/tvm-ffi-macros/src/match_any.rs 
b/rust/tvm-ffi-macros/src/match_any.rs
index e9574fd8..5cb12c2c 100644
--- a/rust/tvm-ffi-macros/src/match_any.rs
+++ b/rust/tvm-ffi-macros/src/match_any.rs
@@ -298,6 +298,9 @@ fn expand_leaf_table_lookup(tvm_ffi: &TokenStream, arms: 
&[TypedArm], view: &Ide
     }
 }
 
+// The identifiers are the hygienic names the generated code shares with its
+// caller.
+#[allow(clippy::too_many_arguments)]
 fn expand_direct_leaf_selection(
     tvm_ffi: &TokenStream,
     arms: &[TypedArm],
diff --git a/rust/tvm-ffi-macros/src/object_macros.rs 
b/rust/tvm-ffi-macros/src/object_macros.rs
index 9a0fe807..dace824b 100644
--- a/rust/tvm-ffi-macros/src/object_macros.rs
+++ b/rust/tvm-ffi-macros/src/object_macros.rs
@@ -76,16 +76,16 @@ pub fn derive_object(input: proc_macro::TokenStream) -> 
TokenStream {
     // search for field name base and derive the base type
     // we expect base always to be the first field
     let final_parent_check = match &derive_input.data {
-        syn::Data::Struct(s) => s.fields.iter().next().and_then(|f| {
+        syn::Data::Struct(s) => s.fields.iter().next().map(|f| {
             let base_ty = f.ty.clone();
-            Some(quote! {
+            quote! {
                 const _: () = {
                     ::core::assert!(
                         !<#base_ty as 
#tvm_ffi_crate::object::ObjectCore>::TYPE_FINAL,
                         "an object type cannot derive from a final parent"
                     );
                 };
-            })
+            }
         }),
         _ => panic!("First field must be `<base_name>: <ObjectCoreType>`"),
     };

Reply via email to