@@ -33,7 +33,7 @@ use rustc_span::{
3333} ;
3434use tracing:: { debug, instrument, trace} ;
3535
36- use crate :: errors:: { FailCreateFileEncoder , FailWriteFile , FailedCreateFile } ;
36+ use crate :: errors:: { FailCreateFileEncoder , FailWriteFile } ;
3737use crate :: rmeta:: * ;
3838
3939pub ( super ) struct EncodeContext < ' a , ' tcx > {
@@ -2240,7 +2240,7 @@ impl EncodedMetadata {
22402240 #[ inline]
22412241 pub fn from_path (
22422242 path : PathBuf ,
2243- reference_path : PathBuf ,
2243+ reference_path : Option < PathBuf > ,
22442244 temp_dir : Option < MaybeTempDir > ,
22452245 ) -> std:: io:: Result < Self > {
22462246 let file = std:: fs:: File :: open ( & path) ?;
@@ -2250,8 +2250,11 @@ impl EncodedMetadata {
22502250 }
22512251 let full_mmap = unsafe { Some ( Mmap :: map ( file) ?) } ;
22522252
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+ } ;
22552258
22562259 Ok ( Self { full_mmap, reference, _temp_dir : temp_dir } )
22572260 }
@@ -2296,7 +2299,7 @@ impl<D: Decoder> Decodable<D> for EncodedMetadata {
22962299 }
22972300}
22982301
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 > ) {
23002303 let _prof_timer = tcx. prof . verbose_generic_activity ( "generate_crate_metadata" ) ;
23012304
23022305 // 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) {
23272330 root. position . get ( )
23282331 } ) ;
23292332
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 {
23332334 with_encode_metadata_header ( tcx, ref_path, |ecx| {
23342335 let header: LazyValue < CrateHeader > = ecx. lazy ( CrateHeader {
23352336 name : tcx. crate_name ( LOCAL_CRATE ) ,
@@ -2340,10 +2341,6 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path, ref_path: &Path) {
23402341 } ) ;
23412342 header. position . get ( )
23422343 } ) ;
2343- } else {
2344- std:: fs:: File :: create ( & ref_path) . unwrap_or_else ( |err| {
2345- tcx. dcx ( ) . emit_fatal ( FailedCreateFile { filename : & ref_path, err } ) ;
2346- } ) ;
23472344 }
23482345}
23492346
0 commit comments