Skip to content

Create and apply a pattern for #[must_use] #74

Description

@ounsworth

Summary

Rust Lang has an attribute #[must_use]

#[must_use]
fn use_me1() -> u8 { 0 }

#[must_use = "explanation of why it should be used"]
fn use_me2() -> u8 { 0 }
#[must_use]
fn f() {}
f(); // ERROR: Unused return value that must be used.

https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute

Scope

The scope of this ticket is to crawl over all public APIs of the bc-rust library and tag any where ignoring a return value could lead to bugs or vulnerabilities. This is probably particularly relevant on functions of the form -> Result<(), Error>, or -> Result<usize, Error>; it might not be necessary to handle the () or usize, but we should use #[must_use] to force the caller to check for an error.

We should come up with a guideline for when a function should be tagged, and document this in QUALITY_AND_STYLE.md.

Acceptance Criteria

  • Usage guidance for #[must_use] has been written in QUALITY_AND_STYLE.md.
  • This guidance has been applied consistently across the library.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationrefactorThis task is primarily about performing a code refactor

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions