@@ -40,7 +40,7 @@ use rustc_span::{
4040use rustc_target:: abi:: VariantIdx ;
4141use std:: borrow:: Borrow ;
4242use std:: hash:: Hash ;
43- use std:: io:: { Read , Seek , Write } ;
43+ use std:: io:: { Read , Write } ;
4444use std:: iter;
4545use std:: num:: NonZeroUsize ;
4646use std:: path:: { Path , PathBuf } ;
@@ -2215,9 +2215,6 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>, path: impl AsRef<Path>) {
22152215 . unwrap_or_else ( |err| tcx. sess . fatal ( & format ! ( "failed to create file encoder: {}" , err) ) ) ;
22162216 encoder. emit_raw_bytes ( METADATA_HEADER ) ;
22172217
2218- // Will be filled with the root position after encoding everything.
2219- encoder. emit_raw_bytes ( & [ 0 , 0 , 0 , 0 ] ) ;
2220-
22212218 let source_map_files = tcx. sess . source_map ( ) . files ( ) ;
22222219 let source_file_cache = ( source_map_files[ 0 ] . clone ( ) , 0 ) ;
22232220 let required_source_files = Some ( GrowableBitSet :: with_capacity ( source_map_files. len ( ) ) ) ;
@@ -2247,25 +2244,20 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>, path: impl AsRef<Path>) {
22472244 // culminating in the `CrateRoot` which points to all of it.
22482245 let root = ecx. encode_crate_root ( ) ;
22492246
2250- ecx. opaque . flush ( ) ;
2251- let mut file = std:: fs:: OpenOptions :: new ( )
2252- . write ( true )
2253- . open ( path. as_ref ( ) )
2254- . unwrap_or_else ( |err| tcx. sess . fatal ( & format ! ( "failed to open the file: {}" , err) ) ) ;
2255-
22562247 // Encode the root position.
2257- let header = METADATA_HEADER . len ( ) ;
2258- file. seek ( std:: io:: SeekFrom :: Start ( header as u64 ) )
2259- . unwrap_or_else ( |err| tcx. sess . fatal ( & format ! ( "failed to seek the file: {}" , err) ) ) ;
22602248 let pos = root. position . get ( ) ;
2261- file. write_all ( & [ ( pos >> 24 ) as u8 , ( pos >> 16 ) as u8 , ( pos >> 8 ) as u8 , ( pos >> 0 ) as u8 ] )
2262- . unwrap_or_else ( |err| tcx. sess . fatal ( & format ! ( "failed to write to the file: {}" , err) ) ) ;
2249+ ecx. opaque . emit_raw_bytes ( & [
2250+ ( pos >> 24 ) as u8 ,
2251+ ( pos >> 16 ) as u8 ,
2252+ ( pos >> 8 ) as u8 ,
2253+ ( pos >> 0 ) as u8 ,
2254+ ] ) ;
22632255
22642256 // Record metadata size for self-profiling
22652257 tcx. prof . artifact_size (
22662258 "crate_metadata" ,
22672259 "crate_metadata" ,
2268- file. metadata ( ) . unwrap ( ) . len ( ) as u64 ,
2260+ ecx . opaque . file ( ) . metadata ( ) . unwrap ( ) . len ( ) as u64 ,
22692261 ) ;
22702262}
22712263
0 commit comments