Skip to content

CI: enforce clippy rules in clippy command #3258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/api_server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

#![deny(missing_docs)]
#![warn(clippy::ptr_as_ptr)]
#![warn(clippy::undocumented_unsafe_blocks)]

//! Implements the interface for intercepting API requests, forwarding them to the VMM
//! and responding to the user.
Expand Down
2 changes: 0 additions & 2 deletions src/arch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

#![deny(missing_docs)]
#![warn(clippy::ptr_as_ptr)]
#![warn(clippy::undocumented_unsafe_blocks)]

//! Implements platform specific functionality.
//! Supported platforms: x86_64 and aarch64.
Expand Down
2 changes: 0 additions & 2 deletions src/cpuid/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// found in the THIRD-PARTY file.

#![deny(missing_docs)]
#![warn(clippy::ptr_as_ptr)]
#![warn(clippy::undocumented_unsafe_blocks)]

//! Utility for configuring the CPUID (CPU identification) for the guest microVM.

Expand Down
3 changes: 0 additions & 3 deletions src/devices/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the THIRD-PARTY file.

#![warn(clippy::ptr_as_ptr)]
#![warn(clippy::undocumented_unsafe_blocks)]

//! Emulates virtual and hardware devices.
use std::io;

Expand Down
2 changes: 0 additions & 2 deletions src/dumbo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

#![deny(missing_docs)]
#![warn(clippy::ptr_as_ptr)]
#![warn(clippy::undocumented_unsafe_blocks)]

//! Provides helper logic for parsing and writing protocol data units, and minimalist
//! implementations of a TCP listener, a TCP connection, and an HTTP/1.1 server.
Expand Down
3 changes: 0 additions & 3 deletions src/firecracker/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

#![warn(clippy::ptr_as_ptr)]
#![warn(clippy::undocumented_unsafe_blocks)]

mod api_server_adapter;
mod metrics;

Expand Down
2 changes: 0 additions & 2 deletions src/io_uring/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

#![deny(missing_docs)]
#![warn(clippy::ptr_as_ptr)]
#![warn(clippy::undocumented_unsafe_blocks)]

//! High-level interface over Linux io_uring.
//!
Expand Down
3 changes: 0 additions & 3 deletions src/jailer/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

#![warn(clippy::ptr_as_ptr)]
#![warn(clippy::undocumented_unsafe_blocks)]

mod cgroup;
mod chroot;
mod env;
Expand Down
2 changes: 0 additions & 2 deletions src/logger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

#![deny(missing_docs)]
#![warn(clippy::ptr_as_ptr)]
#![warn(clippy::undocumented_unsafe_blocks)]

//! Crate that implements Firecracker specific functionality as far as logging and metrics
//! collecting.
Expand Down
3 changes: 0 additions & 3 deletions src/mmds/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

#![warn(clippy::ptr_as_ptr)]
#![warn(clippy::undocumented_unsafe_blocks)]

pub mod data_store;
pub mod ns;
pub mod persist;
Expand Down
2 changes: 0 additions & 2 deletions src/rate_limiter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

#![deny(missing_docs)]
#![warn(clippy::ptr_as_ptr)]
#![warn(clippy::undocumented_unsafe_blocks)]

//! # Rate Limiter
//!
Expand Down
3 changes: 0 additions & 3 deletions src/rebase-snap/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

#![warn(clippy::ptr_as_ptr)]
#![warn(clippy::undocumented_unsafe_blocks)]

use std::fs::{File, OpenOptions};
use std::io::{Seek, SeekFrom};
use std::os::unix::io::AsRawFd;
Expand Down
3 changes: 1 addition & 2 deletions src/seccompiler/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

#![deny(missing_docs)]
#![warn(clippy::ptr_as_ptr)]
#![warn(clippy::undocumented_unsafe_blocks)]

//! The library crate that defines common helper functions that are generally used in
//! conjunction with seccompiler-bin.
Expand Down
2 changes: 0 additions & 2 deletions src/snapshot/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
#![deny(missing_docs)]
#![warn(clippy::ptr_as_ptr)]
#![warn(clippy::undocumented_unsafe_blocks)]

//! Provides version tolerant serialization and deserialization facilities and
//! implements a persistent storage format for Firecracker state snapshots.
Expand Down
3 changes: 0 additions & 3 deletions src/utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

#![warn(clippy::ptr_as_ptr)]
#![warn(clippy::undocumented_unsafe_blocks)]

// We use `utils` as a wrapper over `vmm_sys_util` to control the latter
// dependency easier (i.e. update only in one place `vmm_sys_util` version).
// More specifically, we are re-exporting modules from `vmm_sys_util` as part
Expand Down
3 changes: 1 addition & 2 deletions src/vm-memory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// Portions Copyright 2017 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the THIRD-PARTY file.
#![warn(clippy::undocumented_unsafe_blocks)]

use std::io::Error as IoError;
use std::os::unix::io::AsRawFd;
Expand Down Expand Up @@ -103,7 +102,7 @@ fn build_guarded_region(
// SAFETY: Safe because the parameters are valid.
unsafe {
MmapRegionBuilder::new_with_bitmap(size, bitmap)
.with_raw_mmap_pointer(region_addr as *mut u8)
.with_raw_mmap_pointer(region_addr.cast::<u8>())
.with_mmap_prot(prot)
.with_mmap_flags(flags)
.build()
Expand Down
4 changes: 2 additions & 2 deletions src/vmm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the THIRD-PARTY file.

#![deny(missing_docs)]

//! Virtual Machine Monitor that leverages the Linux Kernel-based Virtual Machine (KVM),
//! and other virtualization features to run a single lightweight micro-virtual
//! machine (microVM).
#![deny(missing_docs)]
#![warn(clippy::undocumented_unsafe_blocks)]

/// Handles setup and initialization a `Vmm` object.
pub mod builder;
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ fn guest_memory_from_uffd(
let host_base_addr = mem_region.as_ptr();
let size = mem_region.size();

uffd.register(host_base_addr as _, size as _)
uffd.register(host_base_addr.cast(), size as _)
.map_err(GuestMemoryFromUffdError::Register)?;
backend_mappings.push(GuestRegionUffdMapping {
base_host_virt_addr: host_base_addr as u64,
Expand Down
9 changes: 6 additions & 3 deletions tests/integration_tests/build/test_clippy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"{}-unknown-linux-gnu".format(MACHINE),
"{}-unknown-linux-musl".format(MACHINE),
]
CLIPPY_CFG = ["ptr_as_ptr", "undocumented_unsafe_blocks"]


@pytest.mark.parametrize("target", TARGETS)
Expand All @@ -22,6 +23,8 @@ def test_rust_clippy(target):

@type: build
"""
utils.run_cmd(
"cargo clippy --target {} --all --profile test" " -- -D warnings".format(target)
)
cmd = "cargo clippy --target {} --all --profile test" " --".format(target)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: make this a single string

also: why do we have to append the "-D warnings" below, can't we include the it here, like it was before?

Copy link
Contributor Author

@dianpopa dianpopa Nov 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean I should make a single string?

I got it

for clippy_rule in CLIPPY_CFG:
cmd += " -D clippy::{}".format(clippy_rule)
cmd += " -D warnings"
utils.run_cmd(cmd)