Skip to content

Commit 0edf34e

Browse files
sidneychangimeoer
authored andcommitted
fix: satisfy newer Clippy lints to pass CI on latest Rust
- replace Error::new(ErrorKind::Other, ...) with Error::other(...) - replace iter().map(|(_, v)| v.clone()) with values().map(|v| v.clone()) - add explicit `'_` lifetime in IoctlData return type - ensures compatibility with clippy --deny warnings on newer Rust
1 parent 22cf6a6 commit 0edf34e

File tree

14 files changed

+56
-71
lines changed

14 files changed

+56
-71
lines changed

src/api/filesystem/sync_io.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ pub trait FileSystem {
863863
cmd: u32,
864864
data: IoctlData,
865865
out_size: u32,
866-
) -> io::Result<IoctlData> {
866+
) -> io::Result<IoctlData<'_>> {
867867
// Rather than ENOSYS, let's return ENOTTY so simulate that the ioctl call is implemented
868868
// but no ioctl number is supported.
869869
Err(io::Error::from_raw_os_error(libc::ENOTTY))
@@ -1313,7 +1313,7 @@ impl<FS: FileSystem> FileSystem for Arc<FS> {
13131313
cmd: u32,
13141314
data: IoctlData,
13151315
out_size: u32,
1316-
) -> io::Result<IoctlData> {
1316+
) -> io::Result<IoctlData<'_>> {
13171317
self.deref()
13181318
.ioctl(ctx, inode, handle, flags, cmd, data, out_size)
13191319
}

src/api/vfs/mod.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::collections::HashMap;
2020
use std::ffi::CStr;
2121
use std::fmt;
2222
use std::io;
23-
use std::io::{Error, ErrorKind, Result};
23+
use std::io::{Error, Result};
2424
use std::ops::Deref;
2525
use std::sync::atomic::{AtomicBool, AtomicU8, Ordering};
2626
use std::sync::{Arc, Mutex};
@@ -434,13 +434,10 @@ impl Vfs {
434434
pub fn restore_mount(&self, fs: BackFileSystem, fs_idx: VfsIndex, path: &str) -> Result<()> {
435435
let (entry, ino) = fs.mount()?;
436436
if ino > VFS_MAX_INO {
437-
return Err(Error::new(
438-
ErrorKind::Other,
439-
format!(
440-
"Unsupported max inode number, requested {} supported {}",
441-
ino, VFS_MAX_INO
442-
),
443-
));
437+
return Err(Error::other(format!(
438+
"Unsupported max inode number, requested {} supported {}",
439+
ino, VFS_MAX_INO
440+
)));
444441
}
445442

446443
let _guard = self.lock.lock().unwrap();
@@ -535,10 +532,9 @@ impl Vfs {
535532
return Ok(inode);
536533
}
537534
if inode > VFS_MAX_INO {
538-
return Err(Error::new(
539-
ErrorKind::Other,
540-
format!("Inode number {inode} too large, max supported {VFS_MAX_INO}"),
541-
));
535+
return Err(Error::other(format!(
536+
"Inode number {inode} too large, max supported {VFS_MAX_INO}"
537+
)));
542538
}
543539
let ino: u64 = ((fs_idx as u64) << VFS_INDEX_SHIFT) | inode;
544540
trace!(
@@ -630,10 +626,7 @@ impl Vfs {
630626
}
631627
}
632628

633-
Err(Error::new(
634-
ErrorKind::Other,
635-
"vfs maximum mountpoints reached",
636-
))
629+
Err(Error::other("vfs maximum mountpoints reached"))
637630
}
638631

639632
fn get_fs_by_idx(&self, fs_idx: VfsIndex) -> Result<Arc<BackFileSystem>> {

src/common/file_buf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,13 @@ impl FileVolatileBuf {
315315
}
316316

317317
/// Generate an `IoSlice` object to read data from the buffer.
318-
pub fn io_slice(&self) -> IoSlice {
318+
pub fn io_slice(&self) -> IoSlice<'_> {
319319
let buf = unsafe { slice::from_raw_parts(self.addr as *const u8, self.size) };
320320
IoSlice::new(buf)
321321
}
322322

323323
/// Generate an `IoSliceMut` object to write data into the buffer.
324-
pub fn io_slice_mut(&self) -> IoSliceMut {
324+
pub fn io_slice_mut(&self) -> IoSliceMut<'_> {
325325
let buf = unsafe {
326326
let ptr = (self.addr as *mut u8).add(self.size);
327327
let sz = self.cap - self.size;

src/overlayfs/inode_store.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (C) 2023 Ant Group. All rights reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use std::io::{Error, ErrorKind, Result};
4+
use std::io::{Error, Result};
55
use std::{
66
collections::HashMap,
77
sync::{atomic::Ordering, Arc},
@@ -45,10 +45,10 @@ impl InodeStore {
4545
ino += 1;
4646
}
4747
error!("reached maximum inode number: {}", VFS_MAX_INO);
48-
Err(Error::new(
49-
ErrorKind::Other,
50-
format!("maximum inode number {} reached", VFS_MAX_INO),
51-
))
48+
Err(Error::other(format!(
49+
"maximum inode number {} reached",
50+
VFS_MAX_INO
51+
)))
5252
}
5353

5454
pub(crate) fn alloc_inode(&mut self, path: &String) -> Result<Inode> {

src/overlayfs/mod.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ impl OverlayInode {
701701
let pnode = if let Some(n) = self.parent.lock().unwrap().upgrade() {
702702
Arc::clone(&n)
703703
} else {
704-
return Err(Error::new(ErrorKind::Other, "no parent?"));
704+
return Err(Error::other("no parent?"));
705705
};
706706

707707
if !pnode.in_upper_layer() {
@@ -818,13 +818,10 @@ impl OverlayInode {
818818
f(None)
819819
}
820820
}
821-
None => Err(Error::new(
822-
ErrorKind::Other,
823-
format!(
824-
"BUG: dangling OverlayInode {} without any backend inode",
825-
self.inode
826-
),
827-
)),
821+
None => Err(Error::other(format!(
822+
"BUG: dangling OverlayInode {} without any backend inode",
823+
self.inode
824+
))),
828825
}
829826
}
830827
}
@@ -1119,7 +1116,7 @@ impl OverlayFs {
11191116
let all_inodes = ovi.real_inodes.lock().unwrap();
11201117
let real_inode = all_inodes
11211118
.first()
1122-
.ok_or(Error::new(ErrorKind::Other, "backend inode not found"))?;
1119+
.ok_or(Error::other("backend inode not found"))?;
11231120
real_inode.layer.statfs(ctx, real_inode.inode)
11241121
}
11251122
None => Err(Error::from_raw_os_error(libc::ENOENT)),
@@ -1694,7 +1691,7 @@ impl OverlayFs {
16941691
let parent_node = if let Some(ref n) = node.parent.lock().unwrap().upgrade() {
16951692
Arc::clone(n)
16961693
} else {
1697-
return Err(Error::new(ErrorKind::Other, "no parent?"));
1694+
return Err(Error::other("no parent?"));
16981695
};
16991696

17001697
let (self_layer, _, self_inode) = node.first_layer_inode();
@@ -1736,7 +1733,7 @@ impl OverlayFs {
17361733
let parent_node = if let Some(ref n) = node.parent.lock().unwrap().upgrade() {
17371734
Arc::clone(n)
17381735
} else {
1739-
return Err(Error::new(ErrorKind::Other, "no parent?"));
1736+
return Err(Error::other("no parent?"));
17401737
};
17411738

17421739
let st = node.stat64(ctx)?;
@@ -2027,8 +2024,8 @@ impl OverlayFs {
20272024
.childrens
20282025
.lock()
20292026
.unwrap()
2030-
.iter()
2031-
.map(|(_, v)| v.clone())
2027+
.values()
2028+
.cloned()
20322029
.collect::<Vec<_>>();
20332030

20342031
for child in iter {

src/overlayfs/sync_io.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::api::filesystem::{
1616
};
1717

1818
use libc;
19-
use std::io::{Error, ErrorKind};
19+
use std::io::Error;
2020

2121
impl FileSystem for OverlayFs {
2222
type Inode = Inode;
@@ -350,7 +350,7 @@ impl FileSystem for OverlayFs {
350350
let rh = if let Some(ref h) = hd.real_handle {
351351
h
352352
} else {
353-
return Err(Error::new(ErrorKind::Other, "no handle"));
353+
return Err(Error::other("no handle"));
354354
};
355355
let real_handle = rh.handle.load(Ordering::Relaxed);
356356
let real_inode = rh.inode;

src/passthrough/mod.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl InodeMap {
238238
.cloned()
239239
}
240240

241-
fn get_map_mut(&self) -> RwLockWriteGuard<InodeStore> {
241+
fn get_map_mut(&self) -> RwLockWriteGuard<'_, InodeStore> {
242242
// Do not expect poisoned lock here, so safe to unwrap().
243243
self.inodes.write().unwrap()
244244
}
@@ -275,11 +275,11 @@ impl HandleData {
275275
&self.file
276276
}
277277

278-
fn get_file_mut(&self) -> (MutexGuard<()>, &File) {
278+
fn get_file_mut(&self) -> (MutexGuard<'_, ()>, &File) {
279279
(self.lock.lock().unwrap(), &self.file)
280280
}
281281

282-
fn borrow_fd(&self) -> BorrowedFd {
282+
fn borrow_fd(&self) -> BorrowedFd<'_> {
283283
self.file.as_fd()
284284
}
285285

@@ -706,10 +706,9 @@ impl<S: BitmapSlice + Send + Sync> PassthroughFs<S> {
706706

707707
if inode > VFS_MAX_INO {
708708
error!("fuse: max inode number reached: {}", VFS_MAX_INO);
709-
return Err(io::Error::new(
710-
io::ErrorKind::Other,
711-
format!("max inode number reached: {VFS_MAX_INO}"),
712-
));
709+
return Err(io::Error::other(format!(
710+
"max inode number reached: {VFS_MAX_INO}"
711+
)));
713712
}
714713

715714
InodeMap::insert_locked(

src/passthrough/mount_fd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub struct MountFd {
2424
}
2525

2626
impl AsFd for MountFd {
27-
fn as_fd(&self) -> BorrowedFd {
27+
fn as_fd(&self) -> BorrowedFd<'_> {
2828
self.file.as_fd()
2929
}
3030
}

src/passthrough/util.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ impl UniqueInodeGenerator {
5353
btree_map::Entry::Occupied(v) => *v.get(),
5454
btree_map::Entry::Vacant(v) => {
5555
if self.next_unique_id.load(Ordering::Relaxed) == u8::MAX {
56-
return Err(io::Error::new(
57-
io::ErrorKind::Other,
56+
return Err(io::Error::other(
5857
"the number of combinations of dev and mntid exceeds 255",
5958
));
6059
}
@@ -69,10 +68,10 @@ impl UniqueInodeGenerator {
6968
id.ino
7069
} else {
7170
if self.next_virtual_inode.load(Ordering::Relaxed) > MAX_HOST_INO {
72-
return Err(io::Error::new(
73-
io::ErrorKind::Other,
74-
format!("the virtual inode excess {}", MAX_HOST_INO),
75-
));
71+
return Err(io::Error::other(format!(
72+
"the virtual inode excess {}",
73+
MAX_HOST_INO
74+
)));
7675
}
7776
self.next_virtual_inode.fetch_add(1, Ordering::Relaxed) | VIRTUAL_INODE_FLAG
7877
};

src/transport/fusedev/fuse_t_session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ impl FuseChannel {
310310
/// - Ok(None): signal has pending on the exiting event channel
311311
/// - Ok(Some((reader, writer))): reader to receive request and writer to send reply
312312
/// - Err(e): error message
313-
pub fn get_request(&mut self) -> Result<Option<(Reader, FuseDevWriter)>> {
313+
pub fn get_request(&mut self) -> Result<Option<(Reader<'_>, FuseDevWriter<'_>)>> {
314314
let file_lock = self.file_lock.clone();
315315
let result = file_lock.lock();
316316
let fd = self.file.as_raw_fd();

0 commit comments

Comments
 (0)