@@ -260,11 +260,12 @@ impl RealFileName {
260
260
}
261
261
}
262
262
263
- pub fn to_string_lossy ( & self , prefer_local : bool ) -> Cow < ' _ , str > {
264
- if prefer_local {
265
- self . local_path_if_available ( ) . to_string_lossy ( )
266
- } else {
267
- self . remapped_path_if_available ( ) . to_string_lossy ( )
263
+ pub fn to_string_lossy ( & self , display_pref : FileNameDisplayPreference ) -> Cow < ' _ , str > {
264
+ match display_pref {
265
+ FileNameDisplayPreference :: Local => self . local_path_if_available ( ) . to_string_lossy ( ) ,
266
+ FileNameDisplayPreference :: Remapped => {
267
+ self . remapped_path_if_available ( ) . to_string_lossy ( )
268
+ }
268
269
}
269
270
}
270
271
}
@@ -300,17 +301,23 @@ impl From<PathBuf> for FileName {
300
301
}
301
302
}
302
303
304
+ #[ derive( Clone , Copy , Eq , PartialEq , Hash , Debug ) ]
305
+ pub enum FileNameDisplayPreference {
306
+ Remapped ,
307
+ Local ,
308
+ }
309
+
303
310
pub struct FileNameDisplay < ' a > {
304
311
inner : & ' a FileName ,
305
- prefer_local : bool ,
312
+ display_pref : FileNameDisplayPreference ,
306
313
}
307
314
308
315
impl fmt:: Display for FileNameDisplay < ' _ > {
309
316
fn fmt ( & self , fmt : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
310
317
use FileName :: * ;
311
318
match * self . inner {
312
319
Real ( ref name) => {
313
- write ! ( fmt, "{}" , name. to_string_lossy( self . prefer_local ) )
320
+ write ! ( fmt, "{}" , name. to_string_lossy( self . display_pref ) )
314
321
}
315
322
QuoteExpansion ( _) => write ! ( fmt, "<quote expansion>" ) ,
316
323
MacroExpansion ( _) => write ! ( fmt, "<macro expansion>" ) ,
@@ -328,7 +335,7 @@ impl fmt::Display for FileNameDisplay<'_> {
328
335
impl FileNameDisplay < ' _ > {
329
336
pub fn to_string_lossy ( & self ) -> Cow < ' _ , str > {
330
337
match self . inner {
331
- FileName :: Real ( ref inner) => inner. to_string_lossy ( self . prefer_local ) ,
338
+ FileName :: Real ( ref inner) => inner. to_string_lossy ( self . display_pref ) ,
332
339
_ => Cow :: from ( format ! ( "{}" , self ) ) ,
333
340
}
334
341
}
@@ -352,13 +359,17 @@ impl FileName {
352
359
}
353
360
354
361
pub fn prefer_remapped ( & self ) -> FileNameDisplay < ' _ > {
355
- FileNameDisplay { inner : self , prefer_local : false }
362
+ FileNameDisplay { inner : self , display_pref : FileNameDisplayPreference :: Remapped }
356
363
}
357
364
358
365
// This may include transient local filesystem information.
359
366
// Must not be embedded in build outputs.
360
367
pub fn prefer_local ( & self ) -> FileNameDisplay < ' _ > {
361
- FileNameDisplay { inner : self , prefer_local : true }
368
+ FileNameDisplay { inner : self , display_pref : FileNameDisplayPreference :: Local }
369
+ }
370
+
371
+ pub fn display ( & self , display_pref : FileNameDisplayPreference ) -> FileNameDisplay < ' _ > {
372
+ FileNameDisplay { inner : self , display_pref }
362
373
}
363
374
364
375
pub fn macro_expansion_source_code ( src : & str ) -> FileName {
0 commit comments