about summary refs log tree commit diff
path: root/src/librustc
diff options
context:
space:
mode:
authorMatthew Jasper <mjjasper1@gmail.com>2019-08-24 16:25:55 +0100
committerMatthew Jasper <mjjasper1@gmail.com>2019-08-27 23:02:22 +0100
commit3d718037dcddd2aa56bd2727dee074ac9b6a6f0e (patch)
treeca95b9980825f513fb9324434dd0cd19f39f4363 /src/librustc
parent0396aace27eea97c3603e9683e921807dff2a314 (diff)
downloadrust-3d718037dcddd2aa56bd2727dee074ac9b6a6f0e.tar.gz
rust-3d718037dcddd2aa56bd2727dee074ac9b6a6f0e.zip
Add default serialization for `Ident`s
Add tests for -Zast-json and -Zast-json-noexpand, which need this impl.
Diffstat (limited to 'src/librustc')
-rw-r--r--src/librustc/ty/query/on_disk_cache.rs25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/librustc/ty/query/on_disk_cache.rs b/src/librustc/ty/query/on_disk_cache.rs
index c21639d0dca..674f8944f26 100644
--- a/src/librustc/ty/query/on_disk_cache.rs
+++ b/src/librustc/ty/query/on_disk_cache.rs
@@ -20,7 +20,7 @@ use rustc_data_structures::thin_vec::ThinVec;
 use rustc_data_structures::sync::{Lrc, Lock, HashMapExt, Once};
 use rustc_data_structures::indexed_vec::{IndexVec, Idx};
 use std::mem;
-use syntax::ast::NodeId;
+use syntax::ast::{Ident, NodeId};
 use syntax::source_map::{SourceMap, StableSourceFileId};
 use syntax_pos::{BytePos, Span, DUMMY_SP, SourceFile};
 use syntax_pos::hygiene::{ExpnId, SyntaxContext};
@@ -591,7 +591,8 @@ impl<'a, 'tcx> SpecializedDecoder<Span> for CacheDecoder<'a, 'tcx> {
         // FIXME(mw): This method does not restore `ExpnData::parent` or
         // `SyntaxContextData::prev_ctxt` or `SyntaxContextData::opaque`. These things
         // don't seem to be used after HIR lowering, so everything should be fine
-        // as long as incremental compilation does not kick in before that.
+        // until we want incremental compilation to serialize Spans that we need
+        // full hygiene information for.
         let location = || Span::with_root_ctxt(lo, hi);
         let recover_from_expn_data = |this: &Self, expn_data, transparency, pos| {
             let span = location().fresh_expansion_with_transparency(expn_data, transparency);
@@ -626,6 +627,13 @@ impl<'a, 'tcx> SpecializedDecoder<Span> for CacheDecoder<'a, 'tcx> {
     }
 }
 
+impl<'a, 'tcx> SpecializedDecoder<Ident> for CacheDecoder<'a, 'tcx> {
+    fn specialized_decode(&mut self) -> Result<Ident, Self::Error> {
+        // FIXME: Handle hygiene in incremental
+        bug!("Trying to decode Ident for incremental");
+    }
+}
+
 // This impl makes sure that we get a runtime error when we try decode a
 // DefIndex that is not contained in a DefId. Such a case would be problematic
 // because we would not know how to transform the DefIndex to the current
@@ -833,6 +841,19 @@ where
     }
 }
 
+impl<'a, 'tcx, E> SpecializedEncoder<Ident> for CacheEncoder<'a, 'tcx, E>
+where
+    E: 'a + ty_codec::TyEncoder,
+{
+    fn specialized_encode(&mut self, _: &Ident) -> Result<(), Self::Error> {
+        // We don't currently encode enough information to ensure hygiene works
+        // with incremental, so panic rather than risk incremental bugs.
+
+        // FIXME: Handle hygiene in incremental
+        bug!("Trying to encode Ident for incremental")
+    }
+}
+
 impl<'a, 'tcx, E> ty_codec::TyEncoder for CacheEncoder<'a, 'tcx, E>
 where
     E: 'a + ty_codec::TyEncoder,