@@ -53,7 +53,7 @@ use std::cmp::{self, Ordering};
53
53
use std:: fmt;
54
54
use std:: hash:: Hash ;
55
55
use std:: ops:: { Add , Sub } ;
56
- use std:: path:: PathBuf ;
56
+ use std:: path:: { Path , PathBuf } ;
57
57
use std:: str:: FromStr ;
58
58
59
59
use md5:: Md5 ;
@@ -81,11 +81,45 @@ impl Globals {
81
81
82
82
scoped_tls:: scoped_thread_local!( pub static GLOBALS : Globals ) ;
83
83
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
+
84
118
/// Differentiates between real files and common virtual files.
85
119
#[ derive( Debug , Eq , PartialEq , Clone , Ord , PartialOrd , Hash , RustcDecodable , RustcEncodable ) ]
86
120
#[ derive( HashStable_Generic ) ]
87
121
pub enum FileName {
88
- Real ( PathBuf ) ,
122
+ Real ( RealFileName ) ,
89
123
/// Call to `quote!`.
90
124
QuoteExpansion ( u64 ) ,
91
125
/// Command line.
@@ -107,7 +141,13 @@ impl std::fmt::Display for FileName {
107
141
fn fmt ( & self , fmt : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
108
142
use FileName :: * ;
109
143
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
+ }
111
151
QuoteExpansion ( _) => write ! ( fmt, "<quote expansion>" ) ,
112
152
MacroExpansion ( _) => write ! ( fmt, "<macro expansion>" ) ,
113
153
Anon ( _) => write ! ( fmt, "<anon>" ) ,
@@ -123,7 +163,7 @@ impl std::fmt::Display for FileName {
123
163
impl From < PathBuf > for FileName {
124
164
fn from ( p : PathBuf ) -> Self {
125
165
assert ! ( !p. to_string_lossy( ) . ends_with( '>' ) ) ;
126
- FileName :: Real ( p )
166
+ FileName :: Real ( RealFileName :: Named ( p ) )
127
167
}
128
168
}
129
169
0 commit comments