Skip to content

lints: add #![forbid] lints per crate #375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ unreachable_pub = "deny"
unused_qualifications = "deny"
variant_size_differences = "deny"
non_camel_case_types = "deny"
unsafe_code = "deny"

# Hot
# unused_results = "deny"
Expand Down
4 changes: 4 additions & 0 deletions binaries/cuprated/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#![doc = include_str!("../README.md")]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![forbid(
unsafe_code,
reason = "Crate-specific lints. There should be good reasoning when removing these."
)]
#![allow(
unused_imports,
unreachable_pub,
Expand Down
7 changes: 7 additions & 0 deletions consensus/context/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
//! This is used during contextual validation, this does not have all the data for contextual validation
//! (outputs) for that you will need a [`Database`].

#![forbid(
clippy::should_panic_without_expect,
clippy::single_char_lifetime_names,
unsafe_code,
reason = "Crate-specific lints. There should be good reasoning when removing these."
)]

// Used in documentation references for [`BlockChainContextRequest`]
// FIXME: should we pull in a dependency just to link docs?
use monero_serai as _;
Expand Down
4 changes: 3 additions & 1 deletion consensus/fast-sync/src/fast_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ fn max_height() -> u64 {
(HASHES_OF_HASHES.len() * BATCH_SIZE) as u64
}

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub struct ValidBlockId(BlockId);

fn valid_block_ids(block_ids: &[BlockId]) -> Vec<ValidBlockId> {
block_ids.iter().map(|b| ValidBlockId(*b)).collect()
}

#[derive(Debug)]
#[expect(clippy::large_enum_variant)]
pub enum FastSyncRequest {
ValidateHashes {
Expand Down Expand Up @@ -110,6 +111,7 @@ impl From<tower::BoxError> for FastSyncError {
}
}

#[derive(Debug)]
pub struct FastSyncService<C> {
context_svc: C,
}
Expand Down
11 changes: 11 additions & 0 deletions consensus/fast-sync/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
#![forbid(
clippy::missing_assert_message,
clippy::should_panic_without_expect,
clippy::single_char_lifetime_names,
unsafe_code,
unused_results,
missing_copy_implementations,
missing_debug_implementations,
reason = "Crate-specific lints. There should be good reasoning when removing these."
)]

// Used in `create.rs`
use clap as _;
use cuprate_blockchain as _;
Expand Down
2 changes: 1 addition & 1 deletion consensus/rules/src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ fn check_txs_unique(txs: &[[u8; 32]]) -> Result<(), BlockError> {

/// This struct contains the data needed to verify a block, implementers MUST make sure
/// the data in this struct is calculated correctly.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Copy)]
pub struct ContextToVerifyBlock {
/// ref: <https://monero-book.cuprate.org/consensus_rules/blocks/weights.html#median-weight-for-coinbase-checks>
pub median_weight_for_block_reward: usize,
Expand Down
7 changes: 7 additions & 0 deletions consensus/rules/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#![forbid(
unsafe_code,
missing_copy_implementations,
missing_debug_implementations,
reason = "Crate-specific lints. There should be good reasoning when removing these."
)]

cfg_if::cfg_if! {
// Used in external `tests/`.
if #[cfg(test)] {
Expand Down
6 changes: 6 additions & 0 deletions consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
//! with [`BlockchainResponse`].
//!

#![forbid(
unsafe_code,
missing_copy_implementations,
reason = "Crate-specific lints. There should be good reasoning when removing these."
)]

cfg_if::cfg_if! {
// Used in external `tests/`.
if #[cfg(test)] {
Expand Down
15 changes: 14 additions & 1 deletion constants/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
#![doc = include_str!("../README.md")]
#![deny(missing_docs, reason = "all constants should document what they are")]
#![forbid(
clippy::missing_assert_message,
clippy::missing_docs_in_private_items,
clippy::missing_errors_doc,
clippy::missing_panics_doc,
clippy::should_panic_without_expect,
clippy::single_char_lifetime_names,
missing_docs,
unsafe_code,
unused_results,
missing_copy_implementations,
missing_debug_implementations,
reason = "Crate-specific lints. There should be good reasoning when removing these."
)]
Comment on lines +2 to +15
Copy link
Contributor Author

@hinto-janai hinto-janai Jan 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the full list of lints, all other crates have some subset of this. Only a few allow unsafe_code, I will list them:

#![no_std] // This can be removed if we eventually need `std`.

mod macros;
Expand Down
2 changes: 2 additions & 0 deletions constants/src/macros.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! General macros.

/// Output a string link to `monerod` source code.
#[allow(
clippy::allow_attributes,
Expand Down
12 changes: 12 additions & 0 deletions cryptonight/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
#![forbid(
clippy::missing_errors_doc,
clippy::missing_panics_doc,
clippy::should_panic_without_expect,
clippy::single_char_lifetime_names,
unsafe_code,
missing_copy_implementations,
missing_debug_implementations,
reason = "Crate-specific lints. There should be good reasoning when removing these."
)]

mod blake256;
mod cnaes;
mod hash_v2;
Expand All @@ -18,6 +29,7 @@ pub struct DataCanNotBeHashed;

/// Calculates the `CryptoNight` v1 hash of buf.
///
/// # Errors
/// This will return an error if buf is less than 43 bytes.
pub fn cryptonight_hash_v1(buf: &[u8]) -> Result<[u8; 32], DataCanNotBeHashed> {
if buf.len() < 43 {
Expand Down
5 changes: 5 additions & 0 deletions helper/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#![doc = include_str!("../README.md")]
#![cfg_attr(not(feature = "std"), no_std)]
#![forbid(
clippy::should_panic_without_expect,
clippy::single_char_lifetime_names,
reason = "Crate-specific lints. There should be good reasoning when removing these."
)]

//---------------------------------------------------------------------------------------------------- Public API
#[cfg(feature = "asynch")]
Expand Down
1 change: 1 addition & 0 deletions helper/src/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ impl_thread_percent! {
///
/// On macOS and *BSD: +20
/// On Linux: +19
#[expect(unsafe_code, reason = "Must call C")]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cuprate_helper uses unsafe 1 time here.

pub fn low_priority_thread() {
#[cfg(target_os = "windows")]
{
Expand Down
7 changes: 7 additions & 0 deletions net/epee-encoding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@
//!
//! ```

#![forbid(
clippy::missing_assert_message,
clippy::should_panic_without_expect,
unsafe_code,
reason = "Crate-specific lints. There should be good reasoning when removing these."
)]

#[cfg(test)]
use hex as _;

Expand Down
10 changes: 10 additions & 0 deletions net/fixed-bytes/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
#![doc = include_str!("../README.md")]
#![forbid(
clippy::missing_assert_message,
clippy::missing_errors_doc,
clippy::missing_panics_doc,
clippy::should_panic_without_expect,
clippy::single_char_lifetime_names,
unsafe_code,
missing_debug_implementations,
reason = "Crate-specific lints. There should be good reasoning when removing these."
)]

use core::{
fmt::{Debug, Formatter},
Expand Down
8 changes: 7 additions & 1 deletion net/levin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
//! This project is licensed under the MIT License.

// Coding conventions
#![forbid(unsafe_code)]
#![forbid(
clippy::missing_assert_message,
clippy::should_panic_without_expect,
unsafe_code,
unused_results,
reason = "Crate-specific lints. There should be good reasoning when removing these."
)]
#![deny(non_upper_case_globals)]
#![deny(non_camel_case_types)]
#![deny(unused_mut)]
Expand Down
8 changes: 8 additions & 0 deletions net/wire/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
//!
//! This project is licensed under the MIT License.

#![forbid(
clippy::missing_assert_message,
clippy::missing_panics_doc,
clippy::should_panic_without_expect,
unsafe_code,
reason = "Crate-specific lints. There should be good reasoning when removing these."
)]

pub mod network_address;
pub mod p2p;

Expand Down
9 changes: 9 additions & 0 deletions p2p/address-book/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
//! clear net peers getting linked to their dark counterparts
//! and so peers will only get told about peers they can
//! connect to.

#![forbid(
clippy::missing_assert_message,
clippy::should_panic_without_expect,
missing_docs,
unsafe_code,
reason = "Crate-specific lints. There should be good reasoning when removing these."
)]

use std::{io::ErrorKind, path::PathBuf, time::Duration};

use cuprate_p2p_core::{NetZoneAddress, NetworkZone};
Expand Down
9 changes: 9 additions & 0 deletions p2p/async-buffer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
//!
//! Weight is used to bound the channel, on creation you specify a max weight and for each value you
//! specify a weight.

#![forbid(
clippy::missing_errors_doc,
clippy::should_panic_without_expect,
unsafe_code,
missing_copy_implementations,
reason = "Crate-specific lints. There should be good reasoning when removing these."
)]

use std::{
cmp::min,
future::Future,
Expand Down
16 changes: 14 additions & 2 deletions p2p/bucket/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,23 @@
//!
//! ```

use arrayvec::{ArrayVec, CapacityError};
use rand::random;
#![forbid(
clippy::missing_assert_message,
clippy::missing_docs_in_private_items,
clippy::missing_errors_doc,
clippy::should_panic_without_expect,
clippy::single_char_lifetime_names,
missing_docs,
unsafe_code,
missing_copy_implementations,
reason = "Crate-specific lints. There should be good reasoning when removing these."
)]

use std::{collections::BTreeMap, net::Ipv4Addr};

use arrayvec::{ArrayVec, CapacityError};
use rand::random;

/// A discriminant that can be computed from the type.
pub trait Bucketable: Sized + Eq + Clone {
/// The type of the discriminant being used in the Binary tree.
Expand Down
11 changes: 11 additions & 0 deletions p2p/dandelion-tower/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@
//! When removing data, for example because of a new block, you can remove from both pools provided it doesn't leak
//! any data about stem transactions. You will probably want to set up a task that monitors the tx pool for stuck transactions,
//! transactions that slipped in just as one was removed etc, this crate does not handle that.

#![forbid(
clippy::missing_assert_message,
clippy::missing_errors_doc,
clippy::should_panic_without_expect,
clippy::single_char_lifetime_names,
unsafe_code,
missing_copy_implementations,
reason = "Crate-specific lints. There should be good reasoning when removing these."
)]

mod config;
#[cfg(feature = "txpool")]
pub mod pool;
Expand Down
8 changes: 8 additions & 0 deletions p2p/p2p-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@
//! # });
//! ```

#![forbid(
clippy::missing_assert_message,
clippy::should_panic_without_expect,
clippy::single_char_lifetime_names,
unsafe_code,
reason = "Crate-specific lints. There should be good reasoning when removing these."
)]

cfg_if::cfg_if! {
// Used in `tests/`
if #[cfg(test)] {
Expand Down
10 changes: 10 additions & 0 deletions p2p/p2p/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
//!
//! This crate contains a [`NetworkInterface`] which allows interacting with the Monero P2P network on
//! a certain [`NetworkZone`]

#![forbid(
clippy::missing_assert_message,
clippy::missing_errors_doc,
clippy::should_panic_without_expect,
clippy::single_char_lifetime_names,
unsafe_code,
reason = "Crate-specific lints. There should be good reasoning when removing these."
)]

use std::sync::Arc;

use futures::FutureExt;
Expand Down
10 changes: 10 additions & 0 deletions pruning/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@
//! ```
//!

#![forbid(
clippy::missing_assert_message,
clippy::should_panic_without_expect,
clippy::single_char_lifetime_names,
unsafe_code,
unused_results,
missing_debug_implementations,
reason = "Crate-specific lints. There should be good reasoning when removing these."
)]

use std::cmp::Ordering;

use cuprate_constants::block::MAX_BLOCK_HEIGHT_USIZE;
Expand Down
14 changes: 14 additions & 0 deletions rpc/interface/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
#![doc = include_str!("../README.md")]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![forbid(
clippy::missing_assert_message,
clippy::missing_docs_in_private_items,
clippy::missing_errors_doc,
clippy::missing_panics_doc,
clippy::should_panic_without_expect,
clippy::single_char_lifetime_names,
missing_docs,
unsafe_code,
unused_results,
missing_copy_implementations,
missing_debug_implementations,
reason = "Crate-specific lints. There should be good reasoning when removing these."
)]

mod route;
mod router_builder;
Expand Down
2 changes: 1 addition & 1 deletion rpc/interface/src/router_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ macro_rules! generate_router_builder {
/// .all()
/// .build();
/// ```
#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct RouterBuilder<H: RpcHandler> {
router: Router<H>,
}
Expand Down
2 changes: 1 addition & 1 deletion rpc/interface/src/rpc_handler_dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::rpc_handler::RpcHandler;
///
/// This is mostly used for testing purposes and can
/// be disabled by disable the `dummy` feature flag.
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub struct RpcHandlerDummy {
/// Should this RPC server be [restricted](RpcHandler::restricted)?
Expand Down
Loading
Loading