Add hir::Attribute
This commit is contained in:
parent
53b2c7cc95
commit
d50c0a5480
89 changed files with 1144 additions and 659 deletions
|
@ -1,18 +1,17 @@
|
|||
//! This module contains `HashStable` implementations for various data types
|
||||
//! from `rustc_ast` in no particular order.
|
||||
//! from various crates in no particular order.
|
||||
|
||||
use std::assert_matches::assert_matches;
|
||||
|
||||
use rustc_ast as ast;
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_hir as hir;
|
||||
use rustc_span::SourceFile;
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use crate::ich::StableHashingContext;
|
||||
|
||||
impl<'ctx> rustc_target::HashStableContext for StableHashingContext<'ctx> {}
|
||||
impl<'ctx> rustc_ast::HashStableContext for StableHashingContext<'ctx> {}
|
||||
|
||||
impl<'a> HashStable<StableHashingContext<'a>> for [ast::Attribute] {
|
||||
impl<'a> HashStable<StableHashingContext<'a>> for [hir::Attribute] {
|
||||
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
|
||||
if self.is_empty() {
|
||||
self.len().hash_stable(hcx, hasher);
|
||||
|
@ -20,7 +19,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for [ast::Attribute] {
|
|||
}
|
||||
|
||||
// Some attributes are always ignored during hashing.
|
||||
let filtered: SmallVec<[&ast::Attribute; 8]> = self
|
||||
let filtered: SmallVec<[&hir::Attribute; 8]> = self
|
||||
.iter()
|
||||
.filter(|attr| {
|
||||
!attr.is_doc_comment()
|
||||
|
@ -35,30 +34,23 @@ impl<'a> HashStable<StableHashingContext<'a>> for [ast::Attribute] {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'ctx> rustc_ast::HashStableContext for StableHashingContext<'ctx> {
|
||||
fn hash_attr(&mut self, attr: &ast::Attribute, hasher: &mut StableHasher) {
|
||||
impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {
|
||||
fn hash_attr(&mut self, attr: &hir::Attribute, hasher: &mut StableHasher) {
|
||||
// Make sure that these have been filtered out.
|
||||
debug_assert!(!attr.ident().is_some_and(|ident| self.is_ignored_attr(ident.name)));
|
||||
debug_assert!(!attr.is_doc_comment());
|
||||
|
||||
let ast::Attribute { kind, id: _, style, span } = attr;
|
||||
if let ast::AttrKind::Normal(normal) = kind {
|
||||
normal.item.hash_stable(self, hasher);
|
||||
let hir::Attribute { kind, id: _, style, span } = attr;
|
||||
if let hir::AttrKind::Normal(item) = kind {
|
||||
item.hash_stable(self, hasher);
|
||||
style.hash_stable(self, hasher);
|
||||
span.hash_stable(self, hasher);
|
||||
assert_matches!(
|
||||
normal.tokens.as_ref(),
|
||||
None,
|
||||
"Tokens should have been removed during lowering!"
|
||||
);
|
||||
} else {
|
||||
unreachable!();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {}
|
||||
|
||||
impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
|
||||
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
|
||||
let SourceFile {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue