Skip to content

Commit

Permalink
fix: only remove #[must_use] for non-dynamic fns
Browse files Browse the repository at this point in the history
  • Loading branch information
oberrich committed Feb 6, 2025
1 parent d0652a0 commit b625a69
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions bindgen/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1153,15 +1153,15 @@ impl CodeGenerator for Type {

let mut attrs = attrs_for_item(item, ctx);
/*attrs.retain(|attr| {
attr.to_string() != attributes::must_use().to_string()
});
TODO: See if this disappears:
+++ generated from: "/home/runner/work/rust-bindgen/rust-bindgen/bindgen-tests/tests/headers/dynamic_loading_attributes.h"
24 24 | let baz = __library.get(b"baz\0").map(|sym| *sym)?;
25 25 | Ok(TestLib { __library, foo, baz })
26 26 | }
27 | - #[must_use]
*/
attr.to_string() != attributes::must_use().to_string()
});
TODO: See if this disappears:
+++ generated from: "/home/runner/work/rust-bindgen/rust-bindgen/bindgen-tests/tests/headers/dynamic_loading_attributes.h"
24 24 | let baz = __library.get(b"baz\0").map(|sym| *sym)?;
25 25 | Ok(TestLib { __library, foo, baz })
26 26 | }
27 | - #[must_use]
*/

if let Some(inner_attrs) =
result.get_attributes(inner_item.id())
Expand Down Expand Up @@ -3314,9 +3314,9 @@ impl Method {

let block = ctx.wrap_unsafe_ops(quote! ( #( #stmts );*));

let mut attrs = attrs_for_item(function_item, ctx);
let mut attrs = attrs_for_item(function_item, ctx);
attrs.push(attributes::inline());

attrs.retain(|attr| {
attr.to_string() != attributes::must_use().to_string()
});
Expand Down Expand Up @@ -4789,9 +4789,6 @@ impl CodeGenerator for Function {

let mut attrs = attrs_for_item(item, ctx);

attrs.retain(|attr| {
attr.to_string() != attributes::must_use().to_string()
});

// Resolve #[must_use] attribute through return type
if signature
Expand Down Expand Up @@ -4907,6 +4904,12 @@ impl CodeGenerator for Function {
.rust_features
.unsafe_extern_blocks
.then(|| quote!(unsafe));

if !is_dynamic_function {
attrs.retain(|attr| {
attr.to_string() != attributes::must_use().to_string()
});
}

let attrs = process_attributes(
result,
Expand Down

0 comments on commit b625a69

Please sign in to comment.