Skip to content

#[must_use] is missing on many methods #1609

@0xForerunner

Description

@0xForerunner

#[must_use] tells the compiler that the output of a particular function must be used, and that not using it is a bug. A perfect example of where this belongs is:

    // This is a great place for #[must_use]
    pub fn saturating_sub(self, other: Self) -> Self {
        Self(self.0.saturating_sub(other.0))
    }

This rust code is currently valid and gives no warnings

let a = Uint256::one();
let mut b = Uint256::from(2u128);
b += a;
b.saturating_sub(a);
println("{}", b.to_string());

A user might wrongly assume that saturating_sub is modifying b, when it is not. (Ask me how I know haha). This fix should be pretty easy to implement!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions