-
Notifications
You must be signed in to change notification settings - Fork 390
Closed
Milestone
Description
#[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!
webmaster128