Skip to content

Commit 0b3100e

Browse files
committed
调整部分代码以通过 cargo clippy
1 parent 430817e commit 0b3100e

File tree

9 files changed

+14
-9
lines changed

9 files changed

+14
-9
lines changed

os/src/algorithm/src/allocator/segment_tree_allocator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl Allocator for SegmentTreeAllocator {
3939
// 递归查找直到找到一个值为 0 的树叶
4040
while node < self.tree.len() / 2 {
4141
if !self.tree.get_bit(node * 2) {
42-
node = node * 2;
42+
node *= 2;
4343
} else if !self.tree.get_bit(node * 2 + 1) {
4444
node = node * 2 + 1;
4545
} else {

os/src/algorithm/src/unsafe_wrapper.rs

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ impl<T> UnsafeWrapper<T> {
1818
}
1919
}
2020

21+
#[allow(clippy::mut_from_ref)]
2122
pub fn get(&self) -> &mut T {
2223
unsafe { &mut *self.object.get() }
2324
}
@@ -52,6 +53,7 @@ impl<T> StaticUnsafeWrapper<T> {
5253
}
5354

5455
impl<T: Default> StaticUnsafeWrapper<T> {
56+
#[allow(clippy::mut_from_ref)]
5557
pub fn get(&self) -> &mut T {
5658
unsafe {
5759
if *self.pointer.get() as usize == 0 {

os/src/drivers/block/virtio_blk.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ impl Driver for VirtIOBlkDriver {
3030
pub fn add_driver(header: &'static mut VirtIOHeader) {
3131
let virtio_blk = VirtIOBlk::new(header).expect("failed to init blk driver");
3232
let driver = Arc::new(VirtIOBlkDriver(Mutex::new(virtio_blk)));
33-
DRIVERS.write().push(driver.clone());
33+
DRIVERS.write().push(driver);
3434
}

os/src/drivers/bus/virtio_mmio.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ extern "C" fn virtio_dma_alloc(pages: usize) -> PhysicalAddress {
6060
last = tracker.address();
6161
TRACKERS.write().insert(last, tracker);
6262
}
63-
return pa;
63+
pa
6464
}
6565

6666
/// 为 DMA 操作释放对应的之前申请的连续的物理页(为 [`virtio_drivers`] 库提供)

os/src/fs/stdin.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ impl INode for Stdin {
2828
Ok(0)
2929
} else {
3030
let mut stdin_buffer = self.buffer.lock();
31-
for i in 0..buf.len() {
32-
if stdin_buffer.is_empty() {
33-
return Ok(i);
31+
for (i, byte) in buf.iter_mut().enumerate() {
32+
if let Some(b) = stdin_buffer.pop_front() {
33+
*byte = b;
3434
} else {
35-
buf[i] = stdin_buffer.pop_front().unwrap();
35+
return Ok(i);
3636
}
3737
}
3838
Ok(buf.len())

os/src/kernel/fs.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ pub(super) fn sys_read(fd: usize, buffer: *mut u8, size: usize) -> SyscallResult
2121
let ret = ret as isize;
2222
if ret > 0 {
2323
return SyscallResult::Proceed(ret);
24-
} else if ret == 0 {
24+
}
25+
if ret == 0 {
2526
return SyscallResult::Park(ret);
2627
}
2728
}

os/src/memory/mapping/mapping.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl Mapping {
8484
// 拷贝数据,注意页表尚未应用,无法直接从刚刚映射的虚拟地址访问,因此必须用物理地址 + 偏移来访问。
8585
if let Some(data) = init_data {
8686
unsafe {
87-
if data.len() == 0 {
87+
if data.is_empty() {
8888
// bss 段中,data 长度为 0,但是仍需要 0-初始化整个空间
8989
(&mut *slice_from_raw_parts_mut(
9090
frame_address.deref_kernel(),

os/src/memory/mapping/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! 每个线程保存一个 [`Mapping`],其中记录了所有的字段 [`Segment`]。
44
//! 同时,也要追踪为页表或字段分配的所有物理页,目的是 drop 掉之后可以安全释放所有资源。
55
6+
#[allow(clippy::module_inception)]
67
mod mapping;
78
mod memory_set;
89
mod page_table;

os/src/process/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
mod config;
44
mod kernel_stack;
5+
#[allow(clippy::module_inception)]
56
mod process;
67
mod processor;
78
mod thread;

0 commit comments

Comments
 (0)