summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ir/function.rs4
-rw-r--r--src/lib.rs20
-rw-r--r--src/options.rs8
3 files changed, 31 insertions, 1 deletions
diff --git a/src/ir/function.rs b/src/ir/function.rs
index f851ad72..acbfe707 100644
--- a/src/ir/function.rs
+++ b/src/ir/function.rs
@@ -394,7 +394,9 @@ impl FunctionSig {
}
};
- let must_use = cursor.has_simple_attr("warn_unused_result");
+ let must_use =
+ ctx.options().enable_function_attribute_detection &&
+ cursor.has_simple_attr("warn_unused_result");
let is_method = cursor.kind() == CXCursor_CXXMethod;
let is_constructor = cursor.kind() == CXCursor_Constructor;
let is_destructor = cursor.kind() == CXCursor_Destructor;
diff --git a/src/lib.rs b/src/lib.rs
index 28de5889..2793182b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -418,6 +418,9 @@ impl Builder {
if self.options.enable_cxx_namespaces {
output_vector.push("--enable-cxx-namespaces".into());
}
+ if self.options.enable_function_attribute_detection {
+ output_vector.push("--enable-function-attribute-detection".into());
+ }
if self.options.disable_name_namespacing {
output_vector.push("--disable-name-namespacing".into());
}
@@ -1057,6 +1060,18 @@ impl Builder {
self
}
+ /// Enable detecting must_use attributes on C functions.
+ ///
+ /// This is quite slow in some cases (see #1465), so it's disabled by
+ /// default.
+ ///
+ /// Note that for this to do something meaningful for now at least, the rust
+ /// target version has to have support for `#[must_use]`.
+ pub fn enable_function_attribute_detection(mut self) -> Self {
+ self.options.enable_function_attribute_detection = true;
+ self
+ }
+
/// Disable name auto-namespacing.
///
/// By default, bindgen mangles names like `foo::bar::Baz` to look like
@@ -1391,6 +1406,10 @@ struct BindgenOptions {
/// generated bindings.
enable_cxx_namespaces: bool,
+ /// True if we should try to find unexposed attributes in functions, in
+ /// order to be able to generate #[must_use] attributes in Rust.
+ enable_function_attribute_detection: bool,
+
/// True if we should avoid mangling names with namespaces.
disable_name_namespacing: bool,
@@ -1618,6 +1637,7 @@ impl Default for BindgenOptions {
derive_partialeq: false,
derive_eq: false,
enable_cxx_namespaces: false,
+ enable_function_attribute_detection: false,
disable_name_namespacing: false,
use_core: false,
ctypes_prefix: None,
diff --git a/src/options.rs b/src/options.rs
index 3594be4e..9d37543a 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -315,6 +315,10 @@ where
.takes_value(true)
.multiple(true)
.number_of_values(1),
+ Arg::with_name("enable-function-attribute-detection")
+ .long("enable-function-attribute-detection")
+ .help("Enables detecting unexposed attributes in functions (slow).
+ Used to generate #[must_use] annotations."),
]) // .args()
.get_matches_from(args);
@@ -484,6 +488,10 @@ where
builder = builder.enable_cxx_namespaces();
}
+ if matches.is_present("enable-function-attribute-detection") {
+ builder = builder.enable_function_attribute_detection();
+ }
+
if matches.is_present("disable-name-namespacing") {
builder = builder.disable_name_namespacing();
}