From b178b3977ad85d664daeb717a44cca1318cd1676 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Sat, 25 Nov 2023 11:26:36 -0300 Subject: [PATCH] chore: consolidate lint settings in Cargo.toml In Rust 1.74.0, support for specifying lint settings via Cargo was introduced, enabling better maintainability by allowing workspace crates to inherit these configurations from the top-level Cargo.toml file. Additionally, remove lint settings that are no longer necessary, and fix `rust_2018_idioms` warnings in holo-cli. Signed-off-by: Renato Westphal --- Cargo.toml | 7 +++++++ holo-bfd/Cargo.toml | 3 +++ holo-bfd/src/lib.rs | 2 -- holo-cli/Cargo.toml | 3 +++ holo-cli/src/internal_commands.rs | 7 ++----- holo-cli/src/terminal.rs | 13 ++++++++----- holo-daemon/Cargo.toml | 3 +++ holo-interface/Cargo.toml | 3 +++ holo-interface/src/lib.rs | 2 -- holo-keychain/Cargo.toml | 3 +++ holo-keychain/src/lib.rs | 2 -- holo-ldp/Cargo.toml | 3 +++ holo-ldp/src/lib.rs | 3 --- holo-northbound/Cargo.toml | 3 +++ holo-northbound/src/lib.rs | 2 -- holo-ospf/Cargo.toml | 3 +++ holo-ospf/src/lib.rs | 2 -- holo-policy/Cargo.toml | 3 +++ holo-policy/src/lib.rs | 2 -- holo-protocol/Cargo.toml | 3 +++ holo-protocol/src/lib.rs | 3 --- holo-rip/Cargo.toml | 3 +++ holo-rip/src/lib.rs | 3 --- holo-routing/Cargo.toml | 3 +++ holo-routing/src/lib.rs | 2 -- holo-tools/Cargo.toml | 3 +++ holo-utils/Cargo.toml | 3 +++ holo-utils/src/lib.rs | 1 - holo-yang/Cargo.toml | 3 +++ holo-yang/src/lib.rs | 1 - 30 files changed, 62 insertions(+), 35 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1c0b58b5..31a5a18d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,6 +67,13 @@ tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] } yang2 = { version = "0.8", features = ["bundled"] } +[workspace.lints.rust] +rust_2018_idioms = "warn" +unsafe_code = "forbid" + +[workspace.lints.clippy] +too_many_arguments = "allow" + [profile.release] lto = true codegen-units = 1 diff --git a/holo-bfd/Cargo.toml b/holo-bfd/Cargo.toml index 8a416086..ab69ffe9 100644 --- a/holo-bfd/Cargo.toml +++ b/holo-bfd/Cargo.toml @@ -39,6 +39,9 @@ holo-bfd = { path = ".", features = ["testing"] } holo-protocol = { path = "../holo-protocol", features = ["testing"] } holo-utils = { path = "../holo-utils", features = ["testing"] } +[lints] +workspace = true + [features] default = [] testing = [] diff --git a/holo-bfd/src/lib.rs b/holo-bfd/src/lib.rs index 56e61b24..25834192 100644 --- a/holo-bfd/src/lib.rs +++ b/holo-bfd/src/lib.rs @@ -4,13 +4,11 @@ // SPDX-License-Identifier: MIT // -#![warn(rust_2018_idioms)] #![cfg_attr( feature = "testing", allow(dead_code, unused_variables, unused_imports) )] #![feature(let_chains, lazy_cell)] -#![allow(clippy::too_many_arguments)] pub mod debug; pub mod error; diff --git a/holo-cli/Cargo.toml b/holo-cli/Cargo.toml index 140d2bdf..73423be0 100644 --- a/holo-cli/Cargo.toml +++ b/holo-cli/Cargo.toml @@ -27,3 +27,6 @@ holo-yang = { path = "../holo-yang" } [build-dependencies] tonic-build.workspace = true + +[lints.rust] +rust_2018_idioms = "warn" diff --git a/holo-cli/src/internal_commands.rs b/holo-cli/src/internal_commands.rs index e980c17a..a060b1f8 100644 --- a/holo-cli/src/internal_commands.rs +++ b/holo-cli/src/internal_commands.rs @@ -261,12 +261,9 @@ fn cmd_show_config_cmds(config: &DataTree, with_defaults: bool) -> String { return true; } let snode = iter.schema(); - match snode.kind() { - SchemaNodeKind::List => false, - _ => true, - } + snode.kind() != SchemaNodeKind::List }) - .collect::>() + .collect::>>() .iter() .rev() { diff --git a/holo-cli/src/terminal.rs b/holo-cli/src/terminal.rs index eb247e65..e2beff62 100644 --- a/holo-cli/src/terminal.rs +++ b/holo-cli/src/terminal.rs @@ -44,26 +44,29 @@ impl CliPrompt { } impl Prompt for CliPrompt { - fn render_prompt_left(&self) -> Cow { + fn render_prompt_left(&self) -> Cow<'_, str> { Cow::Owned(self.0.clone()) } - fn render_prompt_right(&self) -> Cow { + fn render_prompt_right(&self) -> Cow<'_, str> { Cow::Borrowed("") } - fn render_prompt_indicator(&self, _edit_mode: PromptEditMode) -> Cow { + fn render_prompt_indicator( + &self, + _edit_mode: PromptEditMode, + ) -> Cow<'_, str> { DEFAULT_PROMPT_INDICATOR.into() } - fn render_prompt_multiline_indicator(&self) -> Cow { + fn render_prompt_multiline_indicator(&self) -> Cow<'_, str> { DEFAULT_MULTILINE_INDICATOR.into() } fn render_prompt_history_search_indicator( &self, history_search: PromptHistorySearch, - ) -> Cow { + ) -> Cow<'_, str> { let prefix = match history_search.status { PromptHistorySearchStatus::Passing => "", PromptHistorySearchStatus::Failing => "failing ", diff --git a/holo-daemon/Cargo.toml b/holo-daemon/Cargo.toml index 39e6accb..a7ac75ae 100644 --- a/holo-daemon/Cargo.toml +++ b/holo-daemon/Cargo.toml @@ -46,6 +46,9 @@ holo-yang = { path = "../holo-yang" } [build-dependencies] tonic-build.workspace = true +[lints] +workspace = true + [[bin]] name = "holod" path = "src/main.rs" diff --git a/holo-interface/Cargo.toml b/holo-interface/Cargo.toml index ae6bd7a4..6c835d79 100644 --- a/holo-interface/Cargo.toml +++ b/holo-interface/Cargo.toml @@ -23,3 +23,6 @@ yang2.workspace = true holo-northbound = { path = "../holo-northbound" } holo-utils = { path = "../holo-utils" } holo-yang = { path = "../holo-yang" } + +[lints] +workspace = true diff --git a/holo-interface/src/lib.rs b/holo-interface/src/lib.rs index 3afd9b00..9a72f98e 100644 --- a/holo-interface/src/lib.rs +++ b/holo-interface/src/lib.rs @@ -4,8 +4,6 @@ // SPDX-License-Identifier: MIT // -#![forbid(unsafe_code)] -#![warn(rust_2018_idioms)] #![feature(lazy_cell)] mod ibus; diff --git a/holo-keychain/Cargo.toml b/holo-keychain/Cargo.toml index 94ac0e13..a89a8e53 100644 --- a/holo-keychain/Cargo.toml +++ b/holo-keychain/Cargo.toml @@ -17,3 +17,6 @@ yang2.workspace = true holo-northbound = { path = "../holo-northbound" } holo-utils = { path = "../holo-utils" } holo-yang = { path = "../holo-yang" } + +[lints] +workspace = true diff --git a/holo-keychain/src/lib.rs b/holo-keychain/src/lib.rs index e4ae84ae..496ad71b 100644 --- a/holo-keychain/src/lib.rs +++ b/holo-keychain/src/lib.rs @@ -4,8 +4,6 @@ // SPDX-License-Identifier: MIT // -#![forbid(unsafe_code)] -#![warn(rust_2018_idioms)] #![feature(lazy_cell)] pub mod northbound; diff --git a/holo-ldp/Cargo.toml b/holo-ldp/Cargo.toml index 60a4f25a..abd708bd 100644 --- a/holo-ldp/Cargo.toml +++ b/holo-ldp/Cargo.toml @@ -37,6 +37,9 @@ holo-ldp = { path = ".", features = ["testing"] } holo-protocol = { path = "../holo-protocol", features = ["testing"] } holo-utils = { path = "../holo-utils", features = ["testing"] } +[lints] +workspace = true + [features] default = [] testing = [] diff --git a/holo-ldp/src/lib.rs b/holo-ldp/src/lib.rs index b192ae8f..ae279135 100644 --- a/holo-ldp/src/lib.rs +++ b/holo-ldp/src/lib.rs @@ -4,14 +4,11 @@ // SPDX-License-Identifier: MIT // -#![forbid(unsafe_code)] #![feature(ip, lazy_cell)] -#![warn(rust_2018_idioms)] #![cfg_attr( feature = "testing", allow(dead_code, unused_variables, unused_imports) )] -#![allow(clippy::too_many_arguments, clippy::vec_init_then_push)] pub mod collections; pub mod debug; diff --git a/holo-northbound/Cargo.toml b/holo-northbound/Cargo.toml index e4560f06..09dcb28d 100644 --- a/holo-northbound/Cargo.toml +++ b/holo-northbound/Cargo.toml @@ -27,3 +27,6 @@ holo-utils = { path = "../holo-utils" } check_keyword.workspace = true yang2.workspace = true holo-yang = { path = "../holo-yang" } + +[lints] +workspace = true diff --git a/holo-northbound/src/lib.rs b/holo-northbound/src/lib.rs index e031285c..580cec15 100644 --- a/holo-northbound/src/lib.rs +++ b/holo-northbound/src/lib.rs @@ -5,9 +5,7 @@ // #![feature(extract_if)] -#![warn(rust_2018_idioms)] #![allow(type_alias_bounds)] -#![allow(clippy::too_many_arguments)] mod debug; diff --git a/holo-ospf/Cargo.toml b/holo-ospf/Cargo.toml index 68d8c001..e6c39589 100644 --- a/holo-ospf/Cargo.toml +++ b/holo-ospf/Cargo.toml @@ -47,6 +47,9 @@ holo-ospf = { path = ".", features = ["testing", "deterministic"] } holo-protocol = { path = "../holo-protocol", features = ["testing"] } holo-utils = { path = "../holo-utils", features = ["testing"] } +[lints] +workspace = true + [features] default = [] testing = [] diff --git a/holo-ospf/src/lib.rs b/holo-ospf/src/lib.rs index 48e059f3..4be11cfe 100644 --- a/holo-ospf/src/lib.rs +++ b/holo-ospf/src/lib.rs @@ -4,12 +4,10 @@ // SPDX-License-Identifier: MIT // -#![warn(rust_2018_idioms)] #![cfg_attr( feature = "testing", allow(dead_code, unused_variables, unused_imports) )] -#![allow(clippy::single_match, clippy::too_many_arguments)] #![allow(type_alias_bounds)] #![feature(btree_extract_if, hash_extract_if, ip, let_chains, lazy_cell)] diff --git a/holo-policy/Cargo.toml b/holo-policy/Cargo.toml index 51fb6467..cda5c469 100644 --- a/holo-policy/Cargo.toml +++ b/holo-policy/Cargo.toml @@ -16,3 +16,6 @@ yang2.workspace = true holo-northbound = { path = "../holo-northbound" } holo-utils = { path = "../holo-utils" } holo-yang = { path = "../holo-yang" } + +[lints] +workspace = true diff --git a/holo-policy/src/lib.rs b/holo-policy/src/lib.rs index dd5e04ff..ff0ff861 100644 --- a/holo-policy/src/lib.rs +++ b/holo-policy/src/lib.rs @@ -4,8 +4,6 @@ // SPDX-License-Identifier: MIT // -#![forbid(unsafe_code)] -#![warn(rust_2018_idioms)] #![feature(lazy_cell)] pub mod northbound; diff --git a/holo-protocol/Cargo.toml b/holo-protocol/Cargo.toml index fe5d2a7f..395e07f5 100644 --- a/holo-protocol/Cargo.toml +++ b/holo-protocol/Cargo.toml @@ -19,6 +19,9 @@ holo-northbound = { path = "../holo-northbound" } holo-utils = { path = "../holo-utils" } holo-yang = { path = "../holo-yang" } +[lints] +workspace = true + [features] default = [] testing = [] diff --git a/holo-protocol/src/lib.rs b/holo-protocol/src/lib.rs index 96ddb638..4e0a78ec 100644 --- a/holo-protocol/src/lib.rs +++ b/holo-protocol/src/lib.rs @@ -5,8 +5,6 @@ // #![feature(lazy_cell)] -#![forbid(unsafe_code)] -#![warn(rust_2018_idioms)] pub mod event_recorder; #[cfg(feature = "testing")] @@ -284,7 +282,6 @@ async fn event_loop

( } #[cfg_attr(not(feature = "testing"), allow(unused_mut))] -#[allow(clippy::too_many_arguments)] async fn run

( name: String, nb_tx: NbProviderSender, diff --git a/holo-rip/Cargo.toml b/holo-rip/Cargo.toml index 788590df..ca115a5d 100644 --- a/holo-rip/Cargo.toml +++ b/holo-rip/Cargo.toml @@ -36,6 +36,9 @@ holo-rip = { path = ".", features = ["testing"] } holo-protocol = { path = "../holo-protocol", features = ["testing"] } holo-utils = { path = "../holo-utils", features = ["testing"] } +[lints] +workspace = true + [features] default = [] testing = [] diff --git a/holo-rip/src/lib.rs b/holo-rip/src/lib.rs index 28c67699..f7e09dbf 100644 --- a/holo-rip/src/lib.rs +++ b/holo-rip/src/lib.rs @@ -4,13 +4,10 @@ // SPDX-License-Identifier: MIT // -#![forbid(unsafe_code)] -#![warn(rust_2018_idioms)] #![cfg_attr( feature = "testing", allow(dead_code, unused_variables, unused_imports) )] -#![allow(clippy::too_many_arguments)] #![feature(ip, lazy_cell, let_chains)] pub mod debug; diff --git a/holo-routing/Cargo.toml b/holo-routing/Cargo.toml index faf426c7..5209204c 100644 --- a/holo-routing/Cargo.toml +++ b/holo-routing/Cargo.toml @@ -29,3 +29,6 @@ holo-protocol = { path = "../holo-protocol" } holo-rip = { path = "../holo-rip" } holo-utils = { path = "../holo-utils" } holo-yang = { path = "../holo-yang" } + +[lints] +workspace = true diff --git a/holo-routing/src/lib.rs b/holo-routing/src/lib.rs index cd8df96d..175500de 100644 --- a/holo-routing/src/lib.rs +++ b/holo-routing/src/lib.rs @@ -4,8 +4,6 @@ // SPDX-License-Identifier: MIT // -#![forbid(unsafe_code)] -#![warn(rust_2018_idioms)] #![feature(lazy_cell)] mod ibus; diff --git a/holo-tools/Cargo.toml b/holo-tools/Cargo.toml index 787f48f9..f1b928c9 100644 --- a/holo-tools/Cargo.toml +++ b/holo-tools/Cargo.toml @@ -23,6 +23,9 @@ holo-protocol = { path = "../holo-protocol", features = ["testing"] } holo-utils = { path = "../holo-utils", features = ["testing"] } holo-yang = { path = "../holo-yang" } +[lints] +workspace = true + [[bin]] name = "replay" path = "src/replay.rs" diff --git a/holo-utils/Cargo.toml b/holo-utils/Cargo.toml index 3a118c3c..e892c512 100644 --- a/holo-utils/Cargo.toml +++ b/holo-utils/Cargo.toml @@ -30,6 +30,9 @@ yang2.workspace = true holo-yang = { path = "../holo-yang" } +[lints.rust] +rust_2018_idioms = "warn" + [features] default = [] testing = [] diff --git a/holo-utils/src/lib.rs b/holo-utils/src/lib.rs index 6ad33609..27029f1f 100644 --- a/holo-utils/src/lib.rs +++ b/holo-utils/src/lib.rs @@ -4,7 +4,6 @@ // SPDX-License-Identifier: MIT // -#![warn(rust_2018_idioms)] #![feature(ip)] #![cfg_attr( feature = "testing", diff --git a/holo-yang/Cargo.toml b/holo-yang/Cargo.toml index a65c406e..b85230de 100644 --- a/holo-yang/Cargo.toml +++ b/holo-yang/Cargo.toml @@ -10,3 +10,6 @@ maplit.workspace = true serde.workspace = true tracing.workspace = true yang2.workspace = true + +[lints] +workspace = true diff --git a/holo-yang/src/lib.rs b/holo-yang/src/lib.rs index 152c133b..160013c4 100644 --- a/holo-yang/src/lib.rs +++ b/holo-yang/src/lib.rs @@ -5,7 +5,6 @@ // #![feature(lazy_cell)] -#![warn(rust_2018_idioms)] pub mod serde;