@@ -53,7 +53,7 @@ use std::cmp::{self, Ordering};
5353use std:: fmt;
5454use std:: hash:: Hash ;
5555use std:: ops:: { Add , Sub } ;
56- use std:: path:: PathBuf ;
56+ use std:: path:: { Path , PathBuf } ;
5757use std:: str:: FromStr ;
5858
5959use md5:: Md5 ;
@@ -81,11 +81,45 @@ impl Globals {
8181
8282scoped_tls:: scoped_thread_local!( pub static GLOBALS : Globals ) ;
8383
84+ /// FIXME: Perhaps this should not implement Rustc{Decodable, Encodable}
85+ #[ derive( Debug , Eq , PartialEq , Clone , Ord , PartialOrd , Hash , RustcDecodable , RustcEncodable ) ]
86+ #[ derive( HashStable_Generic ) ]
87+ pub enum RealFileName {
88+ Named ( PathBuf ) ,
89+ /// For de-virtualized paths (namely paths into libstd that have been mapped
90+ /// to the appropriate spot on the local host's file system),
91+ Devirtualized {
92+ /// `local_path` is the (host-dependent) local path to the file.
93+ local_path : PathBuf ,
94+ /// `virtual_name` is the stable path rustc will store internally within
95+ /// build artifacts.
96+ virtual_name : PathBuf ,
97+ } ,
98+ }
99+
100+ impl RealFileName {
101+ /// Returns the path suitable for reading from the file system on the local host.
102+ pub fn local_path ( & self ) -> & Path {
103+ match self {
104+ RealFileName :: Named ( p)
105+ | RealFileName :: Devirtualized { local_path : p, virtual_name : _ } => & p,
106+ }
107+ }
108+
109+ /// Returns the path suitable for reading from the file system on the local host.
110+ pub fn into_local_path ( self ) -> PathBuf {
111+ match self {
112+ RealFileName :: Named ( p)
113+ | RealFileName :: Devirtualized { local_path : p, virtual_name : _ } => p,
114+ }
115+ }
116+ }
117+
84118/// Differentiates between real files and common virtual files.
85119#[ derive( Debug , Eq , PartialEq , Clone , Ord , PartialOrd , Hash , RustcDecodable , RustcEncodable ) ]
86120#[ derive( HashStable_Generic ) ]
87121pub enum FileName {
88- Real ( PathBuf ) ,
122+ Real ( RealFileName ) ,
89123 /// Call to `quote!`.
90124 QuoteExpansion ( u64 ) ,
91125 /// Command line.
@@ -107,7 +141,13 @@ impl std::fmt::Display for FileName {
107141 fn fmt ( & self , fmt : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
108142 use FileName :: * ;
109143 match * self {
110- Real ( ref path) => write ! ( fmt, "{}" , path. display( ) ) ,
144+ Real ( RealFileName :: Named ( ref path) ) => write ! ( fmt, "{}" , path. display( ) ) ,
145+ // FIXME: might be nice to display both compoments of Devirtualized.
146+ // But for now (to backport fix for issue #70924), best to not
147+ // perturb diagnostics so its obvious test suite still works.
148+ Real ( RealFileName :: Devirtualized { ref local_path, virtual_name : _ } ) => {
149+ write ! ( fmt, "{}" , local_path. display( ) )
150+ }
111151 QuoteExpansion ( _) => write ! ( fmt, "<quote expansion>" ) ,
112152 MacroExpansion ( _) => write ! ( fmt, "<macro expansion>" ) ,
113153 Anon ( _) => write ! ( fmt, "<anon>" ) ,
@@ -123,7 +163,7 @@ impl std::fmt::Display for FileName {
123163impl From < PathBuf > for FileName {
124164 fn from ( p : PathBuf ) -> Self {
125165 assert ! ( !p. to_string_lossy( ) . ends_with( '>' ) ) ;
126- FileName :: Real ( p )
166+ FileName :: Real ( RealFileName :: Named ( p ) )
127167 }
128168}
129169
0 commit comments