From 72e2e767a2ceb0d5c905700546abaf0d11edd7bb Mon Sep 17 00:00:00 2001 From: rami3l Date: Sun, 6 Oct 2024 12:24:17 +0800 Subject: [PATCH 1/4] build: use `workspace.package` properties in `Cargo.toml` --- Cargo.toml | 11 ++++++++--- download/Cargo.toml | 6 +++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9c43642072..01a171647d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "rustup" -version = "1.27.1" -edition = "2021" +version.workspace = true +edition.workspace = true +license.workspace = true description = "Manage multiple rust installations with ease" homepage = "https://github.com/rust-lang/rustup" keywords = ["rustup", "multirust", "install", "proxy"] -license = "MIT OR Apache-2.0" readme = "README.md" repository = "https://github.com/rust-lang/rustup" build = "build.rs" @@ -133,6 +133,11 @@ regex = "1" [workspace] members = ["download"] +[workspace.package] +version = "1.27.1" +edition = "2021" +license = "MIT OR Apache-2.0" + [workspace.dependencies] anyhow = "1.0.69" fs_at = "0.2.1" diff --git a/download/Cargo.toml b/download/Cargo.toml index c1daeeaefc..691ae22f6e 100644 --- a/download/Cargo.toml +++ b/download/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "download" -version = "1.27.1" -edition = "2021" -license = "MIT OR Apache-2.0" +version.workspace = true +edition.workspace = true +license.workspace = true [features] default = ["reqwest-backend", "reqwest-rustls-tls", "reqwest-native-tls"] From 3d3d76f169ad322698f03a658283fc5ef8030f17 Mon Sep 17 00:00:00 2001 From: rami3l Date: Thu, 24 Oct 2024 09:55:17 +0800 Subject: [PATCH 2/4] style: introduce workspace-wide lint tables --- Cargo.toml | 6 ++++++ download/Cargo.toml | 3 +++ download/src/lib.rs | 1 - src/lib.rs | 1 - 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 01a171647d..5fd067a177 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -130,6 +130,9 @@ trycmd = "0.15.0" platforms.workspace = true regex = "1" +[lints] +workspace = true + [workspace] members = ["download"] @@ -158,6 +161,9 @@ tracing-subscriber = "0.3.16" url = "2.4" walkdir = "2" +[workspace.lints.rust] +rust_2018_idioms = "deny" + [lib] name = "rustup" path = "src/lib.rs" diff --git a/download/Cargo.toml b/download/Cargo.toml index 691ae22f6e..0457cd84dc 100644 --- a/download/Cargo.toml +++ b/download/Cargo.toml @@ -32,3 +32,6 @@ http-body-util = "0.1.0" hyper = { version = "1.0", default-features = false, features = ["server", "http1"] } hyper-util = { version = "0.1.1", features = ["tokio"] } tempfile.workspace = true + +[lints] +workspace = true diff --git a/download/src/lib.rs b/download/src/lib.rs index c22ed87e49..ba796c8306 100644 --- a/download/src/lib.rs +++ b/download/src/lib.rs @@ -1,5 +1,4 @@ //! Easy file downloading -#![deny(rust_2018_idioms)] use std::fs::remove_file; use std::path::Path; diff --git a/src/lib.rs b/src/lib.rs index bacaafe8c9..0b1073c44b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,3 @@ -#![deny(rust_2018_idioms)] #![allow( clippy::type_complexity, clippy::result_large_err, // 288 bytes is our 'large' variant today, which is unlikely to be a performance problem From 80d419501e45656c18e416600771c7e5afa75af1 Mon Sep 17 00:00:00 2001 From: rami3l Date: Thu, 24 Oct 2024 10:19:00 +0800 Subject: [PATCH 3/4] style: enable `clippy::print_std(err|out)` when applicable --- src/cli/rustup_mode.rs | 3 ++- src/diskio/threaded.rs | 1 + src/lib.rs | 5 +++++ src/test.rs | 2 +- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 9b84fe1a28..8c69b25253 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -588,7 +588,8 @@ pub async fn main( } let Some(subcmd) = matches.subcmd else { - eprintln!("{}", Rustup::command().render_long_help()); + let help = Rustup::command().render_long_help(); + writeln!(process.stderr().lock(), "{help}")?; return Ok(utils::ExitCode(1)); }; diff --git a/src/diskio/threaded.rs b/src/diskio/threaded.rs index 85906b3b84..486864bbae 100644 --- a/src/diskio/threaded.rs +++ b/src/diskio/threaded.rs @@ -268,6 +268,7 @@ impl<'a> Executor for Threaded<'a> { prev_files as u64, )); } + #[allow(clippy::print_stderr)] if prev_files > 50 { eprintln!("{prev_files} deferred IO operations"); } diff --git a/src/lib.rs b/src/lib.rs index 0b1073c44b..24664da77c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,11 @@ clippy::result_large_err, // 288 bytes is our 'large' variant today, which is unlikely to be a performance problem clippy::arc_with_non_send_sync, // will get resolved as we move further into async )] +#![cfg_attr(not(test), warn( + // We use the logging system instead of printing directly. + clippy::print_stdout, + clippy::print_stderr, +))] #![recursion_limit = "1024"] use anyhow::{anyhow, Result}; diff --git a/src/test.rs b/src/test.rs index 42a3c728dc..554792d851 100644 --- a/src/test.rs +++ b/src/test.rs @@ -1,4 +1,4 @@ -#![allow(clippy::box_default)] +#![allow(clippy::box_default, clippy::print_stdout, clippy::print_stderr)] //! Test support module; public to permit use from integration tests. pub mod mock; From c0623501e065579b4519a6baddf8df1a9b7489a9 Mon Sep 17 00:00:00 2001 From: rami3l Date: Thu, 24 Oct 2024 10:20:31 +0800 Subject: [PATCH 4/4] style: enable `clippy::(dbg_macro|todo)` across the workspace --- Cargo.toml | 5 +++++ src/test/mock/clitools.rs | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5fd067a177..2882e3f843 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -164,6 +164,11 @@ walkdir = "2" [workspace.lints.rust] rust_2018_idioms = "deny" +[workspace.lints.clippy] +# `dbg!()` and `todo!()` clearly shouldn't make it to production: +dbg_macro = "warn" +todo = "warn" + [lib] name = "rustup" path = "src/lib.rs" diff --git a/src/test/mock/clitools.rs b/src/test/mock/clitools.rs index de9981abd5..256a1c830c 100644 --- a/src/test/mock/clitools.rs +++ b/src/test/mock/clitools.rs @@ -668,8 +668,11 @@ impl Config { println!("expected.ok: true"); print_indented("expected.stdout", stdout); print_indented("expected.stderr", stderr); - dbg!(out.stdout == stdout); - dbg!(out.stderr == stderr); + #[allow(clippy::dbg_macro)] + { + dbg!(out.stdout == stdout); + dbg!(out.stderr == stderr); + } panic!(); } }