Skip to content

Generate #[must_use] on functions annotated with __attribute__((warn_unused_result)) #1450

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

Closed
flowbish opened this issue Nov 26, 2018 · 2 comments

Comments

@flowbish
Copy link
Contributor

As annotating #[must_use] on functions was stabilized in 1.27, it should be possible to automatically carry the __attribute__((warn_unused_result)) attribute from C/C++ into rust with #[must_use]. This will then require a --rust-target option of 1.27 to allow generation of this code.

Input C/C++ Header

__attribute__((warn_unused_result))
int foo(int);

Actual Results

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

Expected Results

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

emilio commented Nov 26, 2018

Yeah, I agree this would be useful. Generally we have a very hard time getting attributes from libclang, but I'd have to check how the libclang AST looks like in that test-case.

@emilio
Copy link
Contributor

emilio commented Nov 27, 2018

Fixed by #1451, thanks a lot @flowbish!

@emilio emilio closed this as completed Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants