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

Add must_use attributes and enable clippy::must-use-candidate #232

Merged
merged 1 commit into from
Dec 9, 2021

Conversation

edmorley
Copy link
Member

@edmorley edmorley commented Dec 8, 2021

If a semicolon discards the result of a function or method tagged with #[must_use], the compiler will emit a lint message warning that the return value is expected to be used.

This lint suggests adding #[must_use] to public functions that:

  • return something that's not already marked as must_use
  • have no mutable reference args (having a mutable owned arg is fine, since as the method took ownership, the caller can only access the result via the returned self, so it therefore still must be used)
  • don't mutate statics

Docs:
https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute
https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate

For more on best practices of when to use must_use, see:
rust-lang/rust#48926 (comment)

Fixes #57.
GUS-W-10222390.

If a semicolon discards the result of a function or method tagged with
`#[must_use]`, the compiler will emit a lint message warning that the
return value is expected to be used. 

This lint suggests adding `#[must_use]` to public functions that:
- return something that's not already marked as `must_use`
- have no mutable *reference* args (having a mutable owned arg is fine,
  since as the method took ownership, the caller can only access the result
  via the returned self, so it therefore still must be used)
- don't mutate statics

Docs:
https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute
https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate

For more on best practices of when to use `must_use`, see:
rust-lang/rust#48926 (comment)

Fixes #57.
GUS-W-10222390.
@edmorley edmorley self-assigned this Dec 8, 2021
@edmorley edmorley requested a review from Malax December 8, 2021 20:42
@edmorley edmorley merged commit 930bd2a into main Dec 9, 2021
@edmorley edmorley deleted the edmorley/clippy-must_use_candidate branch December 9, 2021 08:53
@edmorley edmorley added this to the libcnb 0.5.0 milestone Jan 13, 2022
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.

Fix clippy::must-use-candidate warnings
2 participants