Skip to content

Commit d2dcaaa

Browse files
committed
change hashing to hash hir::Attribute instead of ast::Attribute
1 parent 1bfc0b5 commit d2dcaaa

File tree

3 files changed

+13
-23
lines changed

3 files changed

+13
-23
lines changed

compiler/rustc_ast/src/lib.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,10 @@ pub mod token;
4444
pub mod tokenstream;
4545
pub mod visit;
4646

47-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
48-
4947
pub use self::ast::*;
5048
pub use self::ast_traits::{AstDeref, AstNodeWrapper, HasAttrs, HasNodeId, HasTokens};
5149

5250
/// Requirements for a `StableHashingContext` to be used in this crate.
5351
/// This is a hack to allow using the `HashStable_Generic` derive macro
5452
/// instead of implementing everything in `rustc_middle`.
55-
pub trait HashStableContext: rustc_span::HashStableContext {
56-
fn hash_attr(&mut self, _: &ast::Attribute, hasher: &mut StableHasher);
57-
}
58-
59-
impl<AstCtx: crate::HashStableContext> HashStable<AstCtx> for ast::Attribute {
60-
fn hash_stable(&self, hcx: &mut AstCtx, hasher: &mut StableHasher) {
61-
hcx.hash_attr(self, hasher)
62-
}
63-
}
53+
pub trait HashStableContext: rustc_span::HashStableContext {}

compiler/rustc_hir/src/stable_hash_impls.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::hir_id::{HirId, ItemLocalId};
1313
pub trait HashStableContext:
1414
rustc_ast::HashStableContext + rustc_target::HashStableContext
1515
{
16+
fn hash_attr(&mut self, _: &Attribute, hasher: &mut StableHasher);
1617
}
1718

1819
impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for HirId {
@@ -114,3 +115,9 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Crate<'_> {
114115
opt_hir_hash.unwrap().hash_stable(hcx, hasher)
115116
}
116117
}
118+
119+
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for Attribute {
120+
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
121+
hcx.hash_attr(self, hasher)
122+
}
123+
}

compiler/rustc_query_system/src/ich/impls_syntax.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,23 @@ impl<'ctx> HashStable<StableHashingContext<'ctx>> for [hir::Attribute] {
3535
}
3636
}
3737

38-
impl<'ctx> rustc_ast::HashStableContext for StableHashingContext<'ctx> {
39-
fn hash_attr(&mut self, attr: &ast::Attribute, hasher: &mut StableHasher) {
38+
impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {
39+
fn hash_attr(&mut self, attr: &hir::Attribute, hasher: &mut StableHasher) {
4040
// Make sure that these have been filtered out.
4141
debug_assert!(!attr.ident().is_some_and(|ident| self.is_ignored_attr(ident.name)));
4242
debug_assert!(!attr.is_doc_comment());
4343

44-
let ast::Attribute { kind, id: _, style, span } = attr;
45-
if let ast::AttrKind::Normal(normal) = kind {
46-
normal.item.hash_stable(self, hasher);
44+
let hir::Attribute { kind, id: _, style, span } = attr;
45+
if let hir::AttrKind::Normal(item) = kind {
46+
item.hash_stable(self, hasher);
4747
style.hash_stable(self, hasher);
4848
span.hash_stable(self, hasher);
49-
assert_matches!(
50-
normal.tokens.as_ref(),
51-
None,
52-
"Tokens should have been removed during lowering!"
53-
);
5449
} else {
5550
unreachable!();
5651
}
5752
}
5853
}
5954

60-
impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {}
61-
6255
impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
6356
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
6457
let SourceFile {

0 commit comments

Comments
 (0)