Skip to content

Commit 4b1e1f0

Browse files
committed
style: enforce clippy::disallowed_macros for direct log use
Add clippy.toml with disallowed-macros configuration that prevents direct use of log::error, log::warn, and log::info. Enable the lint as deny in workspace clippy config. The rate-limited macro helper uses allow(clippy::disallowed_macros) internally since it must call the underlying log macros. The log_dev_preview_warning function is also allowed since it is not guest-triggerable. Non-vmm crates (firecracker, cpu-template-helper, log-instrument examples) are allowed since they do not have access to the rate-limited macros and their log calls are not guest-triggerable. Signed-off-by: Nikita Kalyazin <kalyazin@amazon.com>
1 parent e0959d2 commit 4b1e1f0

15 files changed

Lines changed: 28 additions & 0 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ missing_debug_implementations = "warn"
2020
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(kani)'] }
2121

2222
[workspace.lints.clippy]
23+
disallowed_macros = "deny"
2324
ptr_as_ptr = "warn"
2425
undocumented_unsafe_blocks = "warn"
2526
cast_possible_truncation = "warn"

clippy.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
disallowed-macros = [
2+
{ path = "log::error", reason = "use error_rate_limited! to prevent excessive host log output" },
3+
{ path = "log::warn", reason = "use warn_rate_limited! to prevent excessive host log output" },
4+
{ path = "log::info", reason = "use info_rate_limited! to prevent excessive host log output" },
5+
]

src/cpu-template-helper/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
#![allow(clippy::disallowed_macros)]
5+
46
use std::fs::{read_to_string, write};
57
use std::path::PathBuf;
68

src/cpu-template-helper/src/template/dump/aarch64.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3+
#![allow(clippy::disallowed_macros)]
34

45
use vmm::arch::aarch64::regs::{PC, RegSize, SYS_CNTPCT_EL0, SYS_CNTV_CVAL_EL0};
56
use vmm::cpu_config::aarch64::custom_cpu_template::RegisterModifier;

src/firecracker/src/api_server/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3+
#![allow(clippy::disallowed_macros)]
34

45
//! Implements the interface for intercepting API requests, forwarding them to the VMM
56
//! and responding to the user.

src/firecracker/src/api_server/parsed_request.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3+
#![allow(clippy::disallowed_macros)]
34

45
use std::fmt::Debug;
56

src/firecracker/src/api_server_adapter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3+
#![allow(clippy::disallowed_macros)]
34

45
use std::os::unix::io::AsRawFd;
56
use std::path::PathBuf;

src/firecracker/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
// The firecracker binary uses direct log macros for startup, API, and
5+
// shutdown paths that are not guest-triggerable.
6+
#![allow(clippy::disallowed_macros)]
7+
48
#[cfg(all(feature = "fuzzing", not(debug_assertions)))]
59
compile_error!(
610
"The `fuzzing` feature must not be used in release builds. \

src/firecracker/src/metrics.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3+
#![allow(clippy::disallowed_macros)]
34

45
use std::os::unix::io::AsRawFd;
56
use std::time::Duration;

src/log-instrument/examples/five.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
#![warn(clippy::pedantic)]
5+
#![allow(clippy::disallowed_macros)]
56

67
use log::{LevelFilter, debug, info, warn};
78

0 commit comments

Comments
 (0)