@@ -30,22 +30,20 @@ const HEADER_FORMAT_VERSION: u16 = 0;
30
30
/// the Git commit hash.
31
31
const RUSTC_VERSION : Option < & str > = option_env ! ( "CFG_VERSION" ) ;
32
32
33
- pub ( crate ) fn write_file_header ( stream : & mut FileEncoder , nightly_build : bool ) -> FileEncodeResult {
34
- stream. emit_raw_bytes ( FILE_MAGIC ) ?;
35
- stream. emit_raw_bytes ( & [
36
- ( HEADER_FORMAT_VERSION >> 0 ) as u8 ,
37
- ( HEADER_FORMAT_VERSION >> 8 ) as u8 ,
38
- ] ) ?;
33
+ pub ( crate ) fn write_file_header ( stream : & mut FileEncoder , nightly_build : bool ) {
34
+ stream. emit_raw_bytes ( FILE_MAGIC ) ;
35
+ stream
36
+ . emit_raw_bytes ( & [ ( HEADER_FORMAT_VERSION >> 0 ) as u8 , ( HEADER_FORMAT_VERSION >> 8 ) as u8 ] ) ;
39
37
40
38
let rustc_version = rustc_version ( nightly_build) ;
41
39
assert_eq ! ( rustc_version. len( ) , ( rustc_version. len( ) as u8 ) as usize ) ;
42
- stream. emit_raw_bytes ( & [ rustc_version. len ( ) as u8 ] ) ? ;
43
- stream. emit_raw_bytes ( rustc_version. as_bytes ( ) )
40
+ stream. emit_raw_bytes ( & [ rustc_version. len ( ) as u8 ] ) ;
41
+ stream. emit_raw_bytes ( rustc_version. as_bytes ( ) ) ;
44
42
}
45
43
46
44
pub ( crate ) fn save_in < F > ( sess : & Session , path_buf : PathBuf , name : & str , encode : F )
47
45
where
48
- F : FnOnce ( & mut FileEncoder ) -> FileEncodeResult ,
46
+ F : FnOnce ( FileEncoder ) -> FileEncodeResult ,
49
47
{
50
48
debug ! ( "save: storing data in {}" , path_buf. display( ) ) ;
51
49
@@ -80,28 +78,21 @@ where
80
78
}
81
79
} ;
82
80
83
- if let Err ( err) = write_file_header ( & mut encoder, sess. is_nightly_build ( ) ) {
84
- sess. err ( & format ! ( "failed to write {} header to `{}`: {}" , name, path_buf. display( ) , err) ) ;
85
- return ;
86
- }
87
-
88
- if let Err ( err) = encode ( & mut encoder) {
89
- sess. err ( & format ! ( "failed to write {} to `{}`: {}" , name, path_buf. display( ) , err) ) ;
90
- return ;
91
- }
81
+ write_file_header ( & mut encoder, sess. is_nightly_build ( ) ) ;
92
82
93
- if let Err ( err) = encoder. flush ( ) {
94
- sess. err ( & format ! ( "failed to flush {} to `{}`: {}" , name, path_buf. display( ) , err) ) ;
95
- return ;
83
+ match encode ( encoder) {
84
+ Ok ( position) => {
85
+ sess. prof . artifact_size (
86
+ & name. replace ( ' ' , "_" ) ,
87
+ path_buf. file_name ( ) . unwrap ( ) . to_string_lossy ( ) ,
88
+ position as u64 ,
89
+ ) ;
90
+ debug ! ( "save: data written to disk successfully" ) ;
91
+ }
92
+ Err ( err) => {
93
+ sess. err ( & format ! ( "failed to write {} to `{}`: {}" , name, path_buf. display( ) , err) ) ;
94
+ }
96
95
}
97
-
98
- sess. prof . artifact_size (
99
- & name. replace ( ' ' , "_" ) ,
100
- path_buf. file_name ( ) . unwrap ( ) . to_string_lossy ( ) ,
101
- encoder. position ( ) as u64 ,
102
- ) ;
103
-
104
- debug ! ( "save: data written to disk successfully" ) ;
105
96
}
106
97
107
98
/// Reads the contents of a file with a file header as defined in this module.
0 commit comments