File tree 1 file changed +7
-4
lines changed
compiler/rustc_metadata/src/rmeta
1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -2254,10 +2254,10 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>, path: &Path) {
2254
2254
let root = ecx. encode_crate_root ( ) ;
2255
2255
2256
2256
ecx. opaque . flush ( ) ;
2257
- let mut file = std :: fs :: OpenOptions :: new ( )
2258
- . write ( true )
2259
- . open ( path )
2260
- . unwrap_or_else ( |err| tcx . sess . fatal ( & format ! ( "failed to open the file: {}" , err ) ) ) ;
2257
+
2258
+ let mut file = ecx . opaque . file ( ) ;
2259
+ // We will return to this position after writing the root position.
2260
+ let pos_before_seek = file . stream_position ( ) . unwrap ( ) ;
2261
2261
2262
2262
// Encode the root position.
2263
2263
let header = METADATA_HEADER . len ( ) ;
@@ -2267,6 +2267,9 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>, path: &Path) {
2267
2267
file. write_all ( & [ ( pos >> 24 ) as u8 , ( pos >> 16 ) as u8 , ( pos >> 8 ) as u8 , ( pos >> 0 ) as u8 ] )
2268
2268
. unwrap_or_else ( |err| tcx. sess . fatal ( & format ! ( "failed to write to the file: {}" , err) ) ) ;
2269
2269
2270
+ // Return to the position where we are before writing the root position.
2271
+ file. seek ( std:: io:: SeekFrom :: Start ( pos_before_seek) ) . unwrap ( ) ;
2272
+
2270
2273
// Record metadata size for self-profiling
2271
2274
tcx. prof . artifact_size (
2272
2275
"crate_metadata" ,
You can’t perform that action at this time.
0 commit comments