2017-03-30 13:27:27 +00:00
|
|
|
//! This module contains `HashStable` implementations for various data types
|
|
|
|
//! from libsyntax in no particular order.
|
|
|
|
|
2019-02-05 17:20:45 +00:00
|
|
|
use crate::ich::StableHashingContext;
|
2017-03-30 13:27:27 +00:00
|
|
|
|
|
|
|
use std::hash as std_hash;
|
|
|
|
use std::mem;
|
|
|
|
|
|
|
|
use syntax::ast;
|
2018-02-14 15:11:02 +00:00
|
|
|
use syntax::feature_gate;
|
2017-03-30 13:27:27 +00:00
|
|
|
use syntax::parse::token;
|
2018-04-11 21:02:41 +00:00
|
|
|
use syntax::symbol::{InternedString, LocalInternedString};
|
2017-03-30 13:27:27 +00:00
|
|
|
use syntax::tokenstream;
|
2018-08-18 10:13:52 +00:00
|
|
|
use syntax_pos::SourceFile;
|
2017-04-27 14:12:57 +00:00
|
|
|
|
2019-02-05 17:20:45 +00:00
|
|
|
use crate::hir::def_id::{DefId, CrateNum, CRATE_DEF_INDEX};
|
2017-03-30 13:27:27 +00:00
|
|
|
|
2018-08-24 03:51:32 +00:00
|
|
|
use smallvec::SmallVec;
|
2017-09-12 15:07:09 +00:00
|
|
|
use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey,
|
|
|
|
StableHasher, StableHasherResult};
|
2017-03-30 13:27:27 +00:00
|
|
|
|
2018-01-16 09:16:38 +00:00
|
|
|
impl<'a> HashStable<StableHashingContext<'a>> for InternedString {
|
2017-03-30 13:27:27 +00:00
|
|
|
#[inline]
|
|
|
|
fn hash_stable<W: StableHasherResult>(&self,
|
2018-01-16 09:16:38 +00:00
|
|
|
hcx: &mut StableHashingContext<'a>,
|
2017-03-30 13:27:27 +00:00
|
|
|
hasher: &mut StableHasher<W>) {
|
2018-04-11 21:02:41 +00:00
|
|
|
self.with(|s| s.hash_stable(hcx, hasher))
|
2017-03-30 13:27:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-16 09:16:38 +00:00
|
|
|
impl<'a> ToStableHashKey<StableHashingContext<'a>> for InternedString {
|
2017-09-12 15:07:09 +00:00
|
|
|
type KeyType = InternedString;
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn to_stable_hash_key(&self,
|
2018-01-16 09:16:38 +00:00
|
|
|
_: &StableHashingContext<'a>)
|
2017-09-12 15:07:09 +00:00
|
|
|
-> InternedString {
|
|
|
|
self.clone()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-11 21:02:41 +00:00
|
|
|
impl<'a> HashStable<StableHashingContext<'a>> for LocalInternedString {
|
|
|
|
#[inline]
|
|
|
|
fn hash_stable<W: StableHasherResult>(&self,
|
|
|
|
hcx: &mut StableHashingContext<'a>,
|
|
|
|
hasher: &mut StableHasher<W>) {
|
|
|
|
let s: &str = &**self;
|
|
|
|
s.hash_stable(hcx, hasher);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> ToStableHashKey<StableHashingContext<'a>> for LocalInternedString {
|
|
|
|
type KeyType = LocalInternedString;
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn to_stable_hash_key(&self,
|
|
|
|
_: &StableHashingContext<'a>)
|
|
|
|
-> LocalInternedString {
|
|
|
|
self.clone()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-16 09:16:38 +00:00
|
|
|
impl<'a> HashStable<StableHashingContext<'a>> for ast::Name {
|
2017-03-30 13:27:27 +00:00
|
|
|
#[inline]
|
|
|
|
fn hash_stable<W: StableHasherResult>(&self,
|
2018-01-16 09:16:38 +00:00
|
|
|
hcx: &mut StableHashingContext<'a>,
|
2017-03-30 13:27:27 +00:00
|
|
|
hasher: &mut StableHasher<W>) {
|
|
|
|
self.as_str().hash_stable(hcx, hasher);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-16 09:16:38 +00:00
|
|
|
impl<'a> ToStableHashKey<StableHashingContext<'a>> for ast::Name {
|
2017-09-12 15:07:09 +00:00
|
|
|
type KeyType = InternedString;
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn to_stable_hash_key(&self,
|
2018-01-16 09:16:38 +00:00
|
|
|
_: &StableHashingContext<'a>)
|
2017-09-12 15:07:09 +00:00
|
|
|
-> InternedString {
|
2018-04-11 21:02:41 +00:00
|
|
|
self.as_interned_str()
|
2017-09-12 15:07:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-30 13:27:27 +00:00
|
|
|
impl_stable_hash_for!(enum ::syntax::ast::AsmDialect {
|
|
|
|
Att,
|
|
|
|
Intel
|
|
|
|
});
|
|
|
|
|
|
|
|
impl_stable_hash_for!(enum ::syntax::ext::base::MacroKind {
|
|
|
|
Bang,
|
|
|
|
Attr,
|
2018-07-12 10:24:59 +00:00
|
|
|
Derive,
|
2017-03-30 13:27:27 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2018-04-25 16:30:39 +00:00
|
|
|
impl_stable_hash_for!(enum ::rustc_target::spec::abi::Abi {
|
2017-03-30 13:27:27 +00:00
|
|
|
Cdecl,
|
|
|
|
Stdcall,
|
|
|
|
Fastcall,
|
|
|
|
Vectorcall,
|
2017-05-17 13:40:46 +00:00
|
|
|
Thiscall,
|
2017-03-30 13:27:27 +00:00
|
|
|
Aapcs,
|
|
|
|
Win64,
|
|
|
|
SysV64,
|
|
|
|
PtxKernel,
|
|
|
|
Msp430Interrupt,
|
|
|
|
X86Interrupt,
|
2018-07-02 03:42:00 +00:00
|
|
|
AmdGpuKernel,
|
2017-03-30 13:27:27 +00:00
|
|
|
Rust,
|
|
|
|
C,
|
|
|
|
System,
|
|
|
|
RustIntrinsic,
|
|
|
|
RustCall,
|
|
|
|
PlatformIntrinsic,
|
|
|
|
Unadjusted
|
|
|
|
});
|
|
|
|
|
|
|
|
impl_stable_hash_for!(struct ::syntax::attr::Deprecation { since, note });
|
2017-09-08 18:11:30 +00:00
|
|
|
impl_stable_hash_for!(struct ::syntax::attr::Stability {
|
|
|
|
level,
|
|
|
|
feature,
|
|
|
|
rustc_depr,
|
2018-08-31 11:50:14 +00:00
|
|
|
promotable,
|
2019-04-05 21:13:44 +00:00
|
|
|
allow_const_fn_ptr,
|
2018-08-22 13:56:37 +00:00
|
|
|
const_stability
|
2017-09-08 18:11:30 +00:00
|
|
|
});
|
2017-03-30 13:27:27 +00:00
|
|
|
|
2018-12-02 00:59:25 +00:00
|
|
|
impl_stable_hash_for!(enum ::syntax::edition::Edition {
|
|
|
|
Edition2015,
|
|
|
|
Edition2018,
|
|
|
|
});
|
2018-04-27 23:08:16 +00:00
|
|
|
|
2018-01-16 09:16:38 +00:00
|
|
|
impl<'a> HashStable<StableHashingContext<'a>>
|
2017-06-02 13:45:56 +00:00
|
|
|
for ::syntax::attr::StabilityLevel {
|
2017-03-30 13:27:27 +00:00
|
|
|
fn hash_stable<W: StableHasherResult>(&self,
|
2018-01-16 09:16:38 +00:00
|
|
|
hcx: &mut StableHashingContext<'a>,
|
2017-03-30 13:27:27 +00:00
|
|
|
hasher: &mut StableHasher<W>) {
|
|
|
|
mem::discriminant(self).hash_stable(hcx, hasher);
|
|
|
|
match *self {
|
|
|
|
::syntax::attr::StabilityLevel::Unstable { ref reason, ref issue } => {
|
|
|
|
reason.hash_stable(hcx, hasher);
|
|
|
|
issue.hash_stable(hcx, hasher);
|
|
|
|
}
|
|
|
|
::syntax::attr::StabilityLevel::Stable { ref since } => {
|
|
|
|
since.hash_stable(hcx, hasher);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-30 16:47:36 +00:00
|
|
|
impl_stable_hash_for!(struct ::syntax::attr::RustcDeprecation { since, reason, suggestion });
|
2017-03-30 13:27:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
impl_stable_hash_for!(enum ::syntax::attr::IntType {
|
|
|
|
SignedInt(int_ty),
|
|
|
|
UnsignedInt(uint_ty)
|
|
|
|
});
|
|
|
|
|
|
|
|
impl_stable_hash_for!(enum ::syntax::ast::LitIntType {
|
|
|
|
Signed(int_ty),
|
|
|
|
Unsigned(int_ty),
|
|
|
|
Unsuffixed
|
|
|
|
});
|
|
|
|
|
2019-05-08 23:00:29 +00:00
|
|
|
impl_stable_hash_for!(struct ::syntax::ast::Lit {
|
|
|
|
node,
|
2019-05-08 23:17:32 +00:00
|
|
|
token,
|
2019-05-08 23:00:29 +00:00
|
|
|
span
|
|
|
|
});
|
|
|
|
|
2017-03-30 13:27:27 +00:00
|
|
|
impl_stable_hash_for!(enum ::syntax::ast::LitKind {
|
|
|
|
Str(value, style),
|
|
|
|
ByteStr(value),
|
|
|
|
Byte(value),
|
|
|
|
Char(value),
|
|
|
|
Int(value, lit_int_type),
|
|
|
|
Float(value, float_ty),
|
|
|
|
FloatUnsuffixed(value),
|
2019-06-07 09:53:33 +00:00
|
|
|
Bool(value),
|
|
|
|
Err(value)
|
2017-03-30 13:27:27 +00:00
|
|
|
});
|
|
|
|
|
2019-05-09 15:04:24 +00:00
|
|
|
impl_stable_hash_for_spanned!(::syntax::ast::LitKind);
|
|
|
|
|
2018-01-04 01:12:04 +00:00
|
|
|
impl_stable_hash_for!(enum ::syntax::ast::IntTy { Isize, I8, I16, I32, I64, I128 });
|
|
|
|
impl_stable_hash_for!(enum ::syntax::ast::UintTy { Usize, U8, U16, U32, U64, U128 });
|
2017-03-30 13:27:27 +00:00
|
|
|
impl_stable_hash_for!(enum ::syntax::ast::FloatTy { F32, F64 });
|
|
|
|
impl_stable_hash_for!(enum ::syntax::ast::Unsafety { Unsafe, Normal });
|
|
|
|
impl_stable_hash_for!(enum ::syntax::ast::Constness { Const, NotConst });
|
|
|
|
impl_stable_hash_for!(enum ::syntax::ast::Defaultness { Default, Final });
|
2018-03-19 00:54:56 +00:00
|
|
|
impl_stable_hash_for!(struct ::syntax::ast::Lifetime { id, ident });
|
2017-03-30 13:27:27 +00:00
|
|
|
impl_stable_hash_for!(enum ::syntax::ast::StrStyle { Cooked, Raw(pounds) });
|
|
|
|
impl_stable_hash_for!(enum ::syntax::ast::AttrStyle { Outer, Inner });
|
|
|
|
|
2018-01-16 09:16:38 +00:00
|
|
|
impl<'a> HashStable<StableHashingContext<'a>> for [ast::Attribute] {
|
2017-03-30 13:27:27 +00:00
|
|
|
fn hash_stable<W: StableHasherResult>(&self,
|
2018-01-16 09:16:38 +00:00
|
|
|
hcx: &mut StableHashingContext<'a>,
|
2017-03-30 13:27:27 +00:00
|
|
|
hasher: &mut StableHasher<W>) {
|
2017-09-14 10:29:16 +00:00
|
|
|
if self.len() == 0 {
|
|
|
|
self.len().hash_stable(hcx, hasher);
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-03-30 13:27:27 +00:00
|
|
|
// Some attributes are always ignored during hashing.
|
2018-08-24 03:51:32 +00:00
|
|
|
let filtered: SmallVec<[&ast::Attribute; 8]> = self
|
2017-03-30 13:27:27 +00:00
|
|
|
.iter()
|
|
|
|
.filter(|attr| {
|
2019-02-28 06:17:24 +00:00
|
|
|
!attr.is_sugared_doc &&
|
|
|
|
!attr.ident().map_or(false, |ident| hcx.is_ignored_attr(ident.name))
|
2017-03-30 13:27:27 +00:00
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
filtered.len().hash_stable(hcx, hasher);
|
|
|
|
for attr in filtered {
|
|
|
|
attr.hash_stable(hcx, hasher);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-30 05:30:39 +00:00
|
|
|
impl<'a> HashStable<StableHashingContext<'a>> for ast::Path {
|
|
|
|
fn hash_stable<W: StableHasherResult>(&self,
|
|
|
|
hcx: &mut StableHashingContext<'a>,
|
|
|
|
hasher: &mut StableHasher<W>) {
|
|
|
|
self.segments.len().hash_stable(hcx, hasher);
|
|
|
|
for segment in &self.segments {
|
2018-04-17 13:33:39 +00:00
|
|
|
segment.ident.name.hash_stable(hcx, hasher);
|
2018-01-30 05:30:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-16 09:16:38 +00:00
|
|
|
impl<'a> HashStable<StableHashingContext<'a>> for ast::Attribute {
|
2017-03-30 13:27:27 +00:00
|
|
|
fn hash_stable<W: StableHasherResult>(&self,
|
2018-01-16 09:16:38 +00:00
|
|
|
hcx: &mut StableHashingContext<'a>,
|
2017-03-30 13:27:27 +00:00
|
|
|
hasher: &mut StableHasher<W>) {
|
|
|
|
// Make sure that these have been filtered out.
|
2019-02-28 06:17:24 +00:00
|
|
|
debug_assert!(!self.ident().map_or(false, |ident| hcx.is_ignored_attr(ident.name)));
|
2017-03-30 13:27:27 +00:00
|
|
|
debug_assert!(!self.is_sugared_doc);
|
|
|
|
|
|
|
|
let ast::Attribute {
|
|
|
|
id: _,
|
|
|
|
style,
|
|
|
|
ref path,
|
|
|
|
ref tokens,
|
|
|
|
is_sugared_doc: _,
|
|
|
|
span,
|
|
|
|
} = *self;
|
|
|
|
|
|
|
|
style.hash_stable(hcx, hasher);
|
2018-01-30 05:30:39 +00:00
|
|
|
path.hash_stable(hcx, hasher);
|
2017-03-30 13:27:27 +00:00
|
|
|
for tt in tokens.trees() {
|
|
|
|
tt.hash_stable(hcx, hasher);
|
|
|
|
}
|
|
|
|
span.hash_stable(hcx, hasher);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-16 09:16:38 +00:00
|
|
|
impl<'a> HashStable<StableHashingContext<'a>>
|
2017-06-02 13:45:56 +00:00
|
|
|
for tokenstream::TokenTree {
|
2017-03-30 13:27:27 +00:00
|
|
|
fn hash_stable<W: StableHasherResult>(&self,
|
2018-01-16 09:16:38 +00:00
|
|
|
hcx: &mut StableHashingContext<'a>,
|
2017-03-30 13:27:27 +00:00
|
|
|
hasher: &mut StableHasher<W>) {
|
|
|
|
mem::discriminant(self).hash_stable(hcx, hasher);
|
|
|
|
match *self {
|
2019-06-04 17:42:43 +00:00
|
|
|
tokenstream::TokenTree::Token(ref token) => {
|
|
|
|
token.hash_stable(hcx, hasher);
|
2017-03-30 13:27:27 +00:00
|
|
|
}
|
2018-11-29 23:02:04 +00:00
|
|
|
tokenstream::TokenTree::Delimited(span, delim, ref tts) => {
|
2017-03-30 13:27:27 +00:00
|
|
|
span.hash_stable(hcx, hasher);
|
2018-11-29 23:02:04 +00:00
|
|
|
std_hash::Hash::hash(&delim, hasher);
|
2019-01-09 05:53:14 +00:00
|
|
|
for sub_tt in tts.trees() {
|
2017-03-30 13:27:27 +00:00
|
|
|
sub_tt.hash_stable(hcx, hasher);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-16 09:16:38 +00:00
|
|
|
impl<'a> HashStable<StableHashingContext<'a>>
|
2017-06-02 13:45:56 +00:00
|
|
|
for tokenstream::TokenStream {
|
2017-03-30 13:27:27 +00:00
|
|
|
fn hash_stable<W: StableHasherResult>(&self,
|
2018-01-16 09:16:38 +00:00
|
|
|
hcx: &mut StableHashingContext<'a>,
|
2017-03-30 13:27:27 +00:00
|
|
|
hasher: &mut StableHasher<W>) {
|
|
|
|
for sub_tt in self.trees() {
|
|
|
|
sub_tt.hash_stable(hcx, hasher);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-18 22:04:26 +00:00
|
|
|
impl_stable_hash_for!(enum token::LitKind {
|
|
|
|
Bool,
|
|
|
|
Byte,
|
|
|
|
Char,
|
|
|
|
Integer,
|
|
|
|
Float,
|
|
|
|
Str,
|
|
|
|
ByteStr,
|
|
|
|
StrRaw(n),
|
|
|
|
ByteStrRaw(n),
|
|
|
|
Err
|
|
|
|
});
|
|
|
|
|
|
|
|
impl_stable_hash_for!(struct token::Lit {
|
|
|
|
kind,
|
|
|
|
symbol,
|
|
|
|
suffix
|
2019-05-08 23:17:32 +00:00
|
|
|
});
|
|
|
|
|
2019-06-04 17:42:43 +00:00
|
|
|
impl<'a> HashStable<StableHashingContext<'a>> for token::TokenKind {
|
|
|
|
fn hash_stable<W: StableHasherResult>(&self,
|
|
|
|
hcx: &mut StableHashingContext<'a>,
|
|
|
|
hasher: &mut StableHasher<W>) {
|
|
|
|
mem::discriminant(self).hash_stable(hcx, hasher);
|
|
|
|
match *self {
|
|
|
|
token::Eq |
|
|
|
|
token::Lt |
|
|
|
|
token::Le |
|
|
|
|
token::EqEq |
|
|
|
|
token::Ne |
|
|
|
|
token::Ge |
|
|
|
|
token::Gt |
|
|
|
|
token::AndAnd |
|
|
|
|
token::OrOr |
|
|
|
|
token::Not |
|
|
|
|
token::Tilde |
|
|
|
|
token::At |
|
|
|
|
token::Dot |
|
|
|
|
token::DotDot |
|
|
|
|
token::DotDotDot |
|
|
|
|
token::DotDotEq |
|
|
|
|
token::Comma |
|
|
|
|
token::Semi |
|
|
|
|
token::Colon |
|
|
|
|
token::ModSep |
|
|
|
|
token::RArrow |
|
|
|
|
token::LArrow |
|
|
|
|
token::FatArrow |
|
|
|
|
token::Pound |
|
|
|
|
token::Dollar |
|
|
|
|
token::Question |
|
|
|
|
token::SingleQuote |
|
|
|
|
token::Whitespace |
|
|
|
|
token::Comment |
|
|
|
|
token::Eof => {}
|
|
|
|
|
|
|
|
token::BinOp(bin_op_token) |
|
|
|
|
token::BinOpEq(bin_op_token) => {
|
|
|
|
std_hash::Hash::hash(&bin_op_token, hasher);
|
|
|
|
}
|
2017-03-30 13:27:27 +00:00
|
|
|
|
2019-06-04 17:42:43 +00:00
|
|
|
token::OpenDelim(delim_token) |
|
|
|
|
token::CloseDelim(delim_token) => {
|
|
|
|
std_hash::Hash::hash(&delim_token, hasher);
|
|
|
|
}
|
|
|
|
token::Literal(lit) => lit.hash_stable(hcx, hasher),
|
2017-03-30 13:27:27 +00:00
|
|
|
|
2019-06-05 08:56:06 +00:00
|
|
|
token::Ident(name, is_raw) => {
|
|
|
|
name.hash_stable(hcx, hasher);
|
2019-06-04 17:42:43 +00:00
|
|
|
is_raw.hash_stable(hcx, hasher);
|
|
|
|
}
|
2019-06-05 08:00:22 +00:00
|
|
|
token::Lifetime(name) => name.hash_stable(hcx, hasher),
|
2017-03-30 13:27:27 +00:00
|
|
|
|
2019-06-04 17:42:43 +00:00
|
|
|
token::Interpolated(_) => {
|
|
|
|
bug!("interpolated tokens should not be present in the HIR")
|
|
|
|
}
|
2017-03-30 13:27:27 +00:00
|
|
|
|
2019-06-04 17:42:43 +00:00
|
|
|
token::DocComment(val) |
|
|
|
|
token::Shebang(val) => val.hash_stable(hcx, hasher),
|
|
|
|
}
|
2017-03-30 13:27:27 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-27 14:12:57 +00:00
|
|
|
|
2019-06-04 17:42:43 +00:00
|
|
|
impl_stable_hash_for!(struct token::Token {
|
|
|
|
kind,
|
|
|
|
span
|
|
|
|
});
|
|
|
|
|
2019-03-03 17:56:24 +00:00
|
|
|
impl_stable_hash_for!(enum ::syntax::ast::NestedMetaItem {
|
2017-04-27 14:12:57 +00:00
|
|
|
MetaItem(meta_item),
|
|
|
|
Literal(lit)
|
|
|
|
});
|
|
|
|
|
|
|
|
impl_stable_hash_for!(struct ::syntax::ast::MetaItem {
|
2019-03-02 16:15:26 +00:00
|
|
|
path,
|
2017-04-27 14:12:57 +00:00
|
|
|
node,
|
|
|
|
span
|
|
|
|
});
|
|
|
|
|
|
|
|
impl_stable_hash_for!(enum ::syntax::ast::MetaItemKind {
|
|
|
|
Word,
|
|
|
|
List(nested_items),
|
|
|
|
NameValue(lit)
|
|
|
|
});
|
|
|
|
|
2019-06-17 20:55:22 +00:00
|
|
|
impl_stable_hash_for!(enum ::syntax_pos::hygiene::Transparency {
|
|
|
|
Transparent,
|
|
|
|
SemiTransparent,
|
|
|
|
Opaque,
|
|
|
|
});
|
|
|
|
|
2017-11-22 12:41:27 +00:00
|
|
|
impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnInfo {
|
|
|
|
call_site,
|
|
|
|
format,
|
2019-06-17 20:55:22 +00:00
|
|
|
def_site,
|
|
|
|
default_transparency,
|
2017-11-22 12:41:27 +00:00
|
|
|
allow_internal_unstable,
|
|
|
|
allow_internal_unsafe,
|
2018-06-11 11:21:36 +00:00
|
|
|
local_inner_macros,
|
2018-06-23 18:41:39 +00:00
|
|
|
edition
|
2017-11-22 12:41:27 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
impl_stable_hash_for!(enum ::syntax_pos::hygiene::ExpnFormat {
|
|
|
|
MacroAttribute(sym),
|
|
|
|
MacroBang(sym),
|
|
|
|
CompilerDesugaring(kind)
|
|
|
|
});
|
|
|
|
|
|
|
|
impl_stable_hash_for!(enum ::syntax_pos::hygiene::CompilerDesugaringKind {
|
2019-06-20 08:29:42 +00:00
|
|
|
CondTemporary,
|
2018-06-06 22:50:59 +00:00
|
|
|
Async,
|
2019-04-18 19:55:23 +00:00
|
|
|
Await,
|
2018-03-25 07:16:16 +00:00
|
|
|
QuestionMark,
|
2019-05-04 15:09:28 +00:00
|
|
|
ExistentialType,
|
2018-07-16 03:52:41 +00:00
|
|
|
ForLoop,
|
2018-07-22 01:47:02 +00:00
|
|
|
TryBlock
|
2017-11-22 12:41:27 +00:00
|
|
|
});
|
|
|
|
|
2017-12-14 07:09:19 +00:00
|
|
|
impl_stable_hash_for!(enum ::syntax_pos::FileName {
|
|
|
|
Real(pb),
|
|
|
|
Macros(s),
|
2018-10-30 14:11:24 +00:00
|
|
|
QuoteExpansion(s),
|
|
|
|
Anon(s),
|
|
|
|
MacroExpansion(s),
|
|
|
|
ProcMacroSourceCode(s),
|
|
|
|
CliCrateAttr(s),
|
|
|
|
CfgSpec(s),
|
2018-12-04 20:18:03 +00:00
|
|
|
Custom(s),
|
|
|
|
DocTest(pb, line),
|
2017-12-14 07:09:19 +00:00
|
|
|
});
|
|
|
|
|
2018-08-18 10:13:52 +00:00
|
|
|
impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
|
2017-04-27 14:12:57 +00:00
|
|
|
fn hash_stable<W: StableHasherResult>(&self,
|
2018-01-16 09:16:38 +00:00
|
|
|
hcx: &mut StableHashingContext<'a>,
|
2017-04-27 14:12:57 +00:00
|
|
|
hasher: &mut StableHasher<W>) {
|
2018-08-18 10:13:52 +00:00
|
|
|
let SourceFile {
|
2017-12-19 14:14:41 +00:00
|
|
|
name: _, // We hash the smaller name_hash instead of this
|
|
|
|
name_hash,
|
2017-04-27 14:12:57 +00:00
|
|
|
name_was_remapped,
|
2017-10-03 09:44:58 +00:00
|
|
|
unmapped_path: _,
|
2017-04-27 14:12:57 +00:00
|
|
|
crate_of_origin,
|
|
|
|
// Do not hash the source as it is not encoded
|
|
|
|
src: _,
|
2017-06-10 11:39:39 +00:00
|
|
|
src_hash,
|
2017-06-10 19:08:32 +00:00
|
|
|
external_src: _,
|
2017-04-27 14:12:57 +00:00
|
|
|
start_pos,
|
|
|
|
end_pos: _,
|
|
|
|
ref lines,
|
|
|
|
ref multibyte_chars,
|
2017-11-02 01:25:54 +00:00
|
|
|
ref non_narrow_chars,
|
2017-04-27 14:12:57 +00:00
|
|
|
} = *self;
|
|
|
|
|
2017-12-19 14:14:41 +00:00
|
|
|
(name_hash as u64).hash_stable(hcx, hasher);
|
2017-04-27 14:12:57 +00:00
|
|
|
name_was_remapped.hash_stable(hcx, hasher);
|
|
|
|
|
|
|
|
DefId {
|
|
|
|
krate: CrateNum::from_u32(crate_of_origin),
|
|
|
|
index: CRATE_DEF_INDEX,
|
|
|
|
}.hash_stable(hcx, hasher);
|
|
|
|
|
2017-06-10 11:39:39 +00:00
|
|
|
src_hash.hash_stable(hcx, hasher);
|
|
|
|
|
2018-08-18 10:13:56 +00:00
|
|
|
// We only hash the relative position within this source_file
|
2018-05-23 13:59:42 +00:00
|
|
|
lines.len().hash_stable(hcx, hasher);
|
|
|
|
for &line in lines.iter() {
|
|
|
|
stable_byte_pos(line, start_pos).hash_stable(hcx, hasher);
|
|
|
|
}
|
2017-04-27 14:12:57 +00:00
|
|
|
|
2018-08-18 10:13:56 +00:00
|
|
|
// We only hash the relative position within this source_file
|
2018-05-23 13:59:42 +00:00
|
|
|
multibyte_chars.len().hash_stable(hcx, hasher);
|
|
|
|
for &char_pos in multibyte_chars.iter() {
|
|
|
|
stable_multibyte_char(char_pos, start_pos).hash_stable(hcx, hasher);
|
|
|
|
}
|
2017-11-02 01:25:54 +00:00
|
|
|
|
2018-05-23 13:59:42 +00:00
|
|
|
non_narrow_chars.len().hash_stable(hcx, hasher);
|
|
|
|
for &char_pos in non_narrow_chars.iter() {
|
|
|
|
stable_non_narrow_char(char_pos, start_pos).hash_stable(hcx, hasher);
|
|
|
|
}
|
2017-04-27 14:12:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn stable_byte_pos(pos: ::syntax_pos::BytePos,
|
2018-08-18 10:13:56 +00:00
|
|
|
source_file_start: ::syntax_pos::BytePos)
|
2017-04-27 14:12:57 +00:00
|
|
|
-> u32 {
|
2018-08-18 10:13:56 +00:00
|
|
|
pos.0 - source_file_start.0
|
2017-04-27 14:12:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn stable_multibyte_char(mbc: ::syntax_pos::MultiByteChar,
|
2018-08-18 10:13:56 +00:00
|
|
|
source_file_start: ::syntax_pos::BytePos)
|
2017-04-27 14:12:57 +00:00
|
|
|
-> (u32, u32) {
|
|
|
|
let ::syntax_pos::MultiByteChar {
|
|
|
|
pos,
|
|
|
|
bytes,
|
|
|
|
} = mbc;
|
|
|
|
|
2018-08-18 10:13:56 +00:00
|
|
|
(pos.0 - source_file_start.0, bytes as u32)
|
2017-04-27 14:12:57 +00:00
|
|
|
}
|
2017-11-02 01:25:54 +00:00
|
|
|
|
|
|
|
fn stable_non_narrow_char(swc: ::syntax_pos::NonNarrowChar,
|
2018-08-18 10:13:56 +00:00
|
|
|
source_file_start: ::syntax_pos::BytePos)
|
2017-11-02 01:25:54 +00:00
|
|
|
-> (u32, u32) {
|
|
|
|
let pos = swc.pos();
|
|
|
|
let width = swc.width();
|
|
|
|
|
2018-08-18 10:13:56 +00:00
|
|
|
(pos.0 - source_file_start.0, width as u32)
|
2017-11-02 01:25:54 +00:00
|
|
|
}
|
2018-02-14 15:11:02 +00:00
|
|
|
|
2019-06-13 21:48:52 +00:00
|
|
|
impl<'tcx> HashStable<StableHashingContext<'tcx>> for feature_gate::Features {
|
2019-06-13 22:32:15 +00:00
|
|
|
fn hash_stable<W: StableHasherResult>(
|
|
|
|
&self,
|
|
|
|
hcx: &mut StableHashingContext<'tcx>,
|
|
|
|
hasher: &mut StableHasher<W>,
|
|
|
|
) {
|
2018-02-14 15:11:02 +00:00
|
|
|
// Unfortunately we cannot exhaustively list fields here, since the
|
|
|
|
// struct is macro generated.
|
2018-07-23 01:03:01 +00:00
|
|
|
self.declared_lang_features.hash_stable(hcx, hasher);
|
2018-02-14 15:11:02 +00:00
|
|
|
self.declared_lib_features.hash_stable(hcx, hasher);
|
|
|
|
|
|
|
|
self.walk_feature_fields(|feature_name, value| {
|
|
|
|
feature_name.hash_stable(hcx, hasher);
|
|
|
|
value.hash_stable(hcx, hasher);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|