Skip to content

Commit

Permalink
Switch to Cargo.toml based lint configuration (#239)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
edmorley authored Nov 20, 2023
1 parent 38e164a commit f75eb07
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 21 deletions.
11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
7 changes: 5 additions & 2 deletions buildpacks/ruby/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
5 changes: 2 additions & 3 deletions buildpacks/ruby/src/bin/agentmon_loop.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
7 changes: 5 additions & 2 deletions buildpacks/ruby/src/bin/launch_daemon.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -75,7 +78,7 @@ fn main() {
eprintln!(
"Could not write to log file {}. Reason: {error}",
log.display()
)
);
});

command.args(["--output", &log.to_string_lossy()]);
Expand All @@ -88,7 +91,7 @@ fn main() {
eprintln!(
"Could not write to log file {}. Reason: {error}",
log.display()
)
);
});
}

Expand Down
3 changes: 0 additions & 3 deletions buildpacks/ruby/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 2 additions & 1 deletion buildpacks/ruby/tests/integration_test.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
6 changes: 5 additions & 1 deletion commons/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
5 changes: 5 additions & 0 deletions commons/bin/print_style_guide.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -9,6 +13,7 @@ use indoc::formatdoc;
use std::io::stdout;
use std::process::Command;

#[allow(clippy::too_many_lines)]
fn main() {
println!(
"{}",
Expand Down
1 change: 0 additions & 1 deletion commons/src/cache.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(clippy::module_name_repetitions)]
mod app_cache;
mod app_cache_collection;
mod clean;
Expand Down
1 change: 0 additions & 1 deletion commons/src/cache/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion commons/src/cache/error.rs
Original file line number Diff line number Diff line change
@@ -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}")]
Expand Down
1 change: 0 additions & 1 deletion commons/src/layer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(clippy::module_name_repetitions)]
mod configure_env_layer;
mod default_env_layer;

Expand Down
3 changes: 0 additions & 3 deletions commons/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#![warn(unused_crate_dependencies)]
#![warn(clippy::pedantic)]

// Used in both testing and printing the style guide
use indoc as _;

Expand Down
1 change: 0 additions & 1 deletion commons/src/output/build_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, W: Debug> {
pub(crate) io: W,
Expand Down
1 change: 0 additions & 1 deletion commons/src/output/warn_later.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ fn take() -> Option<Vec<String>> {
WARN_LATER.with(|cell| cell.replace(None))
}

#[allow(clippy::module_name_repetitions)]
#[derive(Debug)]
pub enum WarnLaterError {
MissingGuardForThread(ThreadId),
Expand Down

0 comments on commit f75eb07

Please sign in to comment.