]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_metadata/src/rmeta/encoder.rs
Rename RealFileName::Named to LocalPath and Devirtualized to Remapped
[rust.git] / compiler / rustc_metadata / src / rmeta / encoder.rs
index e8f02b8e66f0a9f03caaabd16d90d6c786fba389..fbae2278f1e1f079007113c60803d23e6e76619e 100644 (file)
 use rustc_middle::ty::{self, SymbolName, Ty, TyCtxt};
 use rustc_serialize::{opaque, Encodable, Encoder};
 use rustc_session::config::CrateType;
-use rustc_span::hygiene::{ExpnDataEncodeMode, HygieneEncodeContext, MacroKind};
 use rustc_span::symbol::{sym, Ident, Symbol};
 use rustc_span::{self, ExternalSource, FileName, SourceFile, Span, SyntaxContext};
+use rustc_span::{
+    hygiene::{ExpnDataEncodeMode, HygieneEncodeContext, MacroKind},
+    RealFileName,
+};
 use rustc_target::abi::VariantIdx;
 use std::hash::Hash;
 use std::num::NonZeroUsize;
@@ -485,18 +488,22 @@ fn encode_source_map(&mut self) -> Lazy<[rustc_span::SourceFile]> {
             })
             .map(|(_, source_file)| {
                 let mut adapted = match source_file.name {
-                    // This path of this SourceFile has been modified by
-                    // path-remapping, so we use it verbatim (and avoid
-                    // cloning the whole map in the process).
-                    _ if source_file.name_was_remapped => source_file.clone(),
-
-                    // Otherwise expand all paths to absolute paths because
-                    // any relative paths are potentially relative to a
-                    // wrong directory.
                     FileName::Real(ref name) => {
-                        let name = name.stable_name();
+                        // Expand all local paths to absolute paths because
+                        // any relative paths are potentially relative to a
+                        // wrong directory.
                         let mut adapted = (**source_file).clone();
-                        adapted.name = Path::new(&working_dir).join(name).into();
+                        adapted.name = match name {
+                            RealFileName::LocalPath(local_path) => {
+                                Path::new(&working_dir).join(local_path).into()
+                            }
+                            RealFileName::Remapped { local_path, virtual_name } => {
+                                FileName::Real(RealFileName::Remapped {
+                                    local_path: Path::new(&working_dir).join(local_path),
+                                    virtual_name: virtual_name.clone(),
+                                })
+                            }
+                        };
                         adapted.name_hash = {
                             let mut hasher: StableHasher = StableHasher::new();
                             adapted.name.hash(&mut hasher);