@@ -40,7 +40,7 @@ use rustc_span::{
40
40
use rustc_target:: abi:: VariantIdx ;
41
41
use std:: borrow:: Borrow ;
42
42
use std:: hash:: Hash ;
43
- use std:: io:: { Read , Seek , Write } ;
43
+ use std:: io:: { Read , Write } ;
44
44
use std:: iter;
45
45
use std:: num:: NonZeroUsize ;
46
46
use std:: path:: { Path , PathBuf } ;
@@ -2215,9 +2215,6 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>, path: impl AsRef<Path>) {
2215
2215
. unwrap_or_else ( |err| tcx. sess . fatal ( & format ! ( "failed to create file encoder: {}" , err) ) ) ;
2216
2216
encoder. emit_raw_bytes ( METADATA_HEADER ) ;
2217
2217
2218
- // Will be filled with the root position after encoding everything.
2219
- encoder. emit_raw_bytes ( & [ 0 , 0 , 0 , 0 ] ) ;
2220
-
2221
2218
let source_map_files = tcx. sess . source_map ( ) . files ( ) ;
2222
2219
let source_file_cache = ( source_map_files[ 0 ] . clone ( ) , 0 ) ;
2223
2220
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>) {
2247
2244
// culminating in the `CrateRoot` which points to all of it.
2248
2245
let root = ecx. encode_crate_root ( ) ;
2249
2246
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
-
2256
2247
// 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) ) ) ;
2260
2248
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
+ ] ) ;
2263
2255
2264
2256
// Record metadata size for self-profiling
2265
2257
tcx. prof . artifact_size (
2266
2258
"crate_metadata" ,
2267
2259
"crate_metadata" ,
2268
- file. metadata ( ) . unwrap ( ) . len ( ) as u64 ,
2260
+ ecx . opaque . file ( ) . metadata ( ) . unwrap ( ) . len ( ) as u64 ,
2269
2261
) ;
2270
2262
}
2271
2263
0 commit comments