diff options
| author | Urgau <urgau@numericable.fr> | 2024-03-21 21:13:06 +0100 |
|---|---|---|
| committer | Urgau <urgau@numericable.fr> | 2024-03-28 18:47:26 +0100 |
| commit | 4f4fa42b0ee1cf6c988d3f7ed6bcb4a51e788282 (patch) | |
| tree | 9057c7917e19c80dfdf90cfc2d3d9f564a9cc344 /compiler/rustc_span/src/source_map.rs | |
| parent | ee2898d3f1cbece34153581823fafa7f572bbff0 (diff) | |
| download | rust-4f4fa42b0ee1cf6c988d3f7ed6bcb4a51e788282.tar.gz rust-4f4fa42b0ee1cf6c988d3f7ed6bcb4a51e788282.zip | |
Introduce `FileNameMapping::to_real_filename` and use it everywhere
Diffstat (limited to 'compiler/rustc_span/src/source_map.rs')
| -rw-r--r-- | compiler/rustc_span/src/source_map.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index df7635e447d..770624d331d 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -1129,6 +1129,21 @@ impl FilePathMapping { } } + /// Applies any path prefix substitution as defined by the mapping. + /// The return value is the local path with a "virtual path" representing the remapped + /// part if any remapping was performed. + pub fn to_real_filename<'a>(&self, local_path: impl Into<Cow<'a, Path>>) -> RealFileName { + let local_path = local_path.into(); + if let (remapped_path, true) = self.map_prefix(&*local_path) { + RealFileName::Remapped { + virtual_name: remapped_path.into_owned(), + local_path: Some(local_path.into_owned()), + } + } else { + RealFileName::LocalPath(local_path.into_owned()) + } + } + /// Expand a relative path to an absolute path with remapping taken into account. /// Use this when absolute paths are required (e.g. debuginfo or crate metadata). /// |
