Skip to content

Commit

Permalink
chore: consolidate lint settings in Cargo.toml
Browse files Browse the repository at this point in the history
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 <renato@opensourcerouting.org>
  • Loading branch information
rwestphal committed Nov 25, 2023
1 parent 38fc15f commit b178b39
Show file tree
Hide file tree
Showing 30 changed files with 62 additions and 35 deletions.
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions holo-bfd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
2 changes: 0 additions & 2 deletions holo-bfd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions holo-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ holo-yang = { path = "../holo-yang" }

[build-dependencies]
tonic-build.workspace = true

[lints.rust]
rust_2018_idioms = "warn"
7 changes: 2 additions & 5 deletions holo-cli/src/internal_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<DataNodeRef>>()
.collect::<Vec<DataNodeRef<'_>>>()
.iter()
.rev()
{
Expand Down
13 changes: 8 additions & 5 deletions holo-cli/src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,29 @@ impl CliPrompt {
}

impl Prompt for CliPrompt {
fn render_prompt_left(&self) -> Cow<str> {
fn render_prompt_left(&self) -> Cow<'_, str> {
Cow::Owned(self.0.clone())
}

fn render_prompt_right(&self) -> Cow<str> {
fn render_prompt_right(&self) -> Cow<'_, str> {
Cow::Borrowed("")
}

fn render_prompt_indicator(&self, _edit_mode: PromptEditMode) -> Cow<str> {
fn render_prompt_indicator(
&self,
_edit_mode: PromptEditMode,
) -> Cow<'_, str> {
DEFAULT_PROMPT_INDICATOR.into()
}

fn render_prompt_multiline_indicator(&self) -> Cow<str> {
fn render_prompt_multiline_indicator(&self) -> Cow<'_, str> {
DEFAULT_MULTILINE_INDICATOR.into()
}

fn render_prompt_history_search_indicator(
&self,
history_search: PromptHistorySearch,
) -> Cow<str> {
) -> Cow<'_, str> {
let prefix = match history_search.status {
PromptHistorySearchStatus::Passing => "",
PromptHistorySearchStatus::Failing => "failing ",
Expand Down
3 changes: 3 additions & 0 deletions holo-daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions holo-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions holo-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
// SPDX-License-Identifier: MIT
//

#![forbid(unsafe_code)]
#![warn(rust_2018_idioms)]
#![feature(lazy_cell)]

mod ibus;
Expand Down
3 changes: 3 additions & 0 deletions holo-keychain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions holo-keychain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
// SPDX-License-Identifier: MIT
//

#![forbid(unsafe_code)]
#![warn(rust_2018_idioms)]
#![feature(lazy_cell)]

pub mod northbound;
Expand Down
3 changes: 3 additions & 0 deletions holo-ldp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
3 changes: 0 additions & 3 deletions holo-ldp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions holo-northbound/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ holo-utils = { path = "../holo-utils" }
check_keyword.workspace = true
yang2.workspace = true
holo-yang = { path = "../holo-yang" }

[lints]
workspace = true
2 changes: 0 additions & 2 deletions holo-northbound/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
//

#![feature(extract_if)]
#![warn(rust_2018_idioms)]
#![allow(type_alias_bounds)]
#![allow(clippy::too_many_arguments)]

mod debug;

Expand Down
3 changes: 3 additions & 0 deletions holo-ospf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
2 changes: 0 additions & 2 deletions holo-ospf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand Down
3 changes: 3 additions & 0 deletions holo-policy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions holo-policy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
// SPDX-License-Identifier: MIT
//

#![forbid(unsafe_code)]
#![warn(rust_2018_idioms)]
#![feature(lazy_cell)]

pub mod northbound;
Expand Down
3 changes: 3 additions & 0 deletions holo-protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
3 changes: 0 additions & 3 deletions holo-protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
//

#![feature(lazy_cell)]
#![forbid(unsafe_code)]
#![warn(rust_2018_idioms)]

pub mod event_recorder;
#[cfg(feature = "testing")]
Expand Down Expand Up @@ -284,7 +282,6 @@ async fn event_loop<P>(
}

#[cfg_attr(not(feature = "testing"), allow(unused_mut))]
#[allow(clippy::too_many_arguments)]
async fn run<P>(
name: String,
nb_tx: NbProviderSender,
Expand Down
3 changes: 3 additions & 0 deletions holo-rip/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
3 changes: 0 additions & 3 deletions holo-rip/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions holo-routing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions holo-routing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
// SPDX-License-Identifier: MIT
//

#![forbid(unsafe_code)]
#![warn(rust_2018_idioms)]
#![feature(lazy_cell)]

mod ibus;
Expand Down
3 changes: 3 additions & 0 deletions holo-tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions holo-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ yang2.workspace = true

holo-yang = { path = "../holo-yang" }

[lints.rust]
rust_2018_idioms = "warn"

[features]
default = []
testing = []
1 change: 0 additions & 1 deletion holo-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// SPDX-License-Identifier: MIT
//

#![warn(rust_2018_idioms)]
#![feature(ip)]
#![cfg_attr(
feature = "testing",
Expand Down
3 changes: 3 additions & 0 deletions holo-yang/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ maplit.workspace = true
serde.workspace = true
tracing.workspace = true
yang2.workspace = true

[lints]
workspace = true
1 change: 0 additions & 1 deletion holo-yang/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
//

#![feature(lazy_cell)]
#![warn(rust_2018_idioms)]

pub mod serde;

Expand Down

0 comments on commit b178b39

Please sign in to comment.