Skip to content

Commit

Permalink
Fix cargo clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
equation314 committed May 11, 2024
1 parent 720461a commit 662dcae
Show file tree
Hide file tree
Showing 25 changed files with 105 additions and 29 deletions.
1 change: 1 addition & 0 deletions api/arceos_posix_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ repository = "https://github.com/rcore-os/arceos/tree/main/api/arceos_posix_api"
default = []

smp = ["axfeat/smp"]
irq = ["axfeat/irq"]
alloc = ["dep:axalloc", "axfeat/alloc"]
multitask = ["axtask/multitask", "axfeat/multitask", "axsync/multitask"]
fd = ["alloc"]
Expand Down
1 change: 1 addition & 0 deletions api/arceos_posix_api/src/imp/fd_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::ctypes;

pub const AX_FILE_LIMIT: usize = 1024;

#[allow(dead_code)]
pub trait FileLike: Send + Sync {
fn read(&self, buf: &mut [u8]) -> LinuxResult<usize>;
fn write(&self, buf: &[u8]) -> LinuxResult<usize>;
Expand Down
2 changes: 1 addition & 1 deletion api/arceos_posix_api/src/imp/io_mpx/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl FdSets {
let nfds = nfds.min(FD_SETSIZE);
let nfds_usizes = nfds.div_ceil(BITS_PER_USIZE);
let mut bits = core::mem::MaybeUninit::<[usize; FD_SETSIZE_USIZES * 3]>::uninit();
let bits_ptr = unsafe { core::mem::transmute(bits.as_mut_ptr()) };
let bits_ptr: *mut usize = unsafe { core::mem::transmute(bits.as_mut_ptr()) };

let copy_from_fd_set = |bits_ptr: *mut usize, fds: *const ctypes::fd_set| unsafe {
let dst = core::slice::from_raw_parts_mut(bits_ptr, nfds_usizes);
Expand Down
2 changes: 1 addition & 1 deletion apps/task/priority/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::sync::Arc;
use std::{thread, time};
use std::{vec, vec::Vec};

#[cfg(any(feature = "axstd", target_os = "arceos"))]
#[cfg(feature = "axstd")]
use std::os::arceos::api::task::ax_set_current_priority;

struct TaskParam {
Expand Down
9 changes: 5 additions & 4 deletions apps/task/tls/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#[cfg(feature = "axstd")]
extern crate axstd as std;

use std::{ptr::addr_of, str::from_utf8_unchecked};
use std::{thread, vec::Vec};

#[thread_local]
Expand Down Expand Up @@ -56,14 +57,14 @@ fn main() {
get!(U16),
get!(U32),
get!(U64),
get!(std::str::from_utf8_unchecked(&STR))
get!(from_utf8_unchecked(&*addr_of!(STR)))
);
assert!(get!(BOOL));
assert_eq!(get!(U8), 0xAA);
assert_eq!(get!(U16), 0xcafe);
assert_eq!(get!(U32), 0xdeadbeed);
assert_eq!(get!(U64), 0xa2ce05_a2ce05);
assert_eq!(get!(&STR), b"Hello, world!");
assert_eq!(get!(&*addr_of!(STR)), b"Hello, world!");

let mut tasks = Vec::new();
for i in 1..=10 {
Expand All @@ -85,7 +86,7 @@ fn main() {
get!(U16),
get!(U32),
get!(U64),
get!(std::str::from_utf8_unchecked(&STR))
get!(from_utf8_unchecked(&*addr_of!(STR)))
);
assert_eq!(get!(BOOL), i % 2 == 0);
assert_eq!(get!(U8), 0xAA + i as u8);
Expand All @@ -105,7 +106,7 @@ fn main() {
assert_eq!(get!(U16), 0xcafe);
assert_eq!(get!(U32), 0xdeadbeed);
assert_eq!(get!(U64), 0xa2ce05_a2ce05);
assert_eq!(get!(&STR), b"Hello, world!");
assert_eq!(get!(&*addr_of!(STR)), b"Hello, world!");

println!("TLS tests run OK!");
}
2 changes: 1 addition & 1 deletion crates/axerrno/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl TryFrom<i32> for AxError {
#[inline]
fn try_from(value: i32) -> Result<Self, Self::Error> {
if value > 0 && value <= core::mem::variant_count::<AxError>() as i32 {
Ok(unsafe { core::mem::transmute(value) })
Ok(unsafe { core::mem::transmute::<i32, AxError>(value) })
} else {
Err(value)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/kernel_guard/src/arch/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(not(target_os = "none"), allow(dead_code))]
#![cfg_attr(not(target_os = "none"), allow(dead_code, unused_imports))]

cfg_if::cfg_if! {
if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
Expand Down
6 changes: 3 additions & 3 deletions crates/linked_list/src/unsafe_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ impl<A: Adapter + ?Sized> List<A> {
// SAFETY: The safety requirements of this function satisfy those of `insert_after`.
unsafe { self.insert_after(self.inner_ref(existing).prev, new) };

if self.first.unwrap() == existing {
if core::ptr::eq(self.first.unwrap().as_ptr(), existing.as_ptr()) {
// Update the pointer to the first element as we're inserting before it.
self.first = Some(NonNull::from(new));
}
Expand Down Expand Up @@ -459,7 +459,7 @@ impl<A: Adapter + ?Sized> CommonCursor<A> {
if let Some(head) = list.first {
// SAFETY: Per the function safety requirements, `cur` is in the list.
let links = unsafe { list.inner_ref(cur) };
if links.next != head {
if !core::ptr::eq(links.next.as_ptr(), head.as_ptr()) {
self.cur = Some(links.next);
}
}
Expand All @@ -480,7 +480,7 @@ impl<A: Adapter + ?Sized> CommonCursor<A> {
let next = match self.cur.take() {
None => head,
Some(cur) => {
if cur == head {
if core::ptr::eq(cur.as_ptr(), head.as_ptr()) {
return;
}
cur
Expand Down
1 change: 0 additions & 1 deletion crates/memory_addr/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![no_std]
#![feature(const_mut_refs)]
#![doc = include_str!("../README.md")]

use core::fmt;
Expand Down
1 change: 0 additions & 1 deletion crates/scheduler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//! - [`CFScheduler`]: Completely Fair Scheduler (preemptive).
#![cfg_attr(not(test), no_std)]
#![feature(const_mut_refs)]

mod cfs;
mod fifo;
Expand Down
2 changes: 1 addition & 1 deletion crates/timer_list/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl<E> Ord for TimerEventWrapper<E> {

impl<E> PartialEq for TimerEventWrapper<E> {
fn eq(&self, other: &Self) -> bool {
self.deadline.eq(&other.deadline)
self.deadline == other.deadline
}
}

Expand Down
25 changes: 25 additions & 0 deletions modules/axdriver/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ const NET_DEV_FEATURES: &[&str] = &["ixgbe", "virtio-net"];
const BLOCK_DEV_FEATURES: &[&str] = &["ramdisk", "bcm2835-sdhci", "virtio-blk"];
const DISPLAY_DEV_FEATURES: &[&str] = &["virtio-gpu"];

fn make_cfg_values(str_list: &[&str]) -> String {
str_list
.iter()
.map(|s| format!("{:?}", s))
.collect::<Vec<_>>()
.join(", ")
}

fn has_feature(feature: &str) -> bool {
std::env::var(format!(
"CARGO_FEATURE_{}",
Expand Down Expand Up @@ -47,4 +55,21 @@ fn main() {
enable_cfg(&format!("{dev_kind}_dev"), "dummy");
}
}

println!(
"cargo::rustc-check-cfg=cfg(bus, values({}))",
make_cfg_values(&["pci", "mmio"])
);
println!(
"cargo::rustc-check-cfg=cfg(net_dev, values({}, \"dummy\"))",
make_cfg_values(NET_DEV_FEATURES)
);
println!(
"cargo::rustc-check-cfg=cfg(block_dev, values({}, \"dummy\"))",
make_cfg_values(BLOCK_DEV_FEATURES)
);
println!(
"cargo::rustc-check-cfg=cfg(display_dev, values({}, \"dummy\"))",
make_cfg_values(DISPLAY_DEV_FEATURES)
);
}
33 changes: 33 additions & 0 deletions modules/axhal/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
use std::io::Result;

const BUILTIN_PLATFORMS: &[&str] = &[
"aarch64-bsta1000b",
"aarch64-qemu-virt",
"aarch64-raspi4",
"riscv64-qemu-virt",
"x86_64-pc-oslab",
"x86_64-qemu-q35",
];

const BUILTIN_PLATFORM_FAMILIES: &[&str] = &[
"aarch64-bsta1000b",
"aarch64-qemu-virt",
"aarch64-raspi",
"riscv64-qemu-virt",
"x86-pc",
];

fn make_cfg_values(str_list: &[&str]) -> String {
str_list
.iter()
.map(|s| format!("{:?}", s))
.collect::<Vec<_>>()
.join(", ")
}

fn main() {
let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
let platform = axconfig::PLATFORM;
Expand All @@ -9,6 +34,14 @@ fn main() {

println!("cargo:rustc-cfg=platform=\"{}\"", platform);
println!("cargo:rustc-cfg=platform_family=\"{}\"", axconfig::FAMILY);
println!(
"cargo::rustc-check-cfg=cfg(platform, values({}))",
make_cfg_values(BUILTIN_PLATFORMS)
);
println!(
"cargo::rustc-check-cfg=cfg(platform_family, values({}))",
make_cfg_values(BUILTIN_PLATFORM_FAMILIES)
);
}

fn gen_linker_script(arch: &str, platform: &str) -> Result<()> {
Expand Down
1 change: 1 addition & 0 deletions modules/axhal/src/arch/x86_64/idt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl IdtStruct {
)
};
for i in 0..NUM_INT {
#[allow(clippy::missing_transmute_annotations)]
entries[i].set_handler_fn(unsafe { core::mem::transmute(ENTRIES[i]) });
}
idt
Expand Down
6 changes: 4 additions & 2 deletions modules/axhal/src/platform/aarch64_bsta1000b/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ pub(crate) fn platform_regions() -> impl Iterator<Item = MemRegion> {
}

pub(crate) unsafe fn init_boot_page_table(
boot_pt_l0: &mut [A64PTE; 512],
boot_pt_l1: &mut [A64PTE; 512],
boot_pt_l0: *mut [A64PTE; 512],
boot_pt_l1: *mut [A64PTE; 512],
) {
let boot_pt_l0 = &mut *boot_pt_l0;
let boot_pt_l1 = &mut *boot_pt_l1;
// 0x0000_0000_0000 ~ 0x0080_0000_0000, table
boot_pt_l0[0] = A64PTE::new_table(PhysAddr::from(boot_pt_l1.as_ptr() as usize));
// 0x0000_0000_0000..0x0000_4000_0000, 1G block, device memory
Expand Down
3 changes: 2 additions & 1 deletion modules/axhal/src/platform/aarch64_common/boot.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use aarch64_cpu::{asm, asm::barrier, registers::*};
use core::ptr::addr_of_mut;
use memory_addr::PhysAddr;
use page_table_entry::aarch64::{MemAttr, A64PTE};
use tock_registers::interfaces::{ReadWriteable, Readable, Writeable};
Expand Down Expand Up @@ -97,7 +98,7 @@ unsafe fn enable_fp() {
}

unsafe fn init_boot_page_table() {
crate::platform::mem::init_boot_page_table(&mut BOOT_PT_L0, &mut BOOT_PT_L1);
crate::platform::mem::init_boot_page_table(addr_of_mut!(BOOT_PT_L0), addr_of_mut!(BOOT_PT_L1));
}

/// The earliest entry point for the primary CPU.
Expand Down
6 changes: 4 additions & 2 deletions modules/axhal/src/platform/aarch64_qemu_virt/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ pub(crate) fn platform_regions() -> impl Iterator<Item = MemRegion> {
}

pub(crate) unsafe fn init_boot_page_table(
boot_pt_l0: &mut [A64PTE; 512],
boot_pt_l1: &mut [A64PTE; 512],
boot_pt_l0: *mut [A64PTE; 512],
boot_pt_l1: *mut [A64PTE; 512],
) {
let boot_pt_l0 = &mut *boot_pt_l0;
let boot_pt_l1 = &mut *boot_pt_l1;
// 0x0000_0000_0000 ~ 0x0080_0000_0000, table
boot_pt_l0[0] = A64PTE::new_table(PhysAddr::from(boot_pt_l1.as_ptr() as usize));
// 0x0000_0000_0000..0x0000_4000_0000, 1G block, device memory
Expand Down
6 changes: 4 additions & 2 deletions modules/axhal/src/platform/aarch64_raspi/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ pub(crate) fn platform_regions() -> impl Iterator<Item = MemRegion> {
}

pub(crate) unsafe fn init_boot_page_table(
boot_pt_l0: &mut [A64PTE; 512],
boot_pt_l1: &mut [A64PTE; 512],
boot_pt_l0: *mut [A64PTE; 512],
boot_pt_l1: *mut [A64PTE; 512],
) {
let boot_pt_l0 = &mut *boot_pt_l0;
let boot_pt_l1 = &mut *boot_pt_l1;
// 0x0000_0000_0000 ~ 0x0080_0000_0000, table
boot_pt_l0[0] = A64PTE::new_table(PhysAddr::from(boot_pt_l1.as_ptr() as usize));
// 0x0000_0000_0000..0x0000_4000_0000, 1G block, device memory
Expand Down
7 changes: 4 additions & 3 deletions modules/axnet/src/smoltcp_impl/addr.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::net::{IpAddr, SocketAddr};
use core::net::{IpAddr, Ipv4Addr, SocketAddr};
use smoltcp::wire::{IpAddress, IpEndpoint, Ipv4Address};

pub const fn from_core_ipaddr(ip: IpAddr) -> IpAddress {
Expand All @@ -10,8 +10,9 @@ pub const fn from_core_ipaddr(ip: IpAddr) -> IpAddress {

pub const fn into_core_ipaddr(ip: IpAddress) -> IpAddr {
match ip {
IpAddress::Ipv4(ipv4) => IpAddr::V4(unsafe { core::mem::transmute(ipv4.0) }),
// _ => panic!("IPv6 not supported"),
IpAddress::Ipv4(ipv4) => {
IpAddr::V4(unsafe { core::mem::transmute::<[u8; 4], Ipv4Addr>(ipv4.0) })
} // _ => panic!("IPv6 not supported"),
}
}

Expand Down
2 changes: 1 addition & 1 deletion modules/axtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ crate_interface = { path = "../../crates/crate_interface", optional = true }
[dev-dependencies]
rand = "0.8"
axhal = { path = "../axhal", features = ["fp_simd"] }
axtask = { path = ".", features = ["test"] }
axtask = { path = ".", features = ["test", "multitask"] }
3 changes: 3 additions & 0 deletions modules/axtask/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#![feature(doc_cfg)]
#![feature(doc_auto_cfg)]

#[cfg(test)]
mod tests;

cfg_if::cfg_if! {
if #[cfg(feature = "multitask")] {
#[macro_use]
Expand Down
2 changes: 1 addition & 1 deletion modules/axtask/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Mutex, Once};

use crate::{self as axtask, current, WaitQueue};
use crate::{api as axtask, current, WaitQueue};

static INIT: Once = Once::new();
static SERIAL: Mutex<()> = Mutex::new(());
Expand Down
6 changes: 4 additions & 2 deletions scripts/make/cargo.mk
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ define cargo_build
$(call run_cmd,cargo build,$(build_args) $(1) --features "$(strip $(2))")
endef

clippy_args := -A clippy::new_without_default

define cargo_clippy
$(call run_cmd,cargo clippy,--all-features --workspace --exclude axlog $(1) $(verbose))
$(call run_cmd,cargo clippy,-p axlog -p percpu -p percpu_macros $(1) $(verbose))
$(call run_cmd,cargo clippy,--all-features --workspace --exclude axlog $(1) $(verbose) -- $(clippy_args))
$(call run_cmd,cargo clippy,-p axlog -p percpu -p percpu_macros $(1) $(verbose) -- $(clippy_args))
endef

all_packages := \
Expand Down
2 changes: 1 addition & 1 deletion scripts/make/features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
ifeq ($(APP_TYPE),c)
ax_feat_prefix := axfeat/
lib_feat_prefix := axlibc/
lib_features := fp_simd alloc multitask fs net fd pipe select epoll
lib_features := fp_simd irq alloc multitask fs net fd pipe select epoll
else
# TODO: it's better to use `axfeat/` as `ax_feat_prefix`, but all apps need to have `axfeat` as a dependency
ax_feat_prefix := axstd/
Expand Down
3 changes: 3 additions & 0 deletions ulib/axlibc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ smp = ["arceos_posix_api/smp"]
# Floating point/SIMD
fp_simd = ["axfeat/fp_simd"]

# Interrupts
irq = ["arceos_posix_api/irq", "axfeat/irq"]

# Memory
alloc = ["arceos_posix_api/alloc"]
tls = ["alloc", "axfeat/tls"]
Expand Down

0 comments on commit 662dcae

Please sign in to comment.