Skip to content

Commit 969ca1b

Browse files
authored
Merge pull request #11 from Rustin-Liu/rustin-patch-ci
ci: add fmt and clippy check
2 parents fea585c + 41cbe01 commit 969ca1b

File tree

21 files changed

+91
-100
lines changed

21 files changed

+91
-100
lines changed

.github/workflows/main.yml

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,26 @@ name: CI
33
on: [push, pull_request]
44

55
jobs:
6+
check:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- uses: actions-rs/toolchain@v1
11+
with:
12+
components: rustfmt, clippy
13+
- name: Setup Environment
14+
run: cd os && make env
15+
- name: Check user
16+
run: cd usr/rust/ && cargo fmt -- --check && cargo clippy -- -D warnings
17+
- name: Check os
18+
run: export USER_IMG="../usr/build/riscv64.img" && cd os && cargo fmt -- --check && cargo clippy -- -D warnings
619
build:
720
runs-on: ubuntu-latest
821
steps:
9-
- uses: actions/checkout@v2
10-
- name: Setup Environment
11-
run: cd os && make env
12-
- name: Build user
13-
run: cd usr && make user_img
14-
- name: Build kernel
15-
run: cd os && make build
22+
- uses: actions/checkout@v2
23+
- name: Setup Environment
24+
run: cd os && make env
25+
- name: Build user
26+
run: cd usr && make user_img
27+
- name: Build kernel
28+
run: cd os && make build

os/src/context.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub struct Context {
1919
impl Context {
2020
#[naked]
2121
#[inline(never)]
22-
pub unsafe extern "C" fn switch(&mut self, target: &mut Context) {
22+
pub unsafe extern "C" fn switch(&mut self, _target: &mut Context) {
2323
llvm_asm!(include_str!("process/switch.asm") :::: "volatile");
2424
}
2525

@@ -62,7 +62,7 @@ extern "C" {
6262

6363
impl ContextContent {
6464
fn new_kernel_thread(entry: usize, kstack_top: usize, satp: usize) -> ContextContent {
65-
let content = ContextContent {
65+
ContextContent {
6666
ra: __trapret as usize,
6767
satp,
6868
s: [0; 12],
@@ -76,8 +76,7 @@ impl ContextContent {
7676
tf.sstatus.set_sie(false);
7777
tf
7878
},
79-
};
80-
content
79+
}
8180
}
8281

8382
fn new_user_thread(entry: usize, ustack_top: usize, satp: usize) -> Self {

os/src/fs/file.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ use rcore_fs::vfs::INode;
44

55
#[derive(Copy, Clone, Debug)]
66
pub enum FileDescriptorType {
7-
FD_NONE,
8-
FD_INODE,
9-
FD_DEVICE,
7+
FdNone,
8+
FdInode,
9+
#[allow(dead_code)]
10+
FdDevice,
1011
}
1112

1213
#[derive(Clone)]
@@ -21,7 +22,7 @@ pub struct File {
2122
impl File {
2223
pub fn default() -> Self {
2324
File {
24-
fdtype: FileDescriptorType::FD_NONE,
25+
fdtype: FileDescriptorType::FdNone,
2526
readable: false,
2627
writable: false,
2728
inode: None,
@@ -53,8 +54,9 @@ impl File {
5354
self.offset
5455
}
5556

57+
#[allow(unused_unsafe)]
5658
pub fn open_file(&mut self, path: &'static str, flags: i32) {
57-
self.set_fdtype(FileDescriptorType::FD_INODE);
59+
self.set_fdtype(FileDescriptorType::FdInode);
5860
self.set_readable(true);
5961
if (flags & 1) > 0 {
6062
self.set_readable(false);

os/src/interrupt.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ pub fn init() {
3232
}
3333

3434
pub unsafe fn init_external_interrupt() {
35-
let HART0_S_MODE_INTERRUPT_ENABLES: *mut u32 = access_pa_via_va(0x0c00_2080) as *mut u32;
35+
let hart0_s_mode_interrupt_enables: *mut u32 = access_pa_via_va(0x0c00_2080) as *mut u32;
3636
const SERIAL: u32 = 0xa;
37-
HART0_S_MODE_INTERRUPT_ENABLES.write_volatile(1 << SERIAL);
37+
hart0_s_mode_interrupt_enables.write_volatile(1 << SERIAL);
3838
}
3939

4040
pub unsafe fn enable_serial_interrupt() {
41-
let UART16550: *mut u8 = access_pa_via_va(0x10000000) as *mut u8;
42-
UART16550.add(4).write_volatile(0x0B);
43-
UART16550.add(1).write_volatile(0x01);
41+
let uart16550: *mut u8 = access_pa_via_va(0x10000000) as *mut u8;
42+
uart16550.add(4).write_volatile(0x0B);
43+
uart16550.add(1).write_volatile(0x01);
4444
}
4545

4646
#[no_mangle]

os/src/io.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,6 @@ macro_rules! println {
3737
($($arg:tt)*) => ($crate::print!("{}\n", format_args!($($arg)*)));
3838
}
3939

40-
pub fn getchar() -> char {
41-
let c = sbi::console_getchar() as u8;
42-
43-
match c {
44-
255 => '\0',
45-
c => c as char,
46-
}
47-
}
4840
// 调用 OpenSBI 接口
4941
pub fn getchar_option() -> Option<char> {
5042
let c = sbi::console_getchar() as isize;

os/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
#![no_main]
33

44
#[allow(unused_imports)]
5+
#[allow(clippy::single_component_path_imports)]
56
use os;

os/src/memory/frame_allocator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl SegmentTreeAllocator {
1414
self.n = r - l;
1515
self.m = 1;
1616
while self.m < self.n + 2 {
17-
self.m = self.m << 1;
17+
self.m <<= 1;
1818
}
1919
for i in 1..(self.m << 1) {
2020
self.a[i] = 1;
@@ -35,7 +35,7 @@ impl SegmentTreeAllocator {
3535
let mut p = 1;
3636
while p < self.m {
3737
if self.a[p << 1] == 0 {
38-
p = p << 1;
38+
p <<= 1;
3939
} else {
4040
p = (p << 1) | 1;
4141
}

os/src/memory/memory_set/area.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ impl MemoryArea {
1717
self.handler.map(pt, page, &self.attr);
1818
}
1919
}
20+
21+
#[allow(dead_code)]
2022
fn unmap(&self, pt: &mut PageTableImpl) {
2123
for page in PageRange::new(self.start, self.end) {
2224
self.handler.unmap(pt, page);
@@ -40,8 +42,8 @@ impl MemoryArea {
4042
MemoryArea {
4143
start: start_addr,
4244
end: end_addr,
43-
handler: handler,
44-
attr: attr,
45+
handler,
46+
attr,
4547
}
4648
}
4749

os/src/memory/memory_set/attr.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
use crate::memory::paging::PageEntry;
22

3-
#[derive(Clone, Debug)]
3+
#[derive(Clone, Default, Debug)]
44
pub struct MemoryAttr {
55
user: bool,
66
readonly: bool,
77
execute: bool,
88
}
99

1010
impl MemoryAttr {
11-
pub fn new() -> Self {
12-
MemoryAttr {
13-
user: false,
14-
readonly: false,
15-
execute: false,
16-
}
17-
}
18-
1911
pub fn set_user(mut self) -> Self {
2012
self.user = true;
2113
self

os/src/memory/memory_set/handler.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@ impl MemoryHandler for Linear {
4747
let dst = core::slice::from_raw_parts_mut(va as *mut u8, PAGE_SIZE);
4848
if length > 0 {
4949
let src = core::slice::from_raw_parts(src as *const u8, PAGE_SIZE);
50-
for i in 0..length {
51-
dst[i] = src[i];
52-
}
50+
dst[..length].clone_from_slice(&src[..length]);
5351
}
52+
#[allow(clippy::needless_range_loop)]
5453
for i in length..PAGE_SIZE {
5554
dst[i] = 0;
5655
}
@@ -85,10 +84,9 @@ impl MemoryHandler for ByFrame {
8584
let dst = core::slice::from_raw_parts_mut(access_pa_via_va(pa) as *mut u8, PAGE_SIZE);
8685
if length > 0 {
8786
let src = core::slice::from_raw_parts(src as *const u8, PAGE_SIZE);
88-
for i in 0..length {
89-
dst[i] = src[i];
90-
}
87+
dst[..length].clone_from_slice(&src[..length]);
9188
}
89+
#[allow(clippy::needless_range_loop)]
9290
for i in length..PAGE_SIZE {
9391
dst[i] = 0;
9492
}

0 commit comments

Comments
 (0)