Skip to content

Commit d003bed

Browse files
committed
Fix build and lint errors on MSRV and Stable
1 parent 26abc13 commit d003bed

File tree

5 files changed

+88
-51
lines changed

5 files changed

+88
-51
lines changed

src/error.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ impl From<VfsErrorKind> for VfsError {
2626
let kind = match kind {
2727
VfsErrorKind::IoError(io) => match io.kind() {
2828
io::ErrorKind::NotFound => VfsErrorKind::FileNotFound,
29-
io::ErrorKind::Unsupported => VfsErrorKind::NotSupported,
29+
// TODO: If MSRV changes to 1.53, enable this. Alternatively,
30+
// if it's possible to #[cfg] just this line, try that
31+
// io::ErrorKind::Unsupported => VfsErrorKind::NotSupported,
3032
_ => VfsErrorKind::IoError(io),
3133
},
3234
// Remaining kinda are passed through as-is

src/filesystem.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ pub trait FileSystem: Debug + Sync + Send + 'static {
3535
/// Removes the directory at this path
3636
fn remove_dir(&self, path: &str) -> VfsResult<()>;
3737
/// Copies the src path to the destination path within the same filesystem (optional)
38-
fn copy_file(&self, _src: &str, dest: &str) -> VfsResult<()> {
38+
fn copy_file(&self, _src: &str, _dest: &str) -> VfsResult<()> {
3939
Err(VfsErrorKind::NotSupported.into())
4040
}
4141
/// Moves the src path to the destination path within the same filesystem (optional)
42-
fn move_file(&self, _src: &str, dest: &str) -> VfsResult<()> {
42+
fn move_file(&self, _src: &str, _dest: &str) -> VfsResult<()> {
4343
Err(VfsErrorKind::NotSupported.into())
4444
}
4545
/// Moves the src directory to the destination path within the same filesystem (optional)
46-
fn move_dir(&self, _src: &str, dest: &str) -> VfsResult<()> {
46+
fn move_dir(&self, _src: &str, _dest: &str) -> VfsResult<()> {
4747
Err(VfsErrorKind::NotSupported.into())
4848
}
4949
}

src/impls/embedded.rs

+62-36
Original file line numberDiff line numberDiff line change
@@ -210,18 +210,22 @@ mod tests {
210210
#[test]
211211
fn read_dir_no_directory_err() {
212212
let fs = get_test_fs();
213-
assert!(matches!(
214-
fs.read_dir("/c/f").map(|_| ()).unwrap_err().kind(),
215-
VfsErrorKind::FileNotFound
216-
));
217-
assert!(matches!(
218-
fs.read_dir("/a.txt.").map(|_| ()).unwrap_err().kind(),
219-
VfsErrorKind::FileNotFound
220-
));
221-
assert!(matches!(
222-
fs.read_dir("/abc/def/ghi").map(|_| ()).unwrap_err().kind(),
223-
VfsErrorKind::FileNotFound
224-
));
213+
assert!(match fs.read_dir("/c/f").map(|_| ()).unwrap_err().kind() {
214+
VfsErrorKind::FileNotFound => true,
215+
_ => false,
216+
});
217+
assert!(
218+
match fs.read_dir("/a.txt.").map(|_| ()).unwrap_err().kind() {
219+
VfsErrorKind::FileNotFound => true,
220+
_ => false,
221+
}
222+
);
223+
assert!(
224+
match fs.read_dir("/abc/def/ghi").map(|_| ()).unwrap_err().kind() {
225+
VfsErrorKind::FileNotFound => true,
226+
_ => false,
227+
}
228+
);
225229
}
226230

227231
#[test]
@@ -244,10 +248,12 @@ mod tests {
244248
#[test]
245249
fn create_dir_not_supported() {
246250
let fs = get_test_fs();
247-
assert!(matches!(
248-
fs.create_dir("/abc").map(|_| ()).unwrap_err().kind(),
249-
VfsErrorKind::NotSupported
250-
))
251+
assert!(
252+
match fs.create_dir("/abc").map(|_| ()).unwrap_err().kind() {
253+
VfsErrorKind::NotSupported => true,
254+
_ => false,
255+
}
256+
)
251257
}
252258

253259
#[test]
@@ -278,35 +284,48 @@ mod tests {
278284
// FIXME: These tests have been weakened since the FS implementations aren't intended to
279285
// provide paths for errors. Maybe this could be handled better
280286
assert!(match fs.open_file("/") {
281-
Err(err) => matches!(err.kind(), VfsErrorKind::FileNotFound),
287+
Err(err) => match err.kind() {
288+
VfsErrorKind::FileNotFound => true,
289+
_ => false,
290+
},
282291
_ => false,
283292
});
284293
assert!(match fs.open_file("/abc.txt") {
285-
Err(err) => matches!(err.kind(), VfsErrorKind::FileNotFound),
294+
Err(err) => match err.kind() {
295+
VfsErrorKind::FileNotFound => true,
296+
_ => false,
297+
},
286298
_ => false,
287299
});
288300
assert!(match fs.open_file("/c/f.txt") {
289-
Err(err) => matches!(err.kind(), VfsErrorKind::FileNotFound),
301+
Err(err) => match err.kind() {
302+
VfsErrorKind::FileNotFound => true,
303+
_ => false,
304+
},
290305
_ => false,
291306
});
292307
}
293308

294309
#[test]
295310
fn create_file_not_supported() {
296311
let fs = get_test_fs();
297-
assert!(matches!(
298-
fs.create_file("/abc.txt").map(|_| ()).unwrap_err().kind(),
299-
VfsErrorKind::NotSupported
300-
));
312+
assert!(
313+
match fs.create_file("/abc.txt").map(|_| ()).unwrap_err().kind() {
314+
VfsErrorKind::NotSupported => true,
315+
_ => false,
316+
}
317+
);
301318
}
302319

303320
#[test]
304321
fn append_file_not_supported() {
305322
let fs = get_test_fs();
306-
assert!(matches!(
307-
fs.append_file("/abc.txt").map(|_| ()).unwrap_err().kind(),
308-
VfsErrorKind::NotSupported
309-
));
323+
assert!(
324+
match fs.append_file("/abc.txt").map(|_| ()).unwrap_err().kind() {
325+
VfsErrorKind::NotSupported => true,
326+
_ => false,
327+
}
328+
);
310329
}
311330

312331
#[test]
@@ -342,7 +361,10 @@ mod tests {
342361
fn metadata_not_found() {
343362
let fs = get_test_fs();
344363
assert!(match fs.metadata("/abc.txt") {
345-
Err(err) => matches!(err.kind(), VfsErrorKind::FileNotFound),
364+
Err(err) => match err.kind() {
365+
VfsErrorKind::FileNotFound => true,
366+
_ => false,
367+
},
346368
_ => false,
347369
});
348370
}
@@ -367,19 +389,23 @@ mod tests {
367389
#[test]
368390
fn remove_file_not_supported() {
369391
let fs = get_test_fs();
370-
assert!(matches!(
371-
fs.remove_file("/abc.txt").map(|_| ()).unwrap_err().kind(),
372-
VfsErrorKind::NotSupported
373-
));
392+
assert!(
393+
match fs.remove_file("/abc.txt").map(|_| ()).unwrap_err().kind() {
394+
VfsErrorKind::NotSupported => true,
395+
_ => false,
396+
}
397+
);
374398
}
375399

376400
#[test]
377401
fn remove_dir_not_supported() {
378402
let fs = get_test_fs();
379-
assert!(matches!(
380-
fs.remove_dir("/abc.txt").map(|_| ()).unwrap_err().kind(),
381-
VfsErrorKind::NotSupported
382-
));
403+
assert!(
404+
match fs.remove_dir("/abc.txt").map(|_| ()).unwrap_err().kind() {
405+
VfsErrorKind::NotSupported => true,
406+
_ => false,
407+
}
408+
);
383409
}
384410

385411
#[test]

src/impls/memory.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl FileSystem for MemoryFS {
162162
fn open_file(&self, path: &str) -> VfsResult<Box<dyn SeekAndRead>> {
163163
let handle = self.handle.read().unwrap();
164164
let file = handle.files.get(path).ok_or(VfsErrorKind::FileNotFound)?;
165-
ensure_file(path, file)?;
165+
ensure_file(file)?;
166166
Ok(Box::new(ReadableFile {
167167
content: file.content.clone(),
168168
position: 0,
@@ -356,7 +356,7 @@ mod tests {
356356
}
357357
}
358358

359-
fn ensure_file(path: &str, file: &MemoryFile) -> VfsResult<()> {
359+
fn ensure_file(file: &MemoryFile) -> VfsResult<()> {
360360
if file.file_type != VfsFileType::File {
361361
return Err(VfsErrorKind::Other("Not a file".into()).into());
362362
}

src/path.rs

+18-9
Original file line numberDiff line numberDiff line change
@@ -673,9 +673,12 @@ impl VfsPath {
673673
if Arc::ptr_eq(&self.fs, &destination.fs) {
674674
let result = self.fs.fs.copy_file(&self.path, &destination.path);
675675
match result {
676-
Err(err) if matches!(err.kind(), VfsErrorKind::NotSupported) => {
677-
// continue
678-
}
676+
Err(err) => match err.kind() {
677+
VfsErrorKind::NotSupported => {
678+
// continue
679+
}
680+
_ => return Err(err),
681+
},
679682
other => return other,
680683
}
681684
}
@@ -729,9 +732,12 @@ impl VfsPath {
729732
if Arc::ptr_eq(&self.fs, &destination.fs) {
730733
let result = self.fs.fs.move_file(&self.path, &destination.path);
731734
match result {
732-
Err(err) if matches!(err.kind(), VfsErrorKind::NotSupported) => {
733-
// continue
734-
}
735+
Err(err) => match err.kind() {
736+
VfsErrorKind::NotSupported => {
737+
// continue
738+
}
739+
_ => return Err(err),
740+
},
735741
other => return other,
736742
}
737743
}
@@ -840,9 +846,12 @@ impl VfsPath {
840846
if Arc::ptr_eq(&self.fs, &destination.fs) {
841847
let result = self.fs.fs.move_dir(&self.path, &destination.path);
842848
match result {
843-
Err(err) if matches!(err.kind(), VfsErrorKind::NotSupported) => {
844-
// continue
845-
}
849+
Err(err) => match err.kind() {
850+
VfsErrorKind::NotSupported => {
851+
// continue
852+
}
853+
_ => return Err(err),
854+
},
846855
other => return other,
847856
}
848857
}

0 commit comments

Comments
 (0)