@@ -49,7 +49,7 @@ use std::cmp::{self, Ordering};
4949use std:: fmt;
5050use std:: hash:: Hash ;
5151use std:: ops:: { Add , Sub } ;
52- use std:: path:: PathBuf ;
52+ use std:: path:: { Path , PathBuf } ;
5353use std:: str:: FromStr ;
5454
5555use md5:: Md5 ;
@@ -77,11 +77,45 @@ impl Globals {
7777
7878scoped_tls:: scoped_thread_local!( pub static GLOBALS : Globals ) ;
7979
80+ /// FIXME: Perhaps this should not implement Rustc{Decodable, Encodable}
81+ #[ derive( Debug , Eq , PartialEq , Clone , Ord , PartialOrd , Hash , RustcDecodable , RustcEncodable ) ]
82+ #[ derive( HashStable_Generic ) ]
83+ pub enum RealFileName {
84+ Named ( PathBuf ) ,
85+ /// For de-virtualized paths (namely paths into libstd that have been mapped
86+ /// to the appropriate spot on the local host's file system),
87+ Devirtualized {
88+ /// `local_path` is the (host-dependent) local path to the file.
89+ local_path : PathBuf ,
90+ /// `virtual_name` is the stable path rustc will store internally within
91+ /// build artifacts.
92+ virtual_name : PathBuf ,
93+ } ,
94+ }
95+
96+ impl RealFileName {
97+ /// Returns the path suitable for reading from the file system on the local host.
98+ pub fn local_path ( & self ) -> & Path {
99+ match self {
100+ RealFileName :: Named ( p)
101+ | RealFileName :: Devirtualized { local_path : p, virtual_name : _ } => & p,
102+ }
103+ }
104+
105+ /// Returns the path suitable for reading from the file system on the local host.
106+ pub fn into_local_path ( self ) -> PathBuf {
107+ match self {
108+ RealFileName :: Named ( p)
109+ | RealFileName :: Devirtualized { local_path : p, virtual_name : _ } => p,
110+ }
111+ }
112+ }
113+
80114/// Differentiates between real files and common virtual files.
81115#[ derive( Debug , Eq , PartialEq , Clone , Ord , PartialOrd , Hash , RustcDecodable , RustcEncodable ) ]
82116#[ derive( HashStable_Generic ) ]
83117pub enum FileName {
84- Real ( PathBuf ) ,
118+ Real ( RealFileName ) ,
85119 /// Call to `quote!`.
86120 QuoteExpansion ( u64 ) ,
87121 /// Command line.
@@ -103,7 +137,13 @@ impl std::fmt::Display for FileName {
103137 fn fmt ( & self , fmt : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
104138 use FileName :: * ;
105139 match * self {
106- Real ( ref path) => write ! ( fmt, "{}" , path. display( ) ) ,
140+ Real ( RealFileName :: Named ( ref path) ) => write ! ( fmt, "{}" , path. display( ) ) ,
141+ // FIXME: might be nice to display both compoments of Devirtualized.
142+ // But for now (to backport fix for issue #70924), best to not
143+ // perturb diagnostics so its obvious test suite still works.
144+ Real ( RealFileName :: Devirtualized { ref local_path, virtual_name : _ } ) => {
145+ write ! ( fmt, "{}" , local_path. display( ) )
146+ }
107147 QuoteExpansion ( _) => write ! ( fmt, "<quote expansion>" ) ,
108148 MacroExpansion ( _) => write ! ( fmt, "<macro expansion>" ) ,
109149 Anon ( _) => write ! ( fmt, "<anon>" ) ,
@@ -119,7 +159,7 @@ impl std::fmt::Display for FileName {
119159impl From < PathBuf > for FileName {
120160 fn from ( p : PathBuf ) -> Self {
121161 assert ! ( !p. to_string_lossy( ) . ends_with( '>' ) ) ;
122- FileName :: Real ( p )
162+ FileName :: Real ( RealFileName :: Named ( p ) )
123163 }
124164}
125165
0 commit comments