From a5f6e38a958eb7bed4c33ad7eca735342d994ef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Fri, 10 Mar 2023 17:38:06 +0100 Subject: [PATCH] Run cargo clippy --fix --- src/fs.rs | 16 ++++++++-------- src/path.rs | 2 +- src/tests.rs | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/fs.rs b/src/fs.rs index 326d9405..9ee62945 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -506,9 +506,9 @@ impl Filesystem<'_, Storage> { extern "C" fn lfs_config_erase(c: *const ll::lfs_config, block: ll::lfs_block_t) -> cty::c_int { // println!("in lfs_config_erase"); let storage = unsafe { &mut *((*c).context as *mut Storage) }; - let off = block as usize * Storage::BLOCK_SIZE as usize; + let off = block as usize * Storage::BLOCK_SIZE; - io::error_code_from(storage.erase(off, Storage::BLOCK_SIZE as usize)) + io::error_code_from(storage.erase(off, Storage::BLOCK_SIZE)) } /// C callback interface used by LittleFS to sync data with the lower level interface below the @@ -673,7 +673,7 @@ impl<'a, 'b, Storage: driver::Storage> File<'a, 'b, Storage> { // Safety-hatch to experiment with missing parts of API pub unsafe fn borrow_filesystem<'c>(&'c mut self) -> &'c Filesystem<'a, Storage> { - &self.fs + self.fs } /// Sync the file and drop it from the internal linked list. @@ -1052,7 +1052,7 @@ impl<'a, 'b, S: driver::Storage> Iterator for ReadDir<'a, 'b, S> { impl<'a, 'b, S: driver::Storage> ReadDir<'a, 'b, S> { // Safety-hatch to experiment with missing parts of API pub unsafe fn borrow_filesystem<'c>(&'c mut self) -> &'c Filesystem<'a, S> { - &self.fs + self.fs } } @@ -1367,7 +1367,7 @@ mod tests { let mut alloc = Allocation::new(); let fs = Filesystem::mount(&mut alloc, &mut test_storage).unwrap(); // fs.write(b"/z.txt\0".try_into().unwrap(), &jackson5).unwrap(); - fs.write(&PathBuf::from("z.txt"), &jackson5).unwrap(); + fs.write(&PathBuf::from("z.txt"), jackson5).unwrap(); } #[cfg(feature = "dir-entry-path")] @@ -1446,7 +1446,7 @@ mod tests { // One usecase is to read data from the files iterated over. // if entry.metadata.is_file() { - fs.write(&entry.file_name(), b"wowee zowie")?; + fs.write(entry.file_name(), b"wowee zowie")?; } } Ok(()) @@ -1477,11 +1477,11 @@ mod tests { })?; let mut a1 = File::allocate(); - let f1 = unsafe { File::open(&fs, &mut a1, b"a.txt\0".try_into().unwrap())? }; + let f1 = unsafe { File::open(fs, &mut a1, b"a.txt\0".try_into().unwrap())? }; f1.write(b"some text")?; let mut a2 = File::allocate(); - let f2 = unsafe { File::open(&fs, &mut a2, b"b.txt\0".try_into().unwrap())? }; + let f2 = unsafe { File::open(fs, &mut a2, b"b.txt\0".try_into().unwrap())? }; f2.write(b"more text")?; unsafe { f1.close()? }; // program hangs here diff --git a/src/path.rs b/src/path.rs index 0b2a8100..94fd618b 100644 --- a/src/path.rs +++ b/src/path.rs @@ -300,7 +300,7 @@ impl From<&[u8]> for PathBuf { } else { bytes }; - let has_no_embedded_nul = bytes.iter().find(|&&byte| byte == b'\0').is_none(); + let has_no_embedded_nul = !bytes.iter().any(|&byte| byte == b'\0'); assert!(has_no_embedded_nul); let mut buf = [0; consts::PATH_MAX_PLUS_ONE]; diff --git a/src/tests.rs b/src/tests.rs index cb343bb9..14ddc6a7 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -197,20 +197,20 @@ fn test_create() { assert_eq!(fs.available_blocks().unwrap(), 512 - 2); assert_eq!(fs.available_space().unwrap(), 130_560); - assert!(!crate::path::PathBuf::from(b"/test_open.txt").exists(&fs)); + assert!(!crate::path::PathBuf::from(b"/test_open.txt").exists(fs)); assert_eq!( File::open_and_then(fs, b"/test_open.txt\0".try_into().unwrap(), |_| { Ok(()) }) .map(drop) .unwrap_err(), // "real" contains_err is experimental Error::NoSuchEntry ); - assert!(!crate::path::PathBuf::from(b"/test_open.txt").exists(&fs)); + assert!(!crate::path::PathBuf::from(b"/test_open.txt").exists(fs)); fs.create_dir(b"/tmp\0".try_into().unwrap()).unwrap(); assert_eq!(fs.available_blocks().unwrap(), 512 - 2 - 2); // can create new files - assert!(!crate::path::PathBuf::from(b"/tmp/test_open.txt").exists(&fs)); + assert!(!crate::path::PathBuf::from(b"/tmp/test_open.txt").exists(fs)); fs.create_file_and_then(b"/tmp/test_open.txt\0".try_into().unwrap(), |file| { // can write to files assert!(file.write(&[0u8, 1, 2]).unwrap() == 3); @@ -221,7 +221,7 @@ fn test_create() { // file.close()?; Ok(()) })?; - assert!(crate::path::PathBuf::from(b"/tmp/test_open.txt").exists(&fs)); + assert!(crate::path::PathBuf::from(b"/tmp/test_open.txt").exists(fs)); // // cannot remove non-empty directories assert_eq!(