units: Add pedantic lint return_self_not_must_use

As part of the effort to polish the `units` create ready for the 1.0
release; enable the pedantic lint `return_self_not_must_use`.
This commit is contained in:
Tobin C. Harding 2024-12-09 08:57:46 +11:00
parent e7efdd7c42
commit 79a229b391
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
4 changed files with 8 additions and 0 deletions

View File

@ -527,6 +527,7 @@ pub struct Display {
impl Display { impl Display {
/// Makes subsequent calls to `Display::fmt` display denomination. /// Makes subsequent calls to `Display::fmt` display denomination.
#[must_use]
pub fn show_denomination(mut self) -> Self { pub fn show_denomination(mut self) -> Self {
match &mut self.style { match &mut self.style {
DisplayStyle::FixedDenomination { show_denomination, .. } => *show_denomination = true, DisplayStyle::FixedDenomination { show_denomination, .. } => *show_denomination = true,

View File

@ -206,6 +206,7 @@ impl SignedAmount {
// Some arithmetic that doesn't fit in [`core::ops`] traits. // Some arithmetic that doesn't fit in [`core::ops`] traits.
/// Get the absolute value of this [`SignedAmount`]. /// Get the absolute value of this [`SignedAmount`].
#[must_use]
pub fn abs(self) -> SignedAmount { SignedAmount(self.0.abs()) } pub fn abs(self) -> SignedAmount { SignedAmount(self.0.abs()) }
/// Gets the absolute value of this [`SignedAmount`] returning [`Amount`]. /// Gets the absolute value of this [`SignedAmount`] returning [`Amount`].
@ -307,6 +308,7 @@ impl SignedAmount {
/// # Panics /// # Panics
/// ///
/// On overflow, panics in debug mode, wraps in release mode. /// On overflow, panics in debug mode, wraps in release mode.
#[must_use]
pub fn unchecked_add(self, rhs: SignedAmount) -> SignedAmount { Self(self.0 + rhs.0) } pub fn unchecked_add(self, rhs: SignedAmount) -> SignedAmount { Self(self.0 + rhs.0) }
/// Unchecked subtraction. /// Unchecked subtraction.
@ -316,6 +318,7 @@ impl SignedAmount {
/// # Panics /// # Panics
/// ///
/// On overflow, panics in debug mode, wraps in release mode. /// On overflow, panics in debug mode, wraps in release mode.
#[must_use]
pub fn unchecked_sub(self, rhs: SignedAmount) -> SignedAmount { Self(self.0 - rhs.0) } pub fn unchecked_sub(self, rhs: SignedAmount) -> SignedAmount { Self(self.0 - rhs.0) }
/// Subtraction that doesn't allow negative [`SignedAmount`]s. /// Subtraction that doesn't allow negative [`SignedAmount`]s.

View File

@ -318,6 +318,7 @@ impl Amount {
/// # Panics /// # Panics
/// ///
/// On overflow, panics in debug mode, wraps in release mode. /// On overflow, panics in debug mode, wraps in release mode.
#[must_use]
pub fn unchecked_add(self, rhs: Amount) -> Amount { Self(self.0 + rhs.0) } pub fn unchecked_add(self, rhs: Amount) -> Amount { Self(self.0 + rhs.0) }
/// Unchecked subtraction. /// Unchecked subtraction.
@ -327,6 +328,7 @@ impl Amount {
/// # Panics /// # Panics
/// ///
/// On overflow, panics in debug mode, wraps in release mode. /// On overflow, panics in debug mode, wraps in release mode.
#[must_use]
pub fn unchecked_sub(self, rhs: Amount) -> Amount { Self(self.0 - rhs.0) } pub fn unchecked_sub(self, rhs: Amount) -> Amount { Self(self.0 - rhs.0) }
/// Converts to a signed amount. /// Converts to a signed amount.

View File

@ -11,6 +11,8 @@
#![warn(missing_docs)] #![warn(missing_docs)]
#![warn(deprecated_in_future)] #![warn(deprecated_in_future)]
#![doc(test(attr(warn(unused))))] #![doc(test(attr(warn(unused))))]
// Pedantic lints that we enforce.
#![warn(clippy::return_self_not_must_use)]
// Exclude lints we don't think are valuable. // Exclude lints we don't think are valuable.
#![allow(clippy::needless_question_mark)] // https://github.com/rust-bitcoin/rust-bitcoin/pull/2134 #![allow(clippy::needless_question_mark)] // https://github.com/rust-bitcoin/rust-bitcoin/pull/2134
#![allow(clippy::manual_range_contains)] // More readable than clippy's format. #![allow(clippy::manual_range_contains)] // More readable than clippy's format.