@@ -33,7 +33,7 @@ use rustc_span::{
33
33
} ;
34
34
use tracing:: { debug, instrument, trace} ;
35
35
36
- use crate :: errors:: { FailCreateFileEncoder , FailWriteFile , FailedCreateFile } ;
36
+ use crate :: errors:: { FailCreateFileEncoder , FailWriteFile } ;
37
37
use crate :: rmeta:: * ;
38
38
39
39
pub ( super ) struct EncodeContext < ' a , ' tcx > {
@@ -2240,7 +2240,7 @@ impl EncodedMetadata {
2240
2240
#[ inline]
2241
2241
pub fn from_path (
2242
2242
path : PathBuf ,
2243
- reference_path : PathBuf ,
2243
+ reference_path : Option < PathBuf > ,
2244
2244
temp_dir : Option < MaybeTempDir > ,
2245
2245
) -> std:: io:: Result < Self > {
2246
2246
let file = std:: fs:: File :: open ( & path) ?;
@@ -2250,8 +2250,11 @@ impl EncodedMetadata {
2250
2250
}
2251
2251
let full_mmap = unsafe { Some ( Mmap :: map ( file) ?) } ;
2252
2252
2253
- let reference = std:: fs:: read ( reference_path) ?;
2254
- let reference = if reference. is_empty ( ) { None } else { Some ( reference) } ;
2253
+ let reference = if let Some ( reference_path) = reference_path {
2254
+ Some ( std:: fs:: read ( reference_path) ?)
2255
+ } else {
2256
+ None
2257
+ } ;
2255
2258
2256
2259
Ok ( Self { full_mmap, reference, _temp_dir : temp_dir } )
2257
2260
}
@@ -2296,7 +2299,7 @@ impl<D: Decoder> Decodable<D> for EncodedMetadata {
2296
2299
}
2297
2300
}
2298
2301
2299
- pub fn encode_metadata ( tcx : TyCtxt < ' _ > , path : & Path , ref_path : & Path ) {
2302
+ pub fn encode_metadata ( tcx : TyCtxt < ' _ > , path : & Path , ref_path : Option < & Path > ) {
2300
2303
let _prof_timer = tcx. prof . verbose_generic_activity ( "generate_crate_metadata" ) ;
2301
2304
2302
2305
// Since encoding metadata is not in a query, and nothing is cached,
@@ -2327,9 +2330,7 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path, ref_path: &Path) {
2327
2330
root. position . get ( )
2328
2331
} ) ;
2329
2332
2330
- if tcx. sess . opts . unstable_opts . split_metadata
2331
- && !tcx. crate_types ( ) . contains ( & CrateType :: ProcMacro )
2332
- {
2333
+ if let Some ( ref_path) = ref_path {
2333
2334
with_encode_metadata_header ( tcx, ref_path, |ecx| {
2334
2335
let header: LazyValue < CrateHeader > = ecx. lazy ( CrateHeader {
2335
2336
name : tcx. crate_name ( LOCAL_CRATE ) ,
@@ -2340,10 +2341,6 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path, ref_path: &Path) {
2340
2341
} ) ;
2341
2342
header. position . get ( )
2342
2343
} ) ;
2343
- } else {
2344
- std:: fs:: File :: create ( & ref_path) . unwrap_or_else ( |err| {
2345
- tcx. dcx ( ) . emit_fatal ( FailedCreateFile { filename : & ref_path, err } ) ;
2346
- } ) ;
2347
2344
}
2348
2345
}
2349
2346
0 commit comments