File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed
compiler/rustc_metadata/src/rmeta Expand file tree Collapse file tree 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) {
22542254 let root = ecx. encode_crate_root ( ) ;
22552255
22562256 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 ( ) ;
22612261
22622262 // Encode the root position.
22632263 let header = METADATA_HEADER . len ( ) ;
@@ -2267,6 +2267,9 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>, path: &Path) {
22672267 file. write_all ( & [ ( pos >> 24 ) as u8 , ( pos >> 16 ) as u8 , ( pos >> 8 ) as u8 , ( pos >> 0 ) as u8 ] )
22682268 . unwrap_or_else ( |err| tcx. sess . fatal ( & format ! ( "failed to write to the file: {}" , err) ) ) ;
22692269
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+
22702273 // Record metadata size for self-profiling
22712274 tcx. prof . artifact_size (
22722275 "crate_metadata" ,
You can’t perform that action at this time.
0 commit comments