From f2156f773c2b12b8cb7117b8dc5eaefc05bd4f91 Mon Sep 17 00:00:00 2001 From: Ed Morley <501702+edmorley@users.noreply.github.com> Date: Sun, 19 Nov 2023 00:04:56 +0000 Subject: [PATCH] Switch to Cargo.toml based lint configuration As of the Cargo included in Rust 1.74, lints can now be configured in `Cargo.toml` across whole crates/workspaces: https://blog.rust-lang.org/2023/11/16/Rust-1.74.0.html https://doc.rust-lang.org/stable/cargo/reference/manifest.html#the-lints-section https://doc.rust-lang.org/stable/cargo/reference/workspaces.html#the-lints-table This reduces the boilerplate, and the chance that we forget to enable lints in some targets. The only thing we need to remember is to add the `[lints] workspace = true` to any new crates in the future. Making this switch exposed a few places where lints weren't enabled and issues had been missed, which have been fixed now. Since this feature requires Rust 1.74, the MSRV has also been bumped (however, libcnb 0.16.0 already requires Rust 1.74, so in practice this is a no-op). GUS-W-14523799. --- Cargo.toml | 11 +++++++++++ buildpacks/ruby/Cargo.toml | 7 +++++-- buildpacks/ruby/src/bin/agentmon_loop.rs | 5 ++--- buildpacks/ruby/src/bin/launch_daemon.rs | 7 +++++-- buildpacks/ruby/src/main.rs | 3 --- buildpacks/ruby/tests/integration_test.rs | 3 ++- commons/Cargo.toml | 6 +++++- commons/bin/print_style_guide.rs | 5 +++++ commons/src/cache.rs | 1 - commons/src/cache/config.rs | 1 - commons/src/cache/error.rs | 1 - commons/src/layer.rs | 1 - commons/src/lib.rs | 3 --- commons/src/output/build_log.rs | 1 - commons/src/output/warn_later.rs | 1 - 15 files changed, 35 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a1f41d09..2fecfbc4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,14 @@ [workspace] resolver = "2" members = ["buildpacks/ruby", "commons"] + +[workspace.package] +edition = "2021" +rust-version = "1.74" + +[workspace.lints.rust] +unused_crate_dependencies = "warn" + +[workspace.lints.clippy] +pedantic = "warn" +module_name_repetitions = "allow" diff --git a/buildpacks/ruby/Cargo.toml b/buildpacks/ruby/Cargo.toml index 83f56e0f..be6d494e 100644 --- a/buildpacks/ruby/Cargo.toml +++ b/buildpacks/ruby/Cargo.toml @@ -3,8 +3,11 @@ name = "heroku-ruby-buildpack" # This crate is not published, so the only version that is used is the one in buildpack.toml. version = "0.0.0" publish = false -edition = "2021" -rust-version = "1.66" +edition.workspace = true +rust-version.workspace = true + +[lints] +workspace = true [dependencies] commons = { path = "../../commons" } diff --git a/buildpacks/ruby/src/bin/agentmon_loop.rs b/buildpacks/ruby/src/bin/agentmon_loop.rs index c951f809..f26c8363 100644 --- a/buildpacks/ruby/src/bin/agentmon_loop.rs +++ b/buildpacks/ruby/src/bin/agentmon_loop.rs @@ -1,6 +1,5 @@ -// Enable Clippy lints that are disabled by default. -// https://rust-lang.github.io/rust-clippy/stable/index.html -#![warn(clippy::pedantic)] +// Required due to: https://github.com/rust-lang/rust/issues/95513 +#![allow(unused_crate_dependencies)] use clap::Parser; use std::ffi::OsStr; diff --git a/buildpacks/ruby/src/bin/launch_daemon.rs b/buildpacks/ruby/src/bin/launch_daemon.rs index bb243b86..19cf5f38 100644 --- a/buildpacks/ruby/src/bin/launch_daemon.rs +++ b/buildpacks/ruby/src/bin/launch_daemon.rs @@ -1,3 +1,6 @@ +// Required due to: https://github.com/rust-lang/rust/issues/95513 +#![allow(unused_crate_dependencies)] + use clap::Parser; use std::path::PathBuf; use std::process::exit; @@ -75,7 +78,7 @@ fn main() { eprintln!( "Could not write to log file {}. Reason: {error}", log.display() - ) + ); }); command.args(["--output", &log.to_string_lossy()]); @@ -88,7 +91,7 @@ fn main() { eprintln!( "Could not write to log file {}. Reason: {error}", log.display() - ) + ); }); } diff --git a/buildpacks/ruby/src/main.rs b/buildpacks/ruby/src/main.rs index 8b372c26..2424d89a 100644 --- a/buildpacks/ruby/src/main.rs +++ b/buildpacks/ruby/src/main.rs @@ -1,6 +1,3 @@ -#![warn(unused_crate_dependencies)] -#![warn(clippy::pedantic)] -#![allow(clippy::module_name_repetitions)] use commons::cache::CacheError; use commons::gemfile_lock::GemfileLock; use commons::metadata_digest::MetadataDigest; diff --git a/buildpacks/ruby/tests/integration_test.rs b/buildpacks/ruby/tests/integration_test.rs index 3e64d2e7..7d60cc5c 100644 --- a/buildpacks/ruby/tests/integration_test.rs +++ b/buildpacks/ruby/tests/integration_test.rs @@ -1,4 +1,5 @@ -#![warn(clippy::pedantic)] +// Required due to: https://github.com/rust-lang/rust/issues/95513 +#![allow(unused_crate_dependencies)] use libcnb_test::{ assert_contains, assert_empty, BuildConfig, BuildpackReference, ContainerConfig, diff --git a/commons/Cargo.toml b/commons/Cargo.toml index b10a387c..d0e5b57a 100644 --- a/commons/Cargo.toml +++ b/commons/Cargo.toml @@ -1,13 +1,17 @@ [package] name = "commons" version = "1.0.0" -edition = "2021" publish = false +edition.workspace = true +rust-version.workspace = true [[bin]] name = "print_style_guide" path = "bin/print_style_guide.rs" +[lints] +workspace = true + [dependencies] byte-unit = "4" fancy-regex = "0.12" diff --git a/commons/bin/print_style_guide.rs b/commons/bin/print_style_guide.rs index 0552fbee..bce8c0fb 100644 --- a/commons/bin/print_style_guide.rs +++ b/commons/bin/print_style_guide.rs @@ -1,5 +1,9 @@ +// Required due to: https://github.com/rust-lang/rust/issues/95513 +#![allow(unused_crate_dependencies)] + use ascii_table::AsciiTable; use commons::output::fmt::{self, DEBUG_INFO, HELP}; +#[allow(clippy::wildcard_imports)] use commons::output::{ build_log::*, section_log::{log_step, log_step_stream, log_step_timed}, @@ -9,6 +13,7 @@ use indoc::formatdoc; use std::io::stdout; use std::process::Command; +#[allow(clippy::too_many_lines)] fn main() { println!( "{}", diff --git a/commons/src/cache.rs b/commons/src/cache.rs index f6480876..f7b2ce22 100644 --- a/commons/src/cache.rs +++ b/commons/src/cache.rs @@ -1,4 +1,3 @@ -#![allow(clippy::module_name_repetitions)] mod app_cache; mod app_cache_collection; mod clean; diff --git a/commons/src/cache/config.rs b/commons/src/cache/config.rs index e6d8749c..364fd381 100644 --- a/commons/src/cache/config.rs +++ b/commons/src/cache/config.rs @@ -2,7 +2,6 @@ use byte_unit::{n_mib_bytes, Byte}; use std::path::PathBuf; /// Configure behavior of a cached path -#[allow(clippy::module_name_repetitions)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct CacheConfig { /// Path to the directory you want to cache diff --git a/commons/src/cache/error.rs b/commons/src/cache/error.rs index 0c8a228c..4a5f4e73 100644 --- a/commons/src/cache/error.rs +++ b/commons/src/cache/error.rs @@ -1,6 +1,5 @@ use std::path::PathBuf; -#[allow(clippy::module_name_repetitions)] #[derive(thiserror::Error, Debug)] pub enum CacheError { #[error("Cached path not in application directory: {0}")] diff --git a/commons/src/layer.rs b/commons/src/layer.rs index 74807ed9..48d5a73b 100644 --- a/commons/src/layer.rs +++ b/commons/src/layer.rs @@ -1,4 +1,3 @@ -#![allow(clippy::module_name_repetitions)] mod configure_env_layer; mod default_env_layer; diff --git a/commons/src/lib.rs b/commons/src/lib.rs index 4cede6f7..302abf29 100644 --- a/commons/src/lib.rs +++ b/commons/src/lib.rs @@ -1,6 +1,3 @@ -#![warn(unused_crate_dependencies)] -#![warn(clippy::pedantic)] - // Used in both testing and printing the style guide use indoc as _; diff --git a/commons/src/output/build_log.rs b/commons/src/output/build_log.rs index 715beb62..39e0d47f 100644 --- a/commons/src/output/build_log.rs +++ b/commons/src/output/build_log.rs @@ -31,7 +31,6 @@ use std::time::{Duration, Instant}; /// /// For usage details run `cargo run --bin print_style_guide` -#[allow(clippy::module_name_repetitions)] #[derive(Debug)] pub struct BuildLog { pub(crate) io: W, diff --git a/commons/src/output/warn_later.rs b/commons/src/output/warn_later.rs index b95b2be5..37f55619 100644 --- a/commons/src/output/warn_later.rs +++ b/commons/src/output/warn_later.rs @@ -123,7 +123,6 @@ fn take() -> Option> { WARN_LATER.with(|cell| cell.replace(None)) } -#[allow(clippy::module_name_repetitions)] #[derive(Debug)] pub enum WarnLaterError { MissingGuardForThread(ThreadId),