Skip to content

Add #[must_use] to functions annotated with __attribute__((warn_unused_result)) #1451

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

Merged
merged 1 commit into from
Nov 27, 2018

Conversation

flowbish
Copy link
Contributor

First pass at implementing #1450. Take a look at the tests to see the behavior difference on rustc 1.27.

r? @emilio

@highfive
Copy link

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @emilio (or someone else) soon.

@highfive
Copy link

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!

Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you! Just some minor nits, looks good to go otherwise :)

@@ -387,6 +392,24 @@ impl FunctionSig {
}
};

let mut must_use = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move all this block to a function in clang.rs, probably a method of cursor?

Something like the following maybe:

pub fn has_simple_attr(&self, attr: &str) -> bool;

Then this code could just be:

let must_use = cursor.has_simple_attribute("warn_unused_result");

WDYT?

abi: Abi,
) -> Self {
FunctionSig {
return_type: return_type,
argument_types: arguments,
is_variadic: is_variadic,
must_use: must_use,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's pre-existing, but if you want this can just be must_use, (same for the other members).

@flowbish
Copy link
Contributor Author

Alright, pushed some changes to address your comments. Thanks for the quick review!

Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks amazing :)

return_type,
argument_types,
is_variadic,
must_use,
abi: abi,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could've done this for abi as well, but no big deal in any case :)

@emilio
Copy link
Contributor

emilio commented Nov 27, 2018

@bors-servo r+

@emilio
Copy link
Contributor

emilio commented Nov 27, 2018

Ah, forgot bors is still dead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants