@@ -49,7 +49,7 @@ use std::cmp::{self, Ordering};
49
49
use std:: fmt;
50
50
use std:: hash:: Hash ;
51
51
use std:: ops:: { Add , Sub } ;
52
- use std:: path:: PathBuf ;
52
+ use std:: path:: { Path , PathBuf } ;
53
53
use std:: str:: FromStr ;
54
54
55
55
use md5:: Md5 ;
@@ -77,11 +77,45 @@ impl Globals {
77
77
78
78
scoped_tls:: scoped_thread_local!( pub static GLOBALS : Globals ) ;
79
79
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
+
80
114
/// Differentiates between real files and common virtual files.
81
115
#[ derive( Debug , Eq , PartialEq , Clone , Ord , PartialOrd , Hash , RustcDecodable , RustcEncodable ) ]
82
116
#[ derive( HashStable_Generic ) ]
83
117
pub enum FileName {
84
- Real ( PathBuf ) ,
118
+ Real ( RealFileName ) ,
85
119
/// Call to `quote!`.
86
120
QuoteExpansion ( u64 ) ,
87
121
/// Command line.
@@ -103,7 +137,13 @@ impl std::fmt::Display for FileName {
103
137
fn fmt ( & self , fmt : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
104
138
use FileName :: * ;
105
139
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
+ }
107
147
QuoteExpansion ( _) => write ! ( fmt, "<quote expansion>" ) ,
108
148
MacroExpansion ( _) => write ! ( fmt, "<macro expansion>" ) ,
109
149
Anon ( _) => write ! ( fmt, "<anon>" ) ,
@@ -119,7 +159,7 @@ impl std::fmt::Display for FileName {
119
159
impl From < PathBuf > for FileName {
120
160
fn from ( p : PathBuf ) -> Self {
121
161
assert ! ( !p. to_string_lossy( ) . ends_with( '>' ) ) ;
122
- FileName :: Real ( p )
162
+ FileName :: Real ( RealFileName :: Named ( p ) )
123
163
}
124
164
}
125
165
0 commit comments