Skip to content

Commit

Permalink
refactor: centralize lint settings with new Rust 1.74 feature
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dnaka91 committed Nov 16, 2023
1 parent b6b595c commit a9e0800
Show file tree
Hide file tree
Showing 21 changed files with 54 additions and 65 deletions.
25 changes: 0 additions & 25 deletions Cargo.lock

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

9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions crates/stef-benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ stef-parser = { path = "../stef-parser" }
[dev-dependencies]
divan = "0.1.2"
indoc.workspace = true

[lints]
workspace = true
10 changes: 6 additions & 4 deletions crates/stef-benches/benches/compiler.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(missing_docs)]

use divan::{black_box, Bencher};

#[global_allocator]
Expand All @@ -8,21 +10,21 @@ fn main() {
}

#[divan::bench(consts = [1, 10, 100, 1000])]
fn validate_large_schema<const N: usize>(bencher: Bencher) {
fn validate_large_schema<const N: usize>(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<const N: usize>(bencher: Bencher) {
fn resolve_large_schema<const N: usize>(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)));
}
12 changes: 7 additions & 5 deletions crates/stef-benches/benches/parser.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(missing_docs)]

use divan::{black_box, Bencher};
use indoc::indoc;

Expand All @@ -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;
Expand Down Expand Up @@ -47,17 +49,17 @@ fn basic(bencher: Bencher) {
}

#[divan::bench(consts = [1, 10, 100, 1000])]
fn large_schema<const N: usize>(bencher: Bencher) {
fn large_schema<const N: usize>(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<const N: usize>(bencher: Bencher) {
fn print<const N: usize>(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());
}
2 changes: 2 additions & 0 deletions crates/stef-benches/benches/varint.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(missing_docs)]

use divan::black_box;
use stef_benches::varint;

Expand Down
4 changes: 1 addition & 3 deletions crates/stef-benches/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
6 changes: 3 additions & 3 deletions crates/stef-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 1 addition & 4 deletions crates/stef-build/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down
3 changes: 3 additions & 0 deletions crates/stef-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 1 addition & 4 deletions crates/stef-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down
3 changes: 3 additions & 0 deletions crates/stef-compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ miette = { workspace = true, features = ["fancy-no-backtrace"] }

[features]
debug = []

[lints]
workspace = true
3 changes: 0 additions & 3 deletions crates/stef-compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions crates/stef-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ proc-macro = true
proc-macro2.workspace = true
quote.workspace = true
syn.workspace = true

[lints]
workspace = true
4 changes: 1 addition & 3 deletions crates/stef-derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions crates/stef-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ miette = { workspace = true, features = ["fancy-no-backtrace"] }

[features]
debug = []

[lints]
workspace = true
4 changes: 0 additions & 4 deletions crates/stef-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions crates/stef-playground/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ stef = { path = "../stef" }

[build-dependencies]
stef-build = { path = "../stef-build" }

[lints]
workspace = true
5 changes: 1 addition & 4 deletions crates/stef-playground/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
3 changes: 3 additions & 0 deletions crates/stef/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ license.workspace = true
bytes = "1.5.0"
paste = "1.0.14"
thiserror.workspace = true

[lints]
workspace = true
4 changes: 1 addition & 3 deletions crates/stef/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit a9e0800

Please sign in to comment.