@@ -172,7 +172,7 @@ impl<S: Encoder> Encodable<S> for RealFileName {
172
172
impl RealFileName {
173
173
/// Returns the path suitable for reading from the file system on the local host,
174
174
/// if this information exists.
175
- /// Avoid embedding this in build artifacts; see `stable_name ()` for that.
175
+ /// Avoid embedding this in build artifacts; see `remapped_path_if_available ()` for that.
176
176
pub fn local_path ( & self ) -> Option < & Path > {
177
177
match self {
178
178
RealFileName :: LocalPath ( p) => Some ( p) ,
@@ -184,39 +184,41 @@ impl RealFileName {
184
184
185
185
/// Returns the path suitable for reading from the file system on the local host,
186
186
/// if this information exists.
187
- /// Avoid embedding this in build artifacts; see `stable_name ()` for that.
187
+ /// Avoid embedding this in build artifacts; see `remapped_path_if_available ()` for that.
188
188
pub fn into_local_path ( self ) -> Option < PathBuf > {
189
189
match self {
190
190
RealFileName :: LocalPath ( p) => Some ( p) ,
191
191
RealFileName :: Remapped { local_path : p, virtual_name : _ } => p,
192
192
}
193
193
}
194
194
195
- /// Returns the path suitable for embedding into build artifacts. Note that
196
- /// a remapped path will not correspond to a valid file system path; see
197
- /// `local_path()` for something that is more likely to return paths into the
198
- /// local host file system.
199
- pub fn stable_name ( & self ) -> & Path {
195
+ /// Returns the path suitable for embedding into build artifacts. This would still
196
+ /// be a local path if it has not been remapped. A remapped path will not correspond
197
+ /// to a valid file system path: see `local_path_if_available()` for something that
198
+ /// is more likely to return paths into the local host file system.
199
+ pub fn remapped_path_if_available ( & self ) -> & Path {
200
200
match self {
201
201
RealFileName :: LocalPath ( p)
202
202
| RealFileName :: Remapped { local_path : _, virtual_name : p } => & p,
203
203
}
204
204
}
205
205
206
- fn to_string_lossy ( & self , prefer_local : bool ) -> Cow < ' _ , str > {
207
- use RealFileName :: * ;
206
+ /// Returns the path suitable for reading from the file system on the local host,
207
+ /// if this information exists. Otherwise returns the remapped name.
208
+ /// Avoid embedding this in build artifacts; see `remapped_path_if_available()` for that.
209
+ pub fn local_path_if_available ( & self ) -> & Path {
210
+ match self {
211
+ RealFileName :: LocalPath ( path)
212
+ | RealFileName :: Remapped { local_path : None , virtual_name : path }
213
+ | RealFileName :: Remapped { local_path : Some ( path) , virtual_name : _ } => path,
214
+ }
215
+ }
216
+
217
+ pub fn to_string_lossy ( & self , prefer_local : bool ) -> Cow < ' _ , str > {
208
218
if prefer_local {
209
- match self {
210
- LocalPath ( path)
211
- | Remapped { local_path : None , virtual_name : path }
212
- | Remapped { local_path : Some ( path) , virtual_name : _ } => path. to_string_lossy ( ) ,
213
- }
219
+ self . local_path_if_available ( ) . to_string_lossy ( )
214
220
} else {
215
- match self {
216
- LocalPath ( path) | Remapped { local_path : _, virtual_name : path } => {
217
- path. to_string_lossy ( )
218
- }
219
- }
221
+ self . remapped_path_if_available ( ) . to_string_lossy ( )
220
222
}
221
223
}
222
224
}
@@ -1358,7 +1360,7 @@ impl<D: Decoder> Decodable<D> for SourceFile {
1358
1360
1359
1361
impl fmt:: Debug for SourceFile {
1360
1362
fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1361
- write ! ( fmt, "SourceFile({})" , self . name)
1363
+ write ! ( fmt, "SourceFile({:? })" , self . name)
1362
1364
}
1363
1365
}
1364
1366
0 commit comments