@@ -46,9 +46,8 @@ use rustc_demangle;
46
46
47
47
use std:: any:: Any ;
48
48
use std:: ffi:: { CString , CStr } ;
49
- use std:: fs:: { self , File } ;
50
- use std:: io;
51
- use std:: io:: { Read , Write } ;
49
+ use std:: fs;
50
+ use std:: io:: { self , Write } ;
52
51
use std:: mem;
53
52
use std:: path:: { Path , PathBuf } ;
54
53
use std:: str;
@@ -666,7 +665,7 @@ unsafe fn codegen(cgcx: &CodegenContext,
666
665
timeline. record ( "make-bc" ) ;
667
666
668
667
if write_bc {
669
- if let Err ( e) = File :: create ( & bc_out) . and_then ( | mut f| f . write_all ( data) ) {
668
+ if let Err ( e) = fs :: write ( & bc_out, data) {
670
669
diag_handler. err ( & format ! ( "failed to write bytecode: {}" , e) ) ;
671
670
}
672
671
timeline. record ( "write-bc" ) ;
@@ -675,7 +674,7 @@ unsafe fn codegen(cgcx: &CodegenContext,
675
674
if config. emit_bc_compressed {
676
675
let dst = bc_out. with_extension ( RLIB_BYTECODE_EXTENSION ) ;
677
676
let data = bytecode:: encode ( & mtrans. llmod_id , data) ;
678
- if let Err ( e) = File :: create ( & dst) . and_then ( | mut f| f . write_all ( & data) ) {
677
+ if let Err ( e) = fs :: write ( & dst, data) {
679
678
diag_handler. err ( & format ! ( "failed to write bytecode: {}" , e) ) ;
680
679
}
681
680
timeline. record ( "compress-bc" ) ;
@@ -799,9 +798,7 @@ fn binaryen_assemble(cgcx: &CodegenContext,
799
798
object : & Path ) {
800
799
use rustc_binaryen:: { Module , ModuleOptions } ;
801
800
802
- let input = File :: open ( & assembly) . and_then ( |mut f| {
803
- let mut contents = Vec :: new ( ) ;
804
- f. read_to_end ( & mut contents) ?;
801
+ let input = fs:: read ( & assembly) . and_then ( |contents| {
805
802
Ok ( CString :: new ( contents) ?)
806
803
} ) ;
807
804
let mut options = ModuleOptions :: new ( ) ;
@@ -818,7 +815,7 @@ fn binaryen_assemble(cgcx: &CodegenContext,
818
815
. map_err ( |e| io:: Error :: new ( io:: ErrorKind :: Other , e) )
819
816
} ) ;
820
817
let err = assembled. and_then ( |binary| {
821
- File :: create ( & object) . and_then ( | mut f| f . write_all ( binary. data ( ) ) )
818
+ fs :: write ( & object, binary. data ( ) )
822
819
} ) ;
823
820
if let Err ( e) = err {
824
821
handler. err ( & format ! ( "failed to run binaryen assembler: {}" , e) ) ;
0 commit comments