Merge rust-bitcoin/rust-bitcoin#3712: primitives: Add `must_use`

549be547ac primitives: Add must_use (Tobin C. Harding)

Pull request description:

  Enable lint `clippy::return_self_not_must_use` and add attribute `must_use` as required.

  Also run the linter with `clippy::must_use_candidate` enabled and manually check every warning site.

  Done as part of #3185

ACKs for top commit:
  apoelstra:
    ACK 549be547accdb13037bf3ef60310ca30d045dce0; successfully ran local tests; nice! will one-ACK merge
  sanket1729:
    ACK 549be547ac

Tree-SHA512: b22a6849fd0f4a7b65e1a9816efd47d411dcf2a5d5d46ae75b2b4d2389d3c9f46ab271314b112de9cd6fdc52cac7b53a632642e9bd90092d7065a8646e1362ec
This commit is contained in:
merge-script 2024-12-11 12:55:48 +00:00
commit 540c712dc7
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
6 changed files with 9 additions and 2 deletions

View File

@ -77,6 +77,7 @@ impl Block<Unchecked> {
/// Ignores block validation logic and just assumes you know what you are doing.
///
/// You should only use this function if you trust the block i.e., it comes from a trusted node.
#[must_use]
pub fn assume_checked(self, witness_root: Option<WitnessMerkleNode>) -> Block<Checked> {
Block {
header: self.header,

View File

@ -16,6 +16,9 @@
#![warn(missing_docs)]
#![warn(deprecated_in_future)]
#![doc(test(attr(warn(unused))))]
// Pedantic lints that we enforce.
// #![warn(clippy::must_use_candidate)]
#![warn(clippy::return_self_not_must_use)]
// Exclude lints we don't think are valuable.
#![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.

View File

@ -351,6 +351,7 @@ pub enum ClassifyContext {
impl Opcode {
/// Classifies an Opcode into a broad class.
#[inline]
#[must_use]
pub fn classify(self, ctx: ClassifyContext) -> Class {
match (self, ctx) {
// 3 opcodes illegal in all contexts
@ -424,6 +425,7 @@ impl Opcode {
///
/// Returns `None` if `self` is not a PUSHNUM.
#[inline]
#[must_use]
pub const fn decode_pushnum(self) -> Option<u8> {
const START: u8 = OP_PUSHNUM_1.code;
const END: u8 = OP_PUSHNUM_16.code;

View File

@ -115,7 +115,7 @@ impl Script {
pub fn is_empty(&self) -> bool { self.0.is_empty() }
/// Converts a [`Box<Script>`](Box) into a [`ScriptBuf`] without copying or allocating.
#[must_use = "`self` will be dropped if the result is not used"]
#[must_use]
pub fn into_script_buf(self: Box<Self>) -> ScriptBuf {
let rw = Box::into_raw(self) as *mut [u8];
// SAFETY: copied from `std`

View File

@ -48,7 +48,7 @@ impl ScriptBuf {
/// when they are equal. If you know beforehand that you need to create a script of exact size
/// use [`reserve_exact`](Self::reserve_exact) before adding data to the script so that the
/// reallocation can be avoided.
#[must_use = "`self` will be dropped if the result is not used"]
#[must_use]
#[inline]
pub fn into_boxed_script(self) -> Box<Script> {
// Copied from PathBuf::into_boxed_path

View File

@ -103,6 +103,7 @@ impl Witness {
pub fn is_empty(&self) -> bool { self.witness_elements == 0 }
/// Returns a struct implementing [`Iterator`].
#[must_use = "returned iterator should be used"]
pub fn iter(&self) -> Iter {
Iter { inner: self.content.as_slice(), indices_start: self.indices_start, current_index: 0 }
}