From a1f14f32e01d5e962fcd375bb31aeb3cd312236c Mon Sep 17 00:00:00 2001 From: teor Date: Mon, 24 Jan 2022 13:33:41 +1000 Subject: [PATCH 1/3] Move standard lints into .cargo/config.toml --- .cargo/config.toml | 12 ++++++++++++ .gitignore | 1 - tower-batch/src/lib.rs | 7 ------- tower-batch/tests/ed25519.rs | 6 ------ tower-batch/tests/worker.rs | 6 ------ tower-fallback/src/lib.rs | 7 ------- tower-fallback/tests/fallback.rs | 6 ------ zebra-chain/benches/block.rs | 6 +----- zebra-chain/benches/redpallas.rs | 3 ++- zebra-chain/build.rs | 5 +++++ zebra-chain/src/lib.rs | 6 ------ zebra-client/src/lib.rs | 6 ------ zebra-consensus/src/lib.rs | 7 ------- zebra-network/src/lib.rs | 6 ------ zebra-rpc/src/lib.rs | 6 ------ zebra-script/src/lib.rs | 12 ++++-------- zebra-state/build.rs | 5 +++++ zebra-state/src/lib.rs | 6 ------ zebra-state/tests/basic.rs | 6 ------ zebra-test/src/lib.rs | 6 ------ zebra-test/tests/command.rs | 6 ------ zebra-test/tests/transcript.rs | 6 ------ zebra-utils/src/bin/zebra-checkpoints/main.rs | 6 ------ zebra-utils/src/lib.rs | 6 ------ zebrad/build.rs | 5 +++++ zebrad/src/bin/zebrad/main.rs | 6 ------ zebrad/src/lib.rs | 6 ------ zebrad/tests/acceptance.rs | 6 ------ 28 files changed, 34 insertions(+), 138 deletions(-) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 00000000000..f418ba1e924 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,12 @@ + +[target.'cfg(all())'] +rustflags = [ + # Zebra standard lints for Rust 1.58+ + "-Dunsafe_code", + "-Drust_2021_compatibility", + "-Dclippy::await_holding_lock", + + "-Wmissing_docs", + + "-Aclippy::try_err", +] diff --git a/.gitignore b/.gitignore index 62d81cc249b..283a2e96a77 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,5 @@ # Vscode detrius .vscode/ .zebra-state/ -.cargo/ # Nix configs shell.nix diff --git a/tower-batch/src/lib.rs b/tower-batch/src/lib.rs index 6a6e1b88792..2cf9f770337 100644 --- a/tower-batch/src/lib.rs +++ b/tower-batch/src/lib.rs @@ -85,13 +85,6 @@ //! control logic, as it will receive explicit [`Flush`](BatchControl::Flush) //! requests from the wrapper. -// Standard lints -#![warn(missing_docs)] -#![allow(clippy::try_err)] -#![deny(clippy::await_holding_lock)] -#![deny(rust_2021_compatibility)] -#![forbid(unsafe_code)] - pub mod error; pub mod future; mod layer; diff --git a/tower-batch/tests/ed25519.rs b/tower-batch/tests/ed25519.rs index e96a4bec5a8..5906ad2a3f5 100644 --- a/tower-batch/tests/ed25519.rs +++ b/tower-batch/tests/ed25519.rs @@ -1,9 +1,3 @@ -// Standard lints -#![warn(missing_docs)] -#![allow(clippy::try_err)] -#![deny(clippy::await_holding_lock)] -#![forbid(unsafe_code)] - use std::{ future::Future, mem, diff --git a/tower-batch/tests/worker.rs b/tower-batch/tests/worker.rs index bc21209b633..7bec206b316 100644 --- a/tower-batch/tests/worker.rs +++ b/tower-batch/tests/worker.rs @@ -1,9 +1,3 @@ -// Standard lints -#![warn(missing_docs)] -#![allow(clippy::try_err)] -#![deny(clippy::await_holding_lock)] -#![forbid(unsafe_code)] - use std::time::Duration; use tokio_test::{assert_pending, assert_ready, assert_ready_err, task}; use tower::{Service, ServiceExt}; diff --git a/tower-fallback/src/lib.rs b/tower-fallback/src/lib.rs index 2cb4d20eb8a..01249d85bce 100644 --- a/tower-fallback/src/lib.rs +++ b/tower-fallback/src/lib.rs @@ -10,13 +10,6 @@ //! //! [aws-fallback]: https://aws.amazon.com/builders-library/avoiding-fallback-in-distributed-systems/ -// Standard lints -#![warn(missing_docs)] -#![allow(clippy::try_err)] -#![deny(clippy::await_holding_lock)] -#![deny(rust_2021_compatibility)] -#![forbid(unsafe_code)] - pub mod future; mod service; diff --git a/tower-fallback/tests/fallback.rs b/tower-fallback/tests/fallback.rs index 5ca1d3400a2..e84ab05f581 100644 --- a/tower-fallback/tests/fallback.rs +++ b/tower-fallback/tests/fallback.rs @@ -1,9 +1,3 @@ -// Standard lints -#![warn(missing_docs)] -#![allow(clippy::try_err)] -#![deny(clippy::await_holding_lock)] -#![forbid(unsafe_code)] - use tower::{service_fn, Service, ServiceExt}; use tower_fallback::Fallback; diff --git a/zebra-chain/benches/block.rs b/zebra-chain/benches/block.rs index cd9641cccd4..71194e1a614 100644 --- a/zebra-chain/benches/block.rs +++ b/zebra-chain/benches/block.rs @@ -1,9 +1,5 @@ -// Standard lints // Disabled due to warnings in criterion macros -//#![warn(missing_docs)] -#![allow(clippy::try_err)] -#![deny(clippy::await_holding_lock)] -#![forbid(unsafe_code)] +#![allow(missing_docs)] use std::io::Cursor; diff --git a/zebra-chain/benches/redpallas.rs b/zebra-chain/benches/redpallas.rs index 0160891d901..49fbf52217e 100644 --- a/zebra-chain/benches/redpallas.rs +++ b/zebra-chain/benches/redpallas.rs @@ -1,6 +1,7 @@ //! Benchmarks for batch verifiication of RedPallas signatures. -use std::convert::TryFrom; +// Disabled due to warnings in criterion macros +#![allow(missing_docs)] use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; use rand::{thread_rng, Rng}; diff --git a/zebra-chain/build.rs b/zebra-chain/build.rs index 91ba008f76c..77b5d3202e7 100644 --- a/zebra-chain/build.rs +++ b/zebra-chain/build.rs @@ -1,3 +1,8 @@ +//! Build script for zebra-chain. +//! +//! Turns the environmental variable `$TEST_FAKE_ACTIVATION_HEIGHTS` +//! into the Rust configuration `cfg(test_fake_activation_heights)`. + use std::env; fn main() { diff --git a/zebra-chain/src/lib.rs b/zebra-chain/src/lib.rs index 79d6a0056a6..848090abc8d 100644 --- a/zebra-chain/src/lib.rs +++ b/zebra-chain/src/lib.rs @@ -6,12 +6,6 @@ #![doc(html_favicon_url = "https://www.zfnd.org/images/zebra-favicon-128.png")] #![doc(html_logo_url = "https://www.zfnd.org/images/zebra-icon.png")] #![doc(html_root_url = "https://doc.zebra.zfnd.org/zebra_chain")] -// Standard lints -#![warn(missing_docs)] -#![allow(clippy::try_err)] -#![deny(clippy::await_holding_lock)] -#![deny(rust_2021_compatibility)] -#![forbid(unsafe_code)] // Required by bitvec! macro #![recursion_limit = "256"] diff --git a/zebra-client/src/lib.rs b/zebra-client/src/lib.rs index 298924110ea..d7d37127711 100644 --- a/zebra-client/src/lib.rs +++ b/zebra-client/src/lib.rs @@ -3,9 +3,3 @@ #![doc(html_favicon_url = "https://www.zfnd.org/images/zebra-favicon-128.png")] #![doc(html_logo_url = "https://www.zfnd.org/images/zebra-icon.png")] #![doc(html_root_url = "https://doc.zebra.zfnd.org/zebra_client")] -// Standard lints -#![warn(missing_docs)] -#![allow(clippy::try_err)] -#![deny(clippy::await_holding_lock)] -#![deny(rust_2021_compatibility)] -#![forbid(unsafe_code)] diff --git a/zebra-consensus/src/lib.rs b/zebra-consensus/src/lib.rs index 6d27f6787ea..86a0e0f9970 100644 --- a/zebra-consensus/src/lib.rs +++ b/zebra-consensus/src/lib.rs @@ -33,13 +33,6 @@ #![doc(html_favicon_url = "https://www.zfnd.org/images/zebra-favicon-128.png")] #![doc(html_logo_url = "https://www.zfnd.org/images/zebra-icon.png")] #![doc(html_root_url = "https://doc.zebra.zfnd.org/zebra_consensus")] -// Standard lints -// Warn on missing docs for all modules after cleaning the API surface -#![warn(missing_docs)] -#![allow(clippy::try_err)] -#![deny(clippy::await_holding_lock)] -#![deny(rust_2021_compatibility)] -#![forbid(unsafe_code)] mod block; mod checkpoint; diff --git a/zebra-network/src/lib.rs b/zebra-network/src/lib.rs index 02f69188235..fd547bb0db3 100644 --- a/zebra-network/src/lib.rs +++ b/zebra-network/src/lib.rs @@ -119,12 +119,6 @@ #![doc(html_favicon_url = "https://www.zfnd.org/images/zebra-favicon-128.png")] #![doc(html_logo_url = "https://www.zfnd.org/images/zebra-icon.png")] #![doc(html_root_url = "https://doc.zebra.zfnd.org/zebra_network")] -// Standard lints -#![warn(missing_docs)] -#![allow(clippy::try_err)] -#![deny(clippy::await_holding_lock)] -#![deny(rust_2021_compatibility)] -#![forbid(unsafe_code)] #[macro_use] extern crate pin_project; diff --git a/zebra-rpc/src/lib.rs b/zebra-rpc/src/lib.rs index 02f87917a0d..5515e74018c 100644 --- a/zebra-rpc/src/lib.rs +++ b/zebra-rpc/src/lib.rs @@ -3,9 +3,3 @@ #![doc(html_favicon_url = "https://www.zfnd.org/images/zebra-favicon-128.png")] #![doc(html_logo_url = "https://www.zfnd.org/images/zebra-icon.png")] #![doc(html_root_url = "https://doc.zebra.zfnd.org/zebra_rpc")] -// Standard lints -#![warn(missing_docs)] -#![allow(clippy::try_err)] -#![deny(clippy::await_holding_lock)] -#![deny(rust_2021_compatibility)] -#![forbid(unsafe_code)] diff --git a/zebra-script/src/lib.rs b/zebra-script/src/lib.rs index effdda7d277..ab4208f6959 100644 --- a/zebra-script/src/lib.rs +++ b/zebra-script/src/lib.rs @@ -2,14 +2,10 @@ #![doc(html_favicon_url = "https://www.zfnd.org/images/zebra-favicon-128.png")] #![doc(html_logo_url = "https://www.zfnd.org/images/zebra-icon.png")] #![doc(html_root_url = "https://doc.zebra.zfnd.org/zebra_script")] -// Standard lints -#![warn(missing_docs)] -#![allow(clippy::try_err)] -#![deny(clippy::await_holding_lock)] -#![deny(rust_2021_compatibility)] -// we allow unsafe code, so we can call zcash_script - -use std::{convert::TryInto, sync::Arc}; +// We allow unsafe code, so we can call zcash_script +#![allow(unsafe_code)] + +use std::sync::Arc; use displaydoc::Display; use thiserror::Error; diff --git a/zebra-state/build.rs b/zebra-state/build.rs index 91ba008f76c..a03774a1620 100644 --- a/zebra-state/build.rs +++ b/zebra-state/build.rs @@ -1,3 +1,8 @@ +//! Build script for zebra-state. +//! +//! Turns the environmental variable `$TEST_FAKE_ACTIVATION_HEIGHTS` +//! into the Rust configuration `cfg(test_fake_activation_heights)`. + use std::env; fn main() { diff --git a/zebra-state/src/lib.rs b/zebra-state/src/lib.rs index c01a633f7ef..a8f80441a80 100644 --- a/zebra-state/src/lib.rs +++ b/zebra-state/src/lib.rs @@ -11,12 +11,6 @@ #![doc(html_favicon_url = "https://www.zfnd.org/images/zebra-favicon-128.png")] #![doc(html_logo_url = "https://www.zfnd.org/images/zebra-icon.png")] #![doc(html_root_url = "https://doc.zebra.zfnd.org/zebra_state")] -// Standard lints -#![warn(missing_docs)] -#![allow(clippy::try_err)] -#![deny(clippy::await_holding_lock)] -#![deny(rust_2021_compatibility)] -#![forbid(unsafe_code)] #[cfg(any(test, feature = "proptest-impl"))] mod arbitrary; diff --git a/zebra-state/tests/basic.rs b/zebra-state/tests/basic.rs index 0c8048c85bd..9ecb5516e07 100644 --- a/zebra-state/tests/basic.rs +++ b/zebra-state/tests/basic.rs @@ -1,9 +1,3 @@ -// Standard lints -#![warn(missing_docs)] -#![allow(clippy::try_err)] -#![deny(clippy::await_holding_lock)] -#![forbid(unsafe_code)] - use color_eyre::eyre::Report; use once_cell::sync::Lazy; use std::sync::Arc; diff --git a/zebra-test/src/lib.rs b/zebra-test/src/lib.rs index b1c30d03e52..093779a3db6 100644 --- a/zebra-test/src/lib.rs +++ b/zebra-test/src/lib.rs @@ -2,12 +2,6 @@ #![doc(html_favicon_url = "https://www.zfnd.org/images/zebra-favicon-128.png")] #![doc(html_logo_url = "https://www.zfnd.org/images/zebra-icon.png")] #![doc(html_root_url = "https://doc.zebra.zfnd.org/zebra_test")] -// Standard lints -#![warn(missing_docs)] -#![allow(clippy::try_err)] -#![deny(clippy::await_holding_lock)] -#![deny(rust_2021_compatibility)] -#![forbid(unsafe_code)] // Each lazy_static variable uses additional recursion #![recursion_limit = "512"] diff --git a/zebra-test/tests/command.rs b/zebra-test/tests/command.rs index 12dba0b9882..4a4823010d8 100644 --- a/zebra-test/tests/command.rs +++ b/zebra-test/tests/command.rs @@ -1,9 +1,3 @@ -// Standard lints -#![warn(missing_docs)] -#![allow(clippy::try_err)] -#![deny(clippy::await_holding_lock)] -#![forbid(unsafe_code)] - use std::{process::Command, time::Duration}; use color_eyre::eyre::Result; diff --git a/zebra-test/tests/transcript.rs b/zebra-test/tests/transcript.rs index b8d3ffbb039..8818cb7f9fa 100644 --- a/zebra-test/tests/transcript.rs +++ b/zebra-test/tests/transcript.rs @@ -1,9 +1,3 @@ -// Standard lints -#![warn(missing_docs)] -#![allow(clippy::try_err)] -#![deny(clippy::await_holding_lock)] -#![forbid(unsafe_code)] - use tower::{Service, ServiceExt}; use zebra_test::transcript::ExpectedTranscriptError; use zebra_test::transcript::Transcript; diff --git a/zebra-utils/src/bin/zebra-checkpoints/main.rs b/zebra-utils/src/bin/zebra-checkpoints/main.rs index 634e7a9bbcf..f8523404961 100644 --- a/zebra-utils/src/bin/zebra-checkpoints/main.rs +++ b/zebra-utils/src/bin/zebra-checkpoints/main.rs @@ -8,12 +8,6 @@ //! zebra-consensus accepts an ordered list of checkpoints, starting with the //! genesis block. Checkpoint heights can be chosen arbitrarily. -// Standard lints -#![warn(missing_docs)] -#![allow(clippy::try_err)] -#![deny(clippy::await_holding_lock)] -#![forbid(unsafe_code)] - use color_eyre::eyre::{ensure, Result}; use serde_json::Value; use std::process::Stdio; diff --git a/zebra-utils/src/lib.rs b/zebra-utils/src/lib.rs index d619fb0df66..b1306e7deee 100644 --- a/zebra-utils/src/lib.rs +++ b/zebra-utils/src/lib.rs @@ -4,9 +4,3 @@ #![doc(html_favicon_url = "https://www.zfnd.org/images/zebra-favicon-128.png")] #![doc(html_logo_url = "https://www.zfnd.org/images/zebra-icon.png")] #![doc(html_root_url = "https://doc.zebra.zfnd.org/zebra_utils")] -// Standard lints -#![warn(missing_docs)] -#![allow(clippy::try_err)] -#![deny(clippy::await_holding_lock)] -#![deny(rust_2021_compatibility)] -#![forbid(unsafe_code)] diff --git a/zebrad/build.rs b/zebrad/build.rs index 318c31224f9..66c3c4034b7 100644 --- a/zebrad/build.rs +++ b/zebrad/build.rs @@ -1,3 +1,8 @@ +//! Build script for zebrad. +//! +//! Turns Zebra version information into build-time environmental variables, +//! so that it can be compiled into `zebrad`, and used in diagnostics. + use vergen::{vergen, Config, SemverKind, ShaKind}; /// Disable vergen env vars that could cause spurious reproducible build diff --git a/zebrad/src/bin/zebrad/main.rs b/zebrad/src/bin/zebrad/main.rs index 8717bcbbf9c..9856713a683 100644 --- a/zebrad/src/bin/zebrad/main.rs +++ b/zebrad/src/bin/zebrad/main.rs @@ -1,11 +1,5 @@ //! Main entry point for Zebrad -// Standard lints -#![warn(missing_docs)] -#![allow(clippy::try_err)] -#![deny(clippy::await_holding_lock)] -#![forbid(unsafe_code)] - use zebrad::application::APPLICATION; /// Boot Zebrad diff --git a/zebrad/src/lib.rs b/zebrad/src/lib.rs index cfa4ac629ca..0e1ba85ac59 100644 --- a/zebrad/src/lib.rs +++ b/zebrad/src/lib.rs @@ -17,12 +17,6 @@ #![doc(html_favicon_url = "https://www.zfnd.org/images/zebra-favicon-128.png")] #![doc(html_logo_url = "https://www.zfnd.org/images/zebra-icon.png")] #![doc(html_root_url = "https://doc.zebra.zfnd.org/zebrad")] -// Standard lints -#![warn(missing_docs)] -#![allow(clippy::try_err)] -#![deny(clippy::await_holding_lock)] -#![deny(rust_2021_compatibility)] -#![forbid(unsafe_code)] // Tracing causes false positives on this lint: // https://github.com/tokio-rs/tracing/issues/553 #![allow(clippy::cognitive_complexity)] diff --git a/zebrad/tests/acceptance.rs b/zebrad/tests/acceptance.rs index 7bac70bcce9..a7558103ff3 100644 --- a/zebrad/tests/acceptance.rs +++ b/zebrad/tests/acceptance.rs @@ -21,12 +21,6 @@ //! or you have poor network connectivity, //! skip all the network tests by setting the `ZEBRA_SKIP_NETWORK_TESTS` environmental variable. -// Standard lints -#![warn(missing_docs)] -#![allow(clippy::try_err)] -#![deny(clippy::await_holding_lock)] -#![forbid(unsafe_code)] - use color_eyre::{ eyre::{Result, WrapErr}, Help, From 453ef2eee82a53b6fe4d51c9bc35456d7973350b Mon Sep 17 00:00:00 2001 From: teor Date: Mon, 24 Jan 2022 13:36:18 +1000 Subject: [PATCH 2/3] Ignore "wrong self convention" in a futures-based trait This lint might only trigger on beta or nightly at the moment. --- zebra-test/src/service_extensions.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/zebra-test/src/service_extensions.rs b/zebra-test/src/service_extensions.rs index 0aa9648e331..38ad27f2d7b 100644 --- a/zebra-test/src/service_extensions.rs +++ b/zebra-test/src/service_extensions.rs @@ -8,12 +8,15 @@ use tower::{Service, ServiceExt}; /// An extension trait to check if a [`Service`] is immediately ready to be called. pub trait IsReady: Service { /// Poll the [`Service`] once, and return true if it is immediately ready to be called. + #[allow(clippy::wrong_self_convention)] fn is_ready(&mut self) -> BoxFuture; /// Poll the [`Service`] once, and return true if it is pending. + #[allow(clippy::wrong_self_convention)] fn is_pending(&mut self) -> BoxFuture; /// Poll the [`Service`] once, and return true if it has failed. + #[allow(clippy::wrong_self_convention)] fn is_failed(&mut self) -> BoxFuture; } From f083cef9a2b1d071abf030e6c1a960a05de5446e Mon Sep 17 00:00:00 2001 From: teor Date: Mon, 24 Jan 2022 13:43:03 +1000 Subject: [PATCH 3/3] Warn if future incompatibile code is added to Zebra --- .cargo/config.toml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.cargo/config.toml b/.cargo/config.toml index f418ba1e924..e125cada3c9 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -7,6 +7,13 @@ rustflags = [ "-Dclippy::await_holding_lock", "-Wmissing_docs", + "-Wnonstandard_style", + "-Wfuture_incompatible", "-Aclippy::try_err", + + # TODOs: + + # fix hidden lifetime parameters + #"-Wrust_2018_idioms", ]