Skip to content

Commit e84d493

Browse files
committed
fix: refine clippy
1 parent 6807334 commit e84d493

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

usr/rust/src/bin/user_shell.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub fn main() {
2222
let c = getc();
2323
match c {
2424
LF | CR => {
25-
println!("");
25+
println!();
2626
if !line.is_empty() {
2727
line.push('\0');
2828
println!("searching for program {}", line);

usr/rust/src/bin/write.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use user::io::*;
1010
use user::syscall::{sys_close, sys_open, sys_read, sys_write};
1111

1212
const BUFFER_SIZE: usize = 20;
13-
const FILE: &'static str = "temp\0";
14-
const TEXT: &'static str = "Hello world!\0";
13+
const FILE: &str = "temp\0";
14+
const TEXT: &str = "Hello world!\0";
1515

1616
#[no_mangle]
1717
pub fn main() -> usize {
@@ -30,9 +30,9 @@ pub fn main() -> usize {
3030
// 检查功能是否正确
3131
let len = (0..BUFFER_SIZE).find(|&i| read[i] as u8 == 0).unwrap();
3232
print!("content = ");
33-
for i in 0usize..len {
34-
assert!(read[i] == TEXT.as_bytes()[i]);
35-
putchar(read[i] as char);
33+
for (i, item) in read.iter().enumerate().take(len) {
34+
assert!(*item == TEXT.as_bytes()[i]);
35+
putchar(*item as char);
3636
}
3737
putchar('\n');
3838
sys_close(read_fd as i32);

usr/rust/src/io.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ pub const STDIN: usize = 0;
4242
pub const STDOUT: usize = 1;
4343

4444
pub fn getc() -> u8 {
45-
let mut c = 0u8;
46-
assert_eq!(sys_read(STDIN, &mut c, 1), 1);
45+
let c = 0u8;
46+
assert_eq!(sys_read(STDIN, &c, 1), 1);
4747
c
4848
}
4949

0 commit comments

Comments
 (0)