summaryrefslogtreecommitdiff
path: root/src/codegen/mod.rs
diff options
context:
space:
mode:
authorPorter Smith <flowbish@gmail.com>2018-11-26 16:59:18 -0800
committerPorter Smith <flowbish@gmail.com>2018-11-27 11:31:27 -0800
commitd34e10fbeb5af70bbc7e22405de60f30c8570087 (patch)
tree97d285a485da5af97b680dc1a6a181c39be5c08a /src/codegen/mod.rs
parent1e527e2575119784a0c61783576356090c2be1e1 (diff)
Add #[must_use] to functions annotated with __attribute__((warn_unused_result))
Diffstat (limited to 'src/codegen/mod.rs')
-rw-r--r--src/codegen/mod.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 34b5b4d9..073745b1 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -2154,9 +2154,13 @@ impl MethodCodegen for Method {
let mut attrs = vec![];
attrs.push(attributes::inline());
+ if signature.must_use() && ctx.options().rust_features().must_use_function {
+ attrs.push(attributes::must_use());
+ }
+
let name = ctx.rust_ident(&name);
methods.push(quote! {
- #[inline]
+ #(#attrs)*
pub unsafe fn #name ( #( #args ),* ) #ret {
#block
}
@@ -3374,6 +3378,10 @@ impl CodeGenerator for Function {
let mut attributes = vec![];
+ if signature.must_use() && ctx.options().rust_features().must_use_function {
+ attributes.push(attributes::must_use());
+ }
+
if let Some(comment) = item.comment(ctx) {
attributes.push(attributes::doc(comment));
}