1818
1919const TEMPFILE_ATTEMPTS : u32 = 100 ;
2020
21- use libc;
22- use nix;
23- use openat;
2421use rand:: Rng ;
2522use std:: ffi:: OsStr ;
2623use std:: fs:: File ;
@@ -140,7 +137,7 @@ pub trait OpenatDirExt {
140137
141138 /// Create a `FileWriter` which provides a `std::io::BufWriter` and then atomically creates
142139 /// the file at the destination, renaming it over an existing one if necessary.
143- fn new_file_writer < ' a > ( & ' a self , mode : libc:: mode_t ) -> io:: Result < FileWriter > ;
140+ fn new_file_writer ( & self , mode : libc:: mode_t ) -> io:: Result < FileWriter > ;
144141
145142 /// Atomically create or replace the destination file, calling the provided
146143 /// function to generate the contents. Note that the contents of the
@@ -220,7 +217,7 @@ impl OpenatDirExt for openat::Dir {
220217 }
221218
222219 fn remove_file_optional < P : openat:: AsPath > ( & self , p : P ) -> io:: Result < bool > {
223- Ok ( impl_remove_file_optional ( self , p) ? )
220+ impl_remove_file_optional ( self , p)
224221 }
225222
226223 fn remove_dir_optional < P : openat:: AsPath > ( & self , p : P ) -> io:: Result < bool > {
@@ -414,8 +411,8 @@ impl OpenatDirExt for openat::Dir {
414411 Ok ( ( ) )
415412 }
416413
417- fn new_file_writer < ' a > ( & ' a self , mode : libc:: mode_t ) -> io:: Result < FileWriter > {
418- let ( tmpf, name) = if let Some ( tmpf) = self . new_unnamed_file ( mode) . ok ( ) {
414+ fn new_file_writer ( & self , mode : libc:: mode_t ) -> io:: Result < FileWriter > {
415+ let ( tmpf, name) = if let Ok ( tmpf) = self . new_unnamed_file ( mode) {
419416 ( tmpf, None )
420417 } else {
421418 // FIXME allow this to be configurable
@@ -433,10 +430,7 @@ fn impl_read_to_string(mut f: File) -> io::Result<String> {
433430}
434431
435432fn map_nix_error ( e : nix:: Error ) -> io:: Error {
436- match e. as_errno ( ) {
437- Some ( os_err) => io:: Error :: from_raw_os_error ( os_err as i32 ) ,
438- _ => io:: Error :: new ( io:: ErrorKind :: Other , e) ,
439- }
433+ io:: Error :: from_raw_os_error ( e as i32 )
440434}
441435
442436fn copy_regfile_inner (
@@ -501,7 +495,7 @@ pub(crate) fn tempfile_in(
501495 match d. new_file ( tmpname. as_str ( ) , mode) {
502496 Ok ( f) => return Ok ( ( f, tmpname) ) ,
503497 Err ( ref e) if e. kind ( ) == io:: ErrorKind :: AlreadyExists => continue ,
504- Err ( e) => Err ( e) ? ,
498+ Err ( e) => return Err ( e) ,
505499 }
506500 }
507501 Err ( io:: Error :: new (
@@ -518,7 +512,7 @@ pub(crate) fn tempfile_in(
518512/// optimal case where all components exist above.
519513pub ( crate ) fn impl_ensure_dir_all ( d : & openat:: Dir , p : & Path , mode : libc:: mode_t ) -> io:: Result < ( ) > {
520514 if let Some ( parent) = p. parent ( ) {
521- if parent. as_os_str ( ) . len ( ) > 0 {
515+ if ! parent. as_os_str ( ) . is_empty ( ) {
522516 impl_ensure_dir_all ( d, parent, mode) ?;
523517 }
524518 }
@@ -734,22 +728,22 @@ impl FileExt for File {
734728 let copy_result =
735729 copy_file_range ( self . as_raw_fd ( ) , None , to. as_raw_fd ( ) , None , bytes_to_copy) ;
736730 if let Err ( ref copy_err) = copy_result {
737- match copy_err. as_errno ( ) {
738- Some ( Errno :: ENOSYS ) | Some ( Errno :: EPERM ) => {
731+ match copy_err {
732+ Errno :: ENOSYS | Errno :: EPERM => {
739733 HAS_COPY_FILE_RANGE . store ( false , Ordering :: Relaxed ) ;
740734 }
741735 _ => { }
742736 }
743737 }
744738 copy_result
745739 } else {
746- Err ( nix :: Error :: from_errno ( Errno :: ENOSYS ) )
740+ Err ( Errno :: ENOSYS )
747741 } ;
748742 match copy_result {
749743 Ok ( ret) => written += ret as u64 ,
750744 Err ( err) => {
751- match err. as_errno ( ) {
752- Some ( os_err)
745+ match err {
746+ os_err
753747 if os_err == Errno :: ENOSYS
754748 || os_err == Errno :: EXDEV
755749 || os_err == Errno :: EINVAL
@@ -763,8 +757,7 @@ impl FileExt for File {
763757 assert_eq ! ( written, 0 ) ;
764758 return fallback_file_copy ( self , to) ;
765759 }
766- Some ( os_err) => return Err ( io:: Error :: from_raw_os_error ( os_err as i32 ) ) ,
767- _ => return Err ( io:: Error :: new ( io:: ErrorKind :: Other , err) ) ,
760+ os_err => return Err ( map_nix_error ( os_err) ) ,
768761 }
769762 }
770763 }
@@ -785,7 +778,7 @@ impl FileExt for File {
785778 fn pread_exact ( & self , buf : & mut [ u8 ] , start_pos : usize ) -> io:: Result < ( ) > {
786779 use nix:: sys:: uio:: pread;
787780
788- if buf. len ( ) == 0 {
781+ if buf. is_empty ( ) {
789782 return Err ( io:: Error :: new (
790783 io:: ErrorKind :: InvalidInput ,
791784 "zero-sized buffer in input" ,
0 commit comments