Skip to content

Commit

Permalink
lints: opt in manual lint crates (#263)
Browse files Browse the repository at this point in the history
* cargo.toml: transfer existing lints

* rpc/interface: lints

* rpc/json-rpc: lints

* rpc/types: lints

* storage/blockchain: lints

* rpc/types: fix lints

* cargo.toml: fix lint group priority

* storage/blockchain: fix lints

* fix misc lints

* storage/database: fixes

* storage/txpool: opt in lints + fixes

* types: opt in + fixes

* helper: opt in + fixes

* types: remove borsh

* rpc/interface: fix test

* test fixes

* database: fix lints

* fix lint

* tabs -> spaces

* blockchain: `config/` -> `config.rs`
  • Loading branch information
hinto-janai authored Sep 2, 2024
1 parent b837d35 commit eead49b
Show file tree
Hide file tree
Showing 45 changed files with 241 additions and 743 deletions.
44 changes: 28 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,15 @@ upper_case_acronyms = "deny"
# allow_attributes_without_reason = "deny"
# missing_assert_message = "deny"
# missing_docs_in_private_items = "deny"
# undocumented_unsafe_blocks = "deny"
undocumented_unsafe_blocks = "deny"
# multiple_unsafe_ops_per_block = "deny"
# single_char_lifetime_names = "deny"
# wildcard_enum_match_arm = "deny"

[workspace.lints.rust]
# Cold
future_incompatible = { level = "deny", priority = -1 }
nonstandard_style = { level = "deny", priority = -1 }
absolute_paths_not_starting_with_crate = "deny"
explicit_outlives_requirements = "deny"
keyword_idents_2018 = "deny"
Expand All @@ -306,7 +308,7 @@ ambiguous_glob_imports = "deny"
unused_unsafe = "deny"

# Warm
let_underscore_drop = "deny"
let_underscore = { level = "deny", priority = -1 }
unreachable_pub = "deny"
unused_qualifications = "deny"
variant_size_differences = "deny"
Expand Down
3 changes: 3 additions & 0 deletions helper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ target_os_lib = { package = "libc", version = "0.2.151", optional = true }

[dev-dependencies]
tokio = { workspace = true, features = ["full"] }

[lints]
workspace = true
8 changes: 4 additions & 4 deletions helper/src/asynch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct InfallibleOneshotReceiver<T>(oneshot::Receiver<T>);

impl<T> From<oneshot::Receiver<T>> for InfallibleOneshotReceiver<T> {
fn from(value: oneshot::Receiver<T>) -> Self {
InfallibleOneshotReceiver(value)
Self(value)
}
}

Expand All @@ -43,7 +43,7 @@ where
{
let (tx, rx) = oneshot::channel();
rayon::spawn(move || {
let _ = tx.send(f());
drop(tx.send(f()));
});
rx.await.expect("The sender must not be dropped")
}
Expand All @@ -62,7 +62,7 @@ mod test {
#[tokio::test]
// Assert that basic channel operations work.
async fn infallible_oneshot_receiver() {
let (tx, rx) = futures::channel::oneshot::channel::<String>();
let (tx, rx) = oneshot::channel::<String>();
let msg = "hello world!".to_string();

tx.send(msg.clone()).unwrap();
Expand All @@ -84,7 +84,7 @@ mod test {
let barrier = Arc::new(Barrier::new(2));
let task = |barrier: &Barrier| barrier.wait();

let b_2 = barrier.clone();
let b_2 = Arc::clone(&barrier);

let (tx, rx) = std::sync::mpsc::channel();

Expand Down
2 changes: 2 additions & 0 deletions helper/src/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ pub type AtomicF64 = AtomicCell<f64>;
//---------------------------------------------------------------------------------------------------- TESTS
#[cfg(test)]
mod tests {
#![allow(clippy::float_cmp)]

use super::*;

#[test]
Expand Down
91 changes: 30 additions & 61 deletions helper/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,72 +190,41 @@ mod test {
// - It must `ends_with()` the expected end PATH for the OS
#[test]
fn path_sanity_check() {
assert!(CUPRATE_CACHE_DIR.is_absolute());
assert!(CUPRATE_CONFIG_DIR.is_absolute());
assert!(CUPRATE_DATA_DIR.is_absolute());
assert!(CUPRATE_BLOCKCHAIN_DIR.is_absolute());
// Array of (PATH, expected_path_as_string).
//
// The different OS's will set the expected path below.
let mut array = [
(&*CUPRATE_CACHE_DIR, ""),
(&*CUPRATE_CONFIG_DIR, ""),
(&*CUPRATE_DATA_DIR, ""),
(&*CUPRATE_BLOCKCHAIN_DIR, ""),
(&*CUPRATE_TXPOOL_DIR, ""),
];

if cfg!(target_os = "windows") {
let dir = &*CUPRATE_CACHE_DIR;
println!("cuprate_cache_dir: {dir:?}");
assert!(dir.ends_with(r"AppData\Local\Cuprate"));

let dir = &*CUPRATE_CONFIG_DIR;
println!("cuprate_config_dir: {dir:?}");
assert!(dir.ends_with(r"AppData\Roaming\Cuprate"));

let dir = &*CUPRATE_DATA_DIR;
println!("cuprate_data_dir: {dir:?}");
assert!(dir.ends_with(r"AppData\Roaming\Cuprate"));

let dir = &*CUPRATE_BLOCKCHAIN_DIR;
println!("cuprate_blockchain_dir: {dir:?}");
assert!(dir.ends_with(r"AppData\Roaming\Cuprate\blockchain"));

let dir = &*CUPRATE_TXPOOL_DIR;
println!("cuprate_txpool_dir: {dir:?}");
assert!(dir.ends_with(r"AppData\Roaming\Cuprate\txpool"));
array[0].1 = r"AppData\Local\Cuprate";
array[1].1 = r"AppData\Roaming\Cuprate";
array[2].1 = r"AppData\Roaming\Cuprate";
array[3].1 = r"AppData\Roaming\Cuprate\blockchain";
array[4].1 = r"AppData\Roaming\Cuprate\txpool";
} else if cfg!(target_os = "macos") {
let dir = &*CUPRATE_CACHE_DIR;
println!("cuprate_cache_dir: {dir:?}");
assert!(dir.ends_with("Library/Caches/Cuprate"));

let dir = &*CUPRATE_CONFIG_DIR;
println!("cuprate_config_dir: {dir:?}");
assert!(dir.ends_with("Library/Application Support/Cuprate"));

let dir = &*CUPRATE_DATA_DIR;
println!("cuprate_data_dir: {dir:?}");
assert!(dir.ends_with("Library/Application Support/Cuprate"));

let dir = &*CUPRATE_BLOCKCHAIN_DIR;
println!("cuprate_blockchain_dir: {dir:?}");
assert!(dir.ends_with("Library/Application Support/Cuprate/blockchain"));

let dir = &*CUPRATE_TXPOOL_DIR;
println!("cuprate_txpool_dir: {dir:?}");
assert!(dir.ends_with("Library/Application Support/Cuprate/txpool"));
array[0].1 = "Library/Caches/Cuprate";
array[1].1 = "Library/Application Support/Cuprate";
array[2].1 = "Library/Application Support/Cuprate";
array[3].1 = "Library/Application Support/Cuprate/blockchain";
array[4].1 = "Library/Application Support/Cuprate/txpool";
} else {
// Assumes Linux.
let dir = &*CUPRATE_CACHE_DIR;
println!("cuprate_cache_dir: {dir:?}");
assert!(dir.ends_with(".cache/cuprate"));

let dir = &*CUPRATE_CONFIG_DIR;
println!("cuprate_config_dir: {dir:?}");
assert!(dir.ends_with(".config/cuprate"));

let dir = &*CUPRATE_DATA_DIR;
println!("cuprate_data_dir: {dir:?}");
assert!(dir.ends_with(".local/share/cuprate"));

let dir = &*CUPRATE_BLOCKCHAIN_DIR;
println!("cuprate_blockchain_dir: {dir:?}");
assert!(dir.ends_with(".local/share/cuprate/blockchain"));

let dir = &*CUPRATE_TXPOOL_DIR;
println!("cuprate_txpool_dir: {dir:?}");
assert!(dir.ends_with(".local/share/cuprate/txpool"));
array[0].1 = ".cache/cuprate";
array[1].1 = ".config/cuprate";
array[2].1 = ".local/share/cuprate";
array[3].1 = ".local/share/cuprate/blockchain";
array[4].1 = ".local/share/cuprate/txpool";
};

for (path, expected) in array {
assert!(path.is_absolute());
assert!(path.ends_with(expected));
}
}
}
32 changes: 0 additions & 32 deletions helper/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,4 @@
#![doc = include_str!("../README.md")]
//---------------------------------------------------------------------------------------------------- Lints
#![allow(clippy::len_zero, clippy::type_complexity, clippy::module_inception)]
#![deny(nonstandard_style, deprecated, missing_docs, unused_mut)]
#![forbid(
unused_unsafe,
future_incompatible,
break_with_label_and_loop,
coherence_leak_check,
duplicate_macro_attributes,
exported_private_dependencies,
for_loops_over_fallibles,
large_assignments,
overlapping_range_endpoints,
// private_in_public,
semicolon_in_expressions_from_macros,
redundant_semicolons,
unconditional_recursion,
unreachable_patterns,
unused_allocation,
unused_braces,
unused_comparisons,
unused_doc_comments,
unused_parens,
unused_labels,
while_true,
keyword_idents,
non_ascii_idents,
noop_method_call,
unreachable_pub,
single_use_lifetimes,
// variant_size_differences,
)]
#![cfg_attr(not(feature = "std"), no_std)]

//---------------------------------------------------------------------------------------------------- Public API
Expand Down
3 changes: 2 additions & 1 deletion helper/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use crate::cast::{u64_to_usize, usize_to_u64};
/// ```
#[inline]
pub const fn split_u128_into_low_high_bits(value: u128) -> (u64, u64) {
#[allow(clippy::cast_possible_truncation)]
(value as u64, (value >> 64) as u64)
}

Expand Down Expand Up @@ -60,7 +61,7 @@ pub const fn combine_low_high_bits_to_u128(low_bits: u64, high_bits: u64) -> u12
/// Map a [`u64`] to a [`Timelock`].
///
/// Height/time is not differentiated via type, but rather:
/// "height is any value less than 500_000_000 and timestamp is any value above"
/// "height is any value less than `500_000_000` and timestamp is any value above"
/// so the `u64/usize` is stored without any tag.
///
/// See [`timelock_to_u64`] for the inverse function.
Expand Down
8 changes: 4 additions & 4 deletions helper/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ pub enum Network {

impl Network {
/// Returns the network ID for the current network.
pub fn network_id(&self) -> [u8; 16] {
pub const fn network_id(&self) -> [u8; 16] {
match self {
Network::Mainnet => MAINNET_NETWORK_ID,
Network::Testnet => TESTNET_NETWORK_ID,
Network::Stagenet => STAGENET_NETWORK_ID,
Self::Mainnet => MAINNET_NETWORK_ID,
Self::Testnet => TESTNET_NETWORK_ID,
Self::Stagenet => STAGENET_NETWORK_ID,
}
}
}
3 changes: 2 additions & 1 deletion helper/src/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ where
/// assert_eq!(median(vec), 5);
/// ```
///
/// # Safety
/// # Invariant
/// If not sorted the output will be invalid.
#[allow(clippy::debug_assert_with_mut_call)]
pub fn median<T>(array: impl AsRef<[T]>) -> T
where
T: Add<Output = T>
Expand Down
Loading

0 comments on commit eead49b

Please sign in to comment.