1
Fork 0

Export HashStable for DelimSpan, Lit and Path.

This commit is contained in:
Camille GILLOT 2019-11-10 18:10:15 +01:00
parent 3c5ddfdd57
commit 0073d3be97
5 changed files with 13 additions and 26 deletions

View file

@ -14,7 +14,6 @@ use std::cell::RefCell;
use syntax::ast; use syntax::ast;
use syntax::source_map::SourceMap; use syntax::source_map::SourceMap;
use syntax::symbol::Symbol; use syntax::symbol::Symbol;
use syntax::tokenstream::DelimSpan;
use syntax_pos::{Span, DUMMY_SP}; use syntax_pos::{Span, DUMMY_SP};
use syntax_pos::hygiene::{self, SyntaxContext}; use syntax_pos::hygiene::{self, SyntaxContext};
@ -364,13 +363,6 @@ impl<'a> syntax_pos::StableHashingContextLike for StableHashingContext<'a> {
} }
} }
impl<'a> HashStable<StableHashingContext<'a>> for DelimSpan {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
self.open.hash_stable(hcx, hasher);
self.close.hash_stable(hcx, hasher);
}
}
pub fn hash_stable_trait_impls<'a>( pub fn hash_stable_trait_impls<'a>(
hcx: &mut StableHashingContext<'a>, hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher, hasher: &mut StableHasher,

View file

@ -20,12 +20,6 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
impl<'ctx> syntax::StableHashingContextLike for StableHashingContext<'ctx> {} impl<'ctx> syntax::StableHashingContextLike for StableHashingContext<'ctx> {}
impl<'ctx> rustc_target::StableHashingContextLike for StableHashingContext<'ctx> {} impl<'ctx> rustc_target::StableHashingContextLike for StableHashingContext<'ctx> {}
impl_stable_hash_for!(struct ::syntax::ast::Lit {
kind,
token,
span
});
impl_stable_hash_for_spanned!(::syntax::ast::LitKind); impl_stable_hash_for_spanned!(::syntax::ast::LitKind);
impl_stable_hash_for!(struct ::syntax::ast::Lifetime { id, ident }); impl_stable_hash_for!(struct ::syntax::ast::Lifetime { id, ident });
@ -53,15 +47,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for [ast::Attribute] {
} }
} }
impl<'a> HashStable<StableHashingContext<'a>> for ast::Path {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
self.segments.len().hash_stable(hcx, hasher);
for segment in &self.segments {
segment.ident.name.hash_stable(hcx, hasher);
}
}
}
impl_stable_hash_for!(struct ::syntax::ast::AttrItem { impl_stable_hash_for!(struct ::syntax::ast::AttrItem {
path, path,
tokens, tokens,

View file

@ -33,6 +33,7 @@ use syntax_pos::symbol::{kw, sym, Symbol};
use syntax_pos::{Span, DUMMY_SP, ExpnId}; use syntax_pos::{Span, DUMMY_SP, ExpnId};
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
use rustc_data_structures::thin_vec::ThinVec; use rustc_data_structures::thin_vec::ThinVec;
use rustc_index::vec::Idx; use rustc_index::vec::Idx;
@ -112,6 +113,15 @@ impl PartialEq<Symbol> for Path {
} }
} }
impl<CTX> HashStable<CTX> for Path {
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
self.segments.len().hash_stable(hcx, hasher);
for segment in &self.segments {
segment.ident.name.hash_stable(hcx, hasher);
}
}
}
impl Path { impl Path {
// Convert a span and an identifier to the corresponding // Convert a span and an identifier to the corresponding
// one-segment path. // one-segment path.
@ -1411,7 +1421,7 @@ pub enum StrStyle {
} }
/// An AST literal. /// An AST literal.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] #[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
pub struct Lit { pub struct Lit {
/// The original literal token as written in source code. /// The original literal token as written in source code.
pub token: token::Lit, pub token: token::Lit,

View file

@ -114,4 +114,4 @@ pub mod early_buffered_lints;
/// Requirements for a `StableHashingContext` to be used in this crate. /// Requirements for a `StableHashingContext` to be used in this crate.
/// This is a hack to allow using the `HashStable_Generic` derive macro /// This is a hack to allow using the `HashStable_Generic` derive macro
/// instead of implementing everything in librustc. /// instead of implementing everything in librustc.
pub trait StableHashingContextLike {} pub trait StableHashingContextLike: syntax_pos::StableHashingContextLike {}

View file

@ -444,7 +444,7 @@ impl Cursor {
} }
} }
#[derive(Debug, Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] #[derive(Debug, Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, HashStable_Generic)]
pub struct DelimSpan { pub struct DelimSpan {
pub open: Span, pub open: Span,
pub close: Span, pub close: Span,