From a9e08004f29b4b6c29aea7a8bf74a8ea361fa876 Mon Sep 17 00:00:00 2001 From: Dominik Nakamura Date: Fri, 17 Nov 2023 00:20:20 +0900 Subject: [PATCH] refactor: centralize lint settings with new Rust 1.74 feature Rust 1.75 stabilizes a new `[lints]` setting in Cargo.toml, that allows to define common lints in a central place instead of having to repeatedly define them and keep them in sync in each crate of the workspace. --- Cargo.lock | 25 ------------------------- Cargo.toml | 9 +++++++++ crates/stef-benches/Cargo.toml | 3 +++ crates/stef-benches/benches/compiler.rs | 10 ++++++---- crates/stef-benches/benches/parser.rs | 12 +++++++----- crates/stef-benches/benches/varint.rs | 2 ++ crates/stef-benches/src/lib.rs | 4 +--- crates/stef-build/Cargo.toml | 6 +++--- crates/stef-build/src/lib.rs | 5 +---- crates/stef-cli/Cargo.toml | 3 +++ crates/stef-cli/src/main.rs | 5 +---- crates/stef-compiler/Cargo.toml | 3 +++ crates/stef-compiler/src/lib.rs | 3 --- crates/stef-derive/Cargo.toml | 3 +++ crates/stef-derive/src/lib.rs | 4 +--- crates/stef-parser/Cargo.toml | 3 +++ crates/stef-parser/src/lib.rs | 4 ---- crates/stef-playground/Cargo.toml | 3 +++ crates/stef-playground/src/lib.rs | 5 +---- crates/stef/Cargo.toml | 3 +++ crates/stef/src/lib.rs | 4 +--- 21 files changed, 54 insertions(+), 65 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b178fd2..85d46ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -215,12 +215,6 @@ dependencies = [ "windows-sys 0.45.0", ] -[[package]] -name = "diff" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" - [[package]] name = "divan" version = "0.1.2" @@ -511,16 +505,6 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" -[[package]] -name = "pretty_assertions" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af7cee1a6c8a5b9208b3cb1061f10c0cb689087b3d8ce85fb9d2dd7a29b6ba66" -dependencies = [ - "diff", - "yansi", -] - [[package]] name = "prettyplease" version = "0.2.15" @@ -669,14 +653,11 @@ name = "stef-build" version = "0.1.0" dependencies = [ "glob", - "indoc", "insta", "miette", - "pretty_assertions", "prettyplease", "proc-macro2", "quote", - "stef", "stef-compiler", "stef-parser", "syn", @@ -1055,9 +1036,3 @@ checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" dependencies = [ "linked-hash-map", ] - -[[package]] -name = "yansi" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" diff --git a/Cargo.toml b/Cargo.toml index 6a6349e..c1f995e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,15 @@ homepage = "https://github.com/dnaka91/stef" repository = "https://github.com/dnaka91/stef" license = "MIT" +[workspace.lints.rust] +unsafe_code = "forbid" +rust_2018_idioms = "deny" +missing_docs = "warn" + +[workspace.lints.clippy] +all = "deny" +pedantic = "warn" + [workspace.dependencies] color-eyre = { version = "0.6.2", default-features = false } glob = "0.3.1" diff --git a/crates/stef-benches/Cargo.toml b/crates/stef-benches/Cargo.toml index 9427568..fc2b484 100644 --- a/crates/stef-benches/Cargo.toml +++ b/crates/stef-benches/Cargo.toml @@ -30,3 +30,6 @@ stef-parser = { path = "../stef-parser" } [dev-dependencies] divan = "0.1.2" indoc.workspace = true + +[lints] +workspace = true diff --git a/crates/stef-benches/benches/compiler.rs b/crates/stef-benches/benches/compiler.rs index e212395..d5ee4ee 100644 --- a/crates/stef-benches/benches/compiler.rs +++ b/crates/stef-benches/benches/compiler.rs @@ -1,3 +1,5 @@ +#![allow(missing_docs)] + use divan::{black_box, Bencher}; #[global_allocator] @@ -8,21 +10,21 @@ fn main() { } #[divan::bench(consts = [1, 10, 100, 1000])] -fn validate_large_schema(bencher: Bencher) { +fn validate_large_schema(bencher: Bencher<'_, '_>) { let schema = stef_benches::generate_schema(N); let schema = stef_parser::Schema::parse(&schema, None).unwrap(); stef_compiler::validate_schema(&schema).unwrap(); - bencher.bench(|| stef_compiler::validate_schema(black_box(&schema))) + bencher.bench(|| stef_compiler::validate_schema(black_box(&schema))); } #[divan::bench(consts = [1, 10, 100, 1000])] -fn resolve_large_schema(bencher: Bencher) { +fn resolve_large_schema(bencher: Bencher<'_, '_>) { let schema = stef_benches::generate_schema(N); let schema = stef_parser::Schema::parse(&schema, None).unwrap(); stef_compiler::validate_schema(&schema).unwrap(); let list = &[("bench", black_box(&schema))]; - bencher.bench(|| stef_compiler::resolve_schemas(black_box(list))) + bencher.bench(|| stef_compiler::resolve_schemas(black_box(list))); } diff --git a/crates/stef-benches/benches/parser.rs b/crates/stef-benches/benches/parser.rs index a89a329..0d7c4b3 100644 --- a/crates/stef-benches/benches/parser.rs +++ b/crates/stef-benches/benches/parser.rs @@ -1,3 +1,5 @@ +#![allow(missing_docs)] + use divan::{black_box, Bencher}; use indoc::indoc; @@ -9,7 +11,7 @@ fn main() { } #[divan::bench] -fn basic(bencher: Bencher) { +fn basic(bencher: Bencher<'_, '_>) { let input = indoc! {r#" use other::one::Type1; use other::two; @@ -47,17 +49,17 @@ fn basic(bencher: Bencher) { } #[divan::bench(consts = [1, 10, 100, 1000])] -fn large_schema(bencher: Bencher) { +fn large_schema(bencher: Bencher<'_, '_>) { let schema = stef_benches::generate_schema(N); stef_parser::Schema::parse(&schema, None).unwrap(); - bencher.bench(|| stef_parser::Schema::parse(black_box(&schema), None)) + bencher.bench(|| stef_parser::Schema::parse(black_box(&schema), None)); } #[divan::bench(consts = [1, 10, 100, 1000])] -fn print(bencher: Bencher) { +fn print(bencher: Bencher<'_, '_>) { let schema = stef_benches::generate_schema(N); let schema = stef_parser::Schema::parse(&schema, None).unwrap(); - bencher.bench(|| black_box(&schema).to_string()) + bencher.bench(|| black_box(&schema).to_string()); } diff --git a/crates/stef-benches/benches/varint.rs b/crates/stef-benches/benches/varint.rs index a968c49..e3036e7 100644 --- a/crates/stef-benches/benches/varint.rs +++ b/crates/stef-benches/benches/varint.rs @@ -1,3 +1,5 @@ +#![allow(missing_docs)] + use divan::black_box; use stef_benches::varint; diff --git a/crates/stef-benches/src/lib.rs b/crates/stef-benches/src/lib.rs index 9d7e6eb..b04af55 100644 --- a/crates/stef-benches/src/lib.rs +++ b/crates/stef-benches/src/lib.rs @@ -1,7 +1,5 @@ -#![forbid(unsafe_code)] -#![deny(rust_2018_idioms, clippy::all)] -#![warn(clippy::pedantic)] #![allow( + missing_docs, clippy::cast_possible_wrap, clippy::cast_precision_loss, clippy::cast_sign_loss, diff --git a/crates/stef-build/Cargo.toml b/crates/stef-build/Cargo.toml index 9bdab45..3f890f4 100644 --- a/crates/stef-build/Cargo.toml +++ b/crates/stef-build/Cargo.toml @@ -21,7 +21,7 @@ syn.workspace = true thiserror.workspace = true [dev-dependencies] -indoc.workspace = true insta.workspace = true -pretty_assertions = "1.4.0" -stef = { path = "../stef" } + +[lints] +workspace = true diff --git a/crates/stef-build/src/lib.rs b/crates/stef-build/src/lib.rs index aa921ff..f0b9a2e 100644 --- a/crates/stef-build/src/lib.rs +++ b/crates/stef-build/src/lib.rs @@ -1,7 +1,4 @@ -#![forbid(unsafe_code)] -#![deny(rust_2018_idioms, clippy::all)] -#![warn(clippy::pedantic)] -#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc)] +#![allow(missing_docs, clippy::missing_errors_doc, clippy::missing_panics_doc)] use std::{convert::AsRef, fmt::Debug, path::PathBuf}; diff --git a/crates/stef-cli/Cargo.toml b/crates/stef-cli/Cargo.toml index 37f0532..de9c767 100644 --- a/crates/stef-cli/Cargo.toml +++ b/crates/stef-cli/Cargo.toml @@ -20,3 +20,6 @@ glob.workspace = true miette = { workspace = true, features = ["fancy-no-backtrace"] } mimalloc.workspace = true stef-parser = { path = "../stef-parser" } + +[lints] +workspace = true diff --git a/crates/stef-cli/src/main.rs b/crates/stef-cli/src/main.rs index ab7d278..33664b5 100644 --- a/crates/stef-cli/src/main.rs +++ b/crates/stef-cli/src/main.rs @@ -1,7 +1,4 @@ -#![forbid(unsafe_code)] -#![deny(rust_2018_idioms, clippy::all)] -#![warn(clippy::pedantic)] -#![allow(clippy::missing_errors_doc)] +#![allow(missing_docs, clippy::missing_errors_doc)] use std::{fs, process::ExitCode}; diff --git a/crates/stef-compiler/Cargo.toml b/crates/stef-compiler/Cargo.toml index 93e36db..eea598f 100644 --- a/crates/stef-compiler/Cargo.toml +++ b/crates/stef-compiler/Cargo.toml @@ -21,3 +21,6 @@ miette = { workspace = true, features = ["fancy-no-backtrace"] } [features] debug = [] + +[lints] +workspace = true diff --git a/crates/stef-compiler/src/lib.rs b/crates/stef-compiler/src/lib.rs index 3dd05fc..8416727 100644 --- a/crates/stef-compiler/src/lib.rs +++ b/crates/stef-compiler/src/lib.rs @@ -18,9 +18,6 @@ //! stef_compiler::resolve_schemas(&[("test", &schema)]).unwrap(); //! ``` -#![forbid(unsafe_code)] -#![deny(rust_2018_idioms, clippy::all)] -#![warn(missing_docs, clippy::pedantic)] #![allow(clippy::missing_errors_doc, clippy::module_name_repetitions)] pub use resolve::schemas as resolve_schemas; diff --git a/crates/stef-derive/Cargo.toml b/crates/stef-derive/Cargo.toml index f54c17f..d8f4f60 100644 --- a/crates/stef-derive/Cargo.toml +++ b/crates/stef-derive/Cargo.toml @@ -16,3 +16,6 @@ proc-macro = true proc-macro2.workspace = true quote.workspace = true syn.workspace = true + +[lints] +workspace = true diff --git a/crates/stef-derive/src/lib.rs b/crates/stef-derive/src/lib.rs index 680135e..108c0c2 100644 --- a/crates/stef-derive/src/lib.rs +++ b/crates/stef-derive/src/lib.rs @@ -1,7 +1,5 @@ -#![forbid(unsafe_code)] -#![deny(rust_2018_idioms, clippy::all)] -#![warn(clippy::pedantic)] #![allow( + missing_docs, clippy::missing_errors_doc, clippy::module_name_repetitions, clippy::too_many_lines diff --git a/crates/stef-parser/Cargo.toml b/crates/stef-parser/Cargo.toml index dd2e9ee..9e6c84f 100644 --- a/crates/stef-parser/Cargo.toml +++ b/crates/stef-parser/Cargo.toml @@ -25,3 +25,6 @@ miette = { workspace = true, features = ["fancy-no-backtrace"] } [features] debug = [] + +[lints] +workspace = true diff --git a/crates/stef-parser/src/lib.rs b/crates/stef-parser/src/lib.rs index 1dcb620..3f19051 100644 --- a/crates/stef-parser/src/lib.rs +++ b/crates/stef-parser/src/lib.rs @@ -16,10 +16,6 @@ //! println!("{schema:#?}"); //! ``` -#![forbid(unsafe_code)] -#![deny(rust_2018_idioms, clippy::all)] -#![warn(missing_docs, clippy::pedantic)] - use std::{ fmt::{self, Display}, ops::Range, diff --git a/crates/stef-playground/Cargo.toml b/crates/stef-playground/Cargo.toml index 0dbc0f6..21cfaf1 100644 --- a/crates/stef-playground/Cargo.toml +++ b/crates/stef-playground/Cargo.toml @@ -15,3 +15,6 @@ stef = { path = "../stef" } [build-dependencies] stef-build = { path = "../stef-build" } + +[lints] +workspace = true diff --git a/crates/stef-playground/src/lib.rs b/crates/stef-playground/src/lib.rs index 6c54085..1e2c503 100644 --- a/crates/stef-playground/src/lib.rs +++ b/crates/stef-playground/src/lib.rs @@ -1,7 +1,4 @@ -#![forbid(unsafe_code)] -#![deny(rust_2018_idioms, clippy::all)] -#![warn(clippy::pedantic)] -#![allow(clippy::missing_errors_doc)] +#![allow(missing_docs, clippy::missing_errors_doc)] mod sample { stef::include!("sample"); diff --git a/crates/stef/Cargo.toml b/crates/stef/Cargo.toml index 0ed65b9..ad2d69f 100644 --- a/crates/stef/Cargo.toml +++ b/crates/stef/Cargo.toml @@ -13,3 +13,6 @@ license.workspace = true bytes = "1.5.0" paste = "1.0.14" thiserror.workspace = true + +[lints] +workspace = true diff --git a/crates/stef/src/lib.rs b/crates/stef/src/lib.rs index 6385b97..3e3bb6e 100644 --- a/crates/stef/src/lib.rs +++ b/crates/stef/src/lib.rs @@ -1,7 +1,5 @@ -#![forbid(unsafe_code)] -#![deny(rust_2018_idioms, clippy::all)] -#![warn(clippy::pedantic)] #![allow( + missing_docs, clippy::cast_possible_truncation, clippy::implicit_hasher, clippy::inline_always,