Remove or fix unused variables and methods in docs
Examples in documentation are not linted in the same way as other code, but should still contain correctly written code. Throughout all of the crates except internals (another commit) unused variables have been prefixed with `_`, unused imports have been removed, and a warn attribute added to all of the `lib.rs` files.
This commit is contained in:
parent
ff6b1d4f19
commit
fd89ddf401
|
@ -14,6 +14,7 @@
|
|||
#![cfg_attr(all(not(test), not(feature = "std")), no_std)]
|
||||
// Experimental features we need.
|
||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
||||
#![doc(test(attr(warn(unused))))]
|
||||
// Coding conventions.
|
||||
#![warn(missing_docs)]
|
||||
// Exclude lints we don't think are valuable.
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#![cfg_attr(bench, feature(test))]
|
||||
// Coding conventions.
|
||||
#![warn(missing_docs)]
|
||||
#![doc(test(attr(warn(unused))))]
|
||||
// Instead of littering the codebase for non-fuzzing and bench code just globally allow.
|
||||
#![cfg_attr(fuzzing, allow(dead_code, unused_imports))]
|
||||
#![cfg_attr(bench, allow(dead_code, unused_imports))]
|
||||
|
|
|
@ -15,16 +15,14 @@
|
|||
//! use bitcoin_hashes::Sha256;
|
||||
//!
|
||||
//! let bytes = [0u8; 5];
|
||||
//! let hash_of_bytes = Sha256::hash(&bytes);
|
||||
//! let hash_of_string = Sha256::hash("some string".as_bytes());
|
||||
//! let _hash_of_bytes = Sha256::hash(&bytes);
|
||||
//! let _hash_of_string = Sha256::hash("some string".as_bytes());
|
||||
//! ```
|
||||
//!
|
||||
//!
|
||||
//! Hashing content from a reader:
|
||||
//!
|
||||
//! ```rust
|
||||
//! use bitcoin_hashes::Sha256;
|
||||
//!
|
||||
//! #[cfg(std)]
|
||||
//! # fn main() -> std::io::Result<()> {
|
||||
//! let mut reader: &[u8] = b"hello"; // in real code, this could be a `File` or `TcpStream`
|
||||
|
@ -42,9 +40,6 @@
|
|||
//! Hashing content by [`std::io::Write`] on `HashEngine`:
|
||||
//!
|
||||
//! ```rust
|
||||
//! use bitcoin_hashes::Sha256;
|
||||
//! use std::io::Write;
|
||||
//!
|
||||
//! #[cfg(std)]
|
||||
//! # fn main() -> std::io::Result<()> {
|
||||
//! let mut part1: &[u8] = b"hello";
|
||||
|
@ -68,6 +63,7 @@
|
|||
#![cfg_attr(bench, feature(test))]
|
||||
// Coding conventions.
|
||||
#![warn(missing_docs)]
|
||||
#![doc(test(attr(warn(unused))))]
|
||||
// Instead of littering the codebase for non-fuzzing and bench code just globally allow.
|
||||
#![cfg_attr(hashes_fuzz, allow(dead_code, unused_imports))]
|
||||
#![cfg_attr(bench, allow(dead_code, unused_imports))]
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
||||
// Coding conventions.
|
||||
#![warn(missing_docs)]
|
||||
#![doc(test(attr(warn(unused))))]
|
||||
// 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.
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
||||
// Coding conventions.
|
||||
#![warn(missing_docs)]
|
||||
#![doc(test(attr(warn(unused))))]
|
||||
// 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.
|
||||
|
|
|
@ -46,7 +46,7 @@ pub use units::locktime::absolute::*;
|
|||
/// # let n = LockTime::from_consensus(741521); // n OP_CHECKLOCKTIMEVERIFY
|
||||
/// # let lock_time = LockTime::from_consensus(741521); // nLockTime
|
||||
/// // To compare absolute lock times there are various `is_satisfied_*` methods, you may also use:
|
||||
/// let is_satisfied = match (n, lock_time) {
|
||||
/// let _is_satisfied = match (n, lock_time) {
|
||||
/// (Blocks(n), Blocks(lock_time)) => n <= lock_time,
|
||||
/// (Seconds(n), Seconds(lock_time)) => n <= lock_time,
|
||||
/// _ => panic!("handle invalid comparison error"),
|
||||
|
@ -108,7 +108,6 @@ impl LockTime {
|
|||
///
|
||||
/// ```rust
|
||||
/// # use bitcoin_primitives::absolute::LockTime;
|
||||
/// # let n = LockTime::from_consensus(741521); // n OP_CHECKLOCKTIMEVERIFY
|
||||
///
|
||||
/// // `from_consensus` roundtrips as expected with `to_consensus_u32`.
|
||||
/// let n_lock_time: u32 = 741521;
|
||||
|
@ -237,7 +236,7 @@ impl LockTime {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # use bitcoin_primitives::absolute::{LockTime, LockTime::*};
|
||||
/// # use bitcoin_primitives::absolute::LockTime;
|
||||
/// let lock_time = LockTime::from_consensus(741521);
|
||||
/// let check = LockTime::from_consensus(741521 + 1);
|
||||
/// assert!(lock_time.is_implied_by(check));
|
||||
|
@ -270,7 +269,7 @@ impl LockTime {
|
|||
/// # let n = LockTime::from_consensus(741521); // n OP_CHECKLOCKTIMEVERIFY
|
||||
/// # let lock_time = LockTime::from_consensus(741521 + 1); // nLockTime
|
||||
///
|
||||
/// let is_satisfied = match (n, lock_time) {
|
||||
/// let _is_satisfied = match (n, lock_time) {
|
||||
/// (Blocks(n), Blocks(lock_time)) => n <= lock_time,
|
||||
/// (Seconds(n), Seconds(lock_time)) => n <= lock_time,
|
||||
/// _ => panic!("invalid comparison"),
|
||||
|
|
|
@ -165,7 +165,7 @@ impl LockTime {
|
|||
///
|
||||
/// ```rust
|
||||
/// # use bitcoin_primitives::Sequence;
|
||||
/// # use bitcoin_primitives::locktime::relative::{LockTime, Height, Time};
|
||||
/// # use bitcoin_primitives::locktime::relative::{Height, Time};
|
||||
///
|
||||
/// # let required_height = 100; // 100 blocks.
|
||||
/// # let intervals = 70; // Approx 10 hours.
|
||||
|
@ -204,7 +204,6 @@ impl LockTime {
|
|||
///
|
||||
/// ```rust
|
||||
/// # use bitcoin_primitives::Sequence;
|
||||
/// # use bitcoin_primitives::locktime::relative::{LockTime, Height, Time};
|
||||
///
|
||||
/// # let required_height = 100; // 100 blocks.
|
||||
/// # let lock = Sequence::from_height(required_height).to_relative_lock_time().expect("valid height");
|
||||
|
@ -252,7 +251,7 @@ impl LockTime {
|
|||
///
|
||||
/// ```rust
|
||||
/// # use bitcoin_primitives::Sequence;
|
||||
/// # use bitcoin_primitives::locktime::relative::{LockTime, Height, Time};
|
||||
/// # use bitcoin_primitives::locktime::relative::Height;
|
||||
///
|
||||
/// let required_height: u16 = 100;
|
||||
/// let lock = Sequence::from_height(required_height).to_relative_lock_time().expect("valid height");
|
||||
|
@ -279,7 +278,7 @@ impl LockTime {
|
|||
///
|
||||
/// ```rust
|
||||
/// # use bitcoin_primitives::Sequence;
|
||||
/// # use bitcoin_primitives::locktime::relative::{LockTime, Height, Time};
|
||||
/// # use bitcoin_primitives::locktime::relative::Time;
|
||||
///
|
||||
/// let intervals: u16 = 70; // approx 10 hours;
|
||||
/// let lock = Sequence::from_512_second_intervals(intervals).to_relative_lock_time().expect("valid time");
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
||||
// Coding conventions.
|
||||
#![warn(missing_docs)]
|
||||
#![doc(test(attr(warn(unused))))]
|
||||
// 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.
|
||||
|
|
Loading…
Reference in New Issue