]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_span/lib.rs
Use the virtual name for libstd files in StableSourceFileId and also in the
[rust.git] / src / librustc_span / lib.rs
index f18a863d7208e828bcb5546af972f0e22f8117a5..e17fe1fa782cbe1c1dee94c4d7f651af53266fa7 100644 (file)
@@ -99,6 +99,7 @@ pub enum RealFileName {
 
 impl RealFileName {
     /// Returns the path suitable for reading from the file system on the local host.
+    /// Avoid embedding this in build artifacts; see `stable_name` for that.
     pub fn local_path(&self) -> &Path {
         match self {
             RealFileName::Named(p)
@@ -107,12 +108,24 @@ pub fn local_path(&self) -> &Path {
     }
 
     /// Returns the path suitable for reading from the file system on the local host.
+    /// Avoid embedding this in build artifacts; see `stable_name` for that.
     pub fn into_local_path(self) -> PathBuf {
         match self {
             RealFileName::Named(p)
             | RealFileName::Devirtualized { local_path: p, virtual_name: _ } => p,
         }
     }
+
+    /// Returns the path suitable for embedding into build artifacts. Note that
+    /// a virtualized path will not correspond to a valid file system path; see
+    /// `local_path` for something that is more likely to return paths into the
+    /// local host file system.
+    pub fn stable_name(&self) -> &Path {
+        match self {
+            RealFileName::Named(p)
+            | RealFileName::Devirtualized { local_path: _, virtual_name: p } => &p,
+        }
+    }
 }
 
 /// Differentiates between real files and common virtual files.