about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2019-11-10 17:19:08 +0100
committerCamille GILLOT <gillot.camille@gmail.com>2019-11-22 19:56:20 +0100
commit1de5fdb5babf74f729b008585a8aaf16110bb1fd (patch)
tree8e1f1b6f69cf4e20a435c1b53dab59803dee8406
parent3e969e070fcb0d8fab5d2c812edad12490fe8c1d (diff)
downloadrust-1de5fdb5babf74f729b008585a8aaf16110bb1fd.tar.gz
rust-1de5fdb5babf74f729b008585a8aaf16110bb1fd.zip
Add StableHashingContextLike to HashStable_Generic derive.
-rw-r--r--src/librustc/ich/impls_syntax.rs4
-rw-r--r--src/librustc_macros/src/hash_stable.rs1
-rw-r--r--src/librustc_target/lib.rs5
-rw-r--r--src/libsyntax/lib.rs5
-rw-r--r--src/libsyntax_pos/lib.rs5
5 files changed, 20 insertions, 0 deletions
diff --git a/src/librustc/ich/impls_syntax.rs b/src/librustc/ich/impls_syntax.rs
index f8bf8f4ab8a..b4800796b14 100644
--- a/src/librustc/ich/impls_syntax.rs
+++ b/src/librustc/ich/impls_syntax.rs
@@ -17,6 +17,10 @@ use crate::hir::def_id::{DefId, CrateNum, CRATE_DEF_INDEX};
 use smallvec::SmallVec;
 use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
 
+impl<'ctx> syntax_pos::StableHashingContextLike for StableHashingContext<'ctx> {}
+impl<'ctx> syntax::StableHashingContextLike for StableHashingContext<'ctx> {}
+impl<'ctx> rustc_target::StableHashingContextLike for StableHashingContext<'ctx> {}
+
 impl_stable_hash_for!(struct ::syntax::ast::Lit {
     kind,
     token,
diff --git a/src/librustc_macros/src/hash_stable.rs b/src/librustc_macros/src/hash_stable.rs
index 3fb252cbf8d..9003517d715 100644
--- a/src/librustc_macros/src/hash_stable.rs
+++ b/src/librustc_macros/src/hash_stable.rs
@@ -51,6 +51,7 @@ pub fn hash_stable_generic_derive(mut s: synstructure::Structure<'_>) -> proc_ma
     let generic: syn::GenericParam = parse_quote!(__CTX);
     s.add_bounds(synstructure::AddBounds::Generics);
     s.add_impl_generic(generic);
+    s.add_where_predicate(parse_quote!{ __CTX: crate::StableHashingContextLike });
     let body = s.each(|bi| {
         let attrs = parse_attributes(bi.ast());
         if attrs.ignore {
diff --git a/src/librustc_target/lib.rs b/src/librustc_target/lib.rs
index a349dc26e83..274f5ec7f1d 100644
--- a/src/librustc_target/lib.rs
+++ b/src/librustc_target/lib.rs
@@ -17,3 +17,8 @@
 
 pub mod abi;
 pub mod spec;
+
+/// Requirements for a `StableHashingContext` to be used in this crate.
+/// This is a hack to allow using the `HashStable_Generic` derive macro
+/// instead of implementing everything in librustc.
+pub trait StableHashingContextLike {}
diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs
index e3eca75dfe7..8f091c06b4b 100644
--- a/src/libsyntax/lib.rs
+++ b/src/libsyntax/lib.rs
@@ -110,3 +110,8 @@ pub mod print {
 }
 
 pub mod early_buffered_lints;
+
+/// Requirements for a `StableHashingContext` to be used in this crate.
+/// This is a hack to allow using the `HashStable_Generic` derive macro
+/// instead of implementing everything in librustc.
+pub trait StableHashingContextLike {}
diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs
index 720ace90324..d11ef5fcab2 100644
--- a/src/libsyntax_pos/lib.rs
+++ b/src/libsyntax_pos/lib.rs
@@ -1562,3 +1562,8 @@ fn lookup_line(lines: &[BytePos], pos: BytePos) -> isize {
         Err(line) => line as isize - 1
     }
 }
+
+/// Requirements for a `StableHashingContext` to be used in this crate.
+/// This is a hack to allow using the `HashStable_Generic` derive macro
+/// instead of implementing everything in librustc.
+pub trait StableHashingContextLike {}