Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement __attribute__((__warn_unused_result__)) #2149

Closed
jethrogb opened this issue Jan 6, 2022 · 3 comments
Closed

Implement __attribute__((__warn_unused_result__)) #2149

jethrogb opened this issue Jan 6, 2022 · 3 comments

Comments

@jethrogb
Copy link
Contributor

jethrogb commented Jan 6, 2022

Input C/C++ Header

__attribute__((__warn_unused_result__)) int f();

Bindgen Invocation

$ bindgen input.h

Actual Results

/* automatically generated by rust-bindgen 0.59.2 */

extern "C" {
    pub fn f() -> ::std::os::raw::c_int;
}

Expected Results

/* automatically generated by rust-bindgen 0.59.2 */

extern "C" {
    #[must_use] pub fn f() -> ::std::os::raw::c_int;
}
@emilio
Copy link
Contributor

emilio commented Jan 29, 2022

Hmm, we're supposed to have some support for this, see tests/expectations/tests/attribute_warn_unused_result.rs

@emilio
Copy link
Contributor

emilio commented Jan 29, 2022

We have this behind the --enable-function-attribute-detection, because it is expensive to detect unfortunately, but we do support this.

@emilio emilio closed this as completed Jan 29, 2022
@jethrogb
Copy link
Contributor Author

jethrogb commented Feb 7, 2022

Would it be ok to filter this through the ParseCallbacks to avoid calling it unnecessarily?

MihirLuthra added a commit to fortanix/rust-mbedtls that referenced this issue Feb 7, 2022
Although, bindgen needs .enable_function_attribute_detection()
to process __attribute__((__warn_unused_result__)) because parsing
attrs can be really slow in certain cases. Benches were performed
to confirm our case doesn't face that issue.

References:
rust-lang/rust-bindgen#2149
rust-lang/rust-bindgen#1465
rust-lang/rust-bindgen#1466
rust-lang/rust-bindgen#1467
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants