Add StableHashingContextLike to HashStable_Generic derive.

This commit is contained in:
Camille GILLOT 2019-11-10 17:19:08 +01:00
parent 3e969e070f
commit 1de5fdb5ba
5 changed files with 20 additions and 0 deletions

View file

@ -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,

View file

@ -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 {

View file

@ -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 {}

View file

@ -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 {}

View file

@ -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 {}