diff options
| author | bors <bors@rust-lang.org> | 2024-12-15 22:05:33 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-12-15 22:05:33 +0000 |
| commit | f2b91ccbc27cb06369aa2dd934ff219e156408a8 (patch) | |
| tree | 19f4a39307c4ccf081e763eddd4c4d6ffe86e99f /compiler/rustc_query_system | |
| parent | c26db435bf8aee2efc397aab50f3a21eb351d6e5 (diff) | |
| parent | 1d5ec2cd6a359fbae353586c7aedfac9a5fcc845 (diff) | |
| download | rust-f2b91ccbc27cb06369aa2dd934ff219e156408a8.tar.gz rust-f2b91ccbc27cb06369aa2dd934ff219e156408a8.zip | |
Auto merge of #131808 - jdonszelmann:hir-attributes, r=oli-obk,petrochenkov
Hir attributes This PR needs some explanation, it's somewhat large. - This is step one as described in https://github.com/rust-lang/compiler-team/issues/796. I've added a new `hir::Attribute` which is a lowered version of `ast::Attribute`. Right now, this has few concrete effects, however every place that after this PR parses a `hir::Attribute` should later get a pre-parsed attribute as described in https://github.com/rust-lang/compiler-team/issues/796 and transitively https://github.com/rust-lang/rust/issues/131229. - an extension trait `AttributeExt` is added, which is implemented for both `ast::Attribute` and `hir::Atribute`. This makes `hir::Attributes` mostly compatible with code that used to parse `ast::Attribute`. All its methods are also added as inherent methods to avoid having to import the trait everywhere in the compiler. - Incremental can not not hash `ast::Attribute` at all.
Diffstat (limited to 'compiler/rustc_query_system')
| -rw-r--r-- | compiler/rustc_query_system/src/ich/impls_syntax.rs | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/compiler/rustc_query_system/src/ich/impls_syntax.rs b/compiler/rustc_query_system/src/ich/impls_syntax.rs index 5a72e80a0a5..480fd497728 100644 --- a/compiler/rustc_query_system/src/ich/impls_syntax.rs +++ b/compiler/rustc_query_system/src/ich/impls_syntax.rs @@ -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 { |
