From 1de5fdb5babf74f729b008585a8aaf16110bb1fd Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 10 Nov 2019 17:19:08 +0100 Subject: [PATCH] Add StableHashingContextLike to HashStable_Generic derive. --- src/librustc/ich/impls_syntax.rs | 4 ++++ src/librustc_macros/src/hash_stable.rs | 1 + src/librustc_target/lib.rs | 5 +++++ src/libsyntax/lib.rs | 5 +++++ src/libsyntax_pos/lib.rs | 5 +++++ 5 files changed, 20 insertions(+) diff --git a/src/librustc/ich/impls_syntax.rs b/src/librustc/ich/impls_syntax.rs index f8bf8f4ab8a2..b4800796b145 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 3fb252cbf8d9..9003517d715a 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 a349dc26e834..274f5ec7f1d0 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 e3eca75dfe7e..8f091c06b4b8 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 720ace90324b..d11ef5fcab2e 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 {}