Skip to content

Commit 95c27d0

Browse files
Copilotjsturtevant
andcommitted
Fix clippy unused_unit warnings in host_bindgen macro for void return functions
Co-authored-by: jsturtevant <[email protected]>
1 parent 544f52f commit 95c27d0

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

src/hyperlight_component_util/src/guest.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ fn emit_import_extern_decl<'a, 'b, 'c>(
6868
ResourceItemName::Static(mn) => quote! { #mn },
6969
},
7070
};
71+
// Only emit the allow attribute if unmarshal is not empty
72+
let unmarshal_with_attr = if unmarshal.is_empty() {
73+
quote! {}
74+
} else {
75+
quote! {
76+
#[allow(clippy::unused_unit)]
77+
#unmarshal
78+
}
79+
};
7180
let decl = quote! {
7281
fn #n(&mut self, #(#param_decls),*) -> #result_decl {
7382
let mut args = ::alloc::vec::Vec::new();
@@ -78,8 +87,7 @@ fn emit_import_extern_decl<'a, 'b, 'c>(
7887
::hyperlight_common::flatbuffer_wrappers::function_types::ReturnType::VecBytes,
7988
);
8089
let ::core::result::Result::Ok(#ret) = #ret else { panic!("bad return from guest {:?}", #ret) };
81-
#[allow(clippy::unused_unit)]
82-
#unmarshal
90+
#unmarshal_with_attr
8391
}
8492
};
8593
match fnname {

src/hyperlight_component_util/src/hl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ pub fn emit_hl_unmarshal_param(s: &mut State, id: Ident, pt: &Value) -> TokenStr
655655
/// are no names in it (i.e. a unit type)
656656
pub fn emit_hl_unmarshal_result(s: &mut State, id: Ident, rt: &etypes::Result) -> TokenStream {
657657
match rt {
658-
etypes::Result::Named(rs) if rs.is_empty() => quote! { () },
658+
etypes::Result::Named(rs) if rs.is_empty() => TokenStream::new(),
659659
etypes::Result::Unnamed(vt) => {
660660
let toks = emit_hl_unmarshal_value(s, id, vt);
661661
quote! { { #toks }.0 }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Seeds for failure cases proptest has generated in the past. It is
2+
# automatically read and these particular cases re-run before any
3+
# novel cases are generated.
4+
#
5+
# It is recommended to check this file in to source control so that
6+
# everyone who runs the test benefits from these saved cases.
7+
cc 9e697e3320100630afae15901d82d23237f04e3d8090ec2c9ecb211fbf322909 # shrinks to x = 0.0
8+
cc 033b8487116d6b64d1c321ca2475618b943551b670ed562648c12f3a7586243a # shrinks to x = EnumA
9+
cc 37f8b1a347c5a2a096a8904b918c0f049b729c80e329ed63dc1b501258a2973b # shrinks to x = false
10+
cc f401ff3b24d9e0b6a5332fbaecbb5cde12d13d932d33d27a5d15ce2ea73a1125 # shrinks to x = 'A'

src/tests/rust_guests/witguest/Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)