about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFelix S. Klock II <pnkfelix@pnkfx.org>2020-05-29 14:04:03 -0400
committerMark Rousskov <mark.simulacrum@gmail.com>2020-06-01 08:26:38 -0400
commit5684eaef5f9b78074a1d4d994ec8976401f5d1f6 (patch)
tree4b0cf7eb86affbee8272e5bfdc9ba8ce1ebb0a4a
parent0a91077ff9de48d4b05c7a081964b876f61a5f68 (diff)
downloadrust-5684eaef5f9b78074a1d4d994ec8976401f5d1f6.tar.gz
rust-5684eaef5f9b78074a1d4d994ec8976401f5d1f6.zip
Use the virtual name for libstd files in StableSourceFileId and also in the
encoded build artifacts.

Fix #70924.
-rw-r--r--src/librustc_metadata/rmeta/encoder.rs2
-rw-r--r--src/librustc_span/lib.rs13
-rw-r--r--src/librustc_span/source_map.rs11
3 files changed, 24 insertions, 2 deletions
diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs
index 715cb52db1c..b739882b7aa 100644
--- a/src/librustc_metadata/rmeta/encoder.rs
+++ b/src/librustc_metadata/rmeta/encoder.rs
@@ -398,7 +398,7 @@ impl<'tcx> EncodeContext<'tcx> {
                     // any relative paths are potentially relative to a
                     // wrong directory.
                     FileName::Real(ref name) => {
-                        let name = name.local_path();
+                        let name = name.stable_name();
                         let mut adapted = (**source_file).clone();
                         adapted.name = Path::new(&working_dir).join(name).into();
                         adapted.name_hash = {
diff --git a/src/librustc_span/lib.rs b/src/librustc_span/lib.rs
index 7a12d7da31f..94a5acc8610 100644
--- a/src/librustc_span/lib.rs
+++ b/src/librustc_span/lib.rs
@@ -95,6 +95,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)
@@ -103,12 +104,24 @@ 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 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.
diff --git a/src/librustc_span/source_map.rs b/src/librustc_span/source_map.rs
index e2ae32f6a1b..54d3dc2c867 100644
--- a/src/librustc_span/source_map.rs
+++ b/src/librustc_span/source_map.rs
@@ -98,6 +98,8 @@ impl FileLoader for RealFileLoader {
 #[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug)]
 pub struct StableSourceFileId(u128);
 
+// FIXME: we need a more globally consistent approach to the problem solved by
+// StableSourceFileId, perhaps built atop source_file.name_hash.
 impl StableSourceFileId {
     pub fn new(source_file: &SourceFile) -> StableSourceFileId {
         StableSourceFileId::new_from_pieces(
@@ -114,7 +116,14 @@ impl StableSourceFileId {
     ) -> StableSourceFileId {
         let mut hasher = StableHasher::new();
 
-        name.hash(&mut hasher);
+        if let FileName::Real(real_name) = name {
+            // rust-lang/rust#70924: Use the stable (virtualized) name when
+            // available. (We do not want artifacts from transient file system
+            // paths for libstd to leak into our build artifacts.)
+            real_name.stable_name().hash(&mut hasher)
+        } else {
+            name.hash(&mut hasher);
+        }
         name_was_remapped.hash(&mut hasher);
         unmapped_path.hash(&mut hasher);