Skip to content

Commit 5e883ef

Browse files
committed
Port #[rustc_coherence_is_core] to the new attribute system
1 parent abca2c1 commit 5e883ef

File tree

7 files changed

+20
-6
lines changed

7 files changed

+20
-6
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ pub enum AttributeKind {
216216
span: Span,
217217
},
218218

219+
/// Represents `#[rustc_coherence_is_core]`.
220+
CoherenceIsCore,
221+
219222
/// Represents `#[rustc_coinductive]`.
220223
Coinductive(Span),
221224

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ impl AttributeKind {
1919
AllowInternalUnstable(..) => Yes,
2020
AsPtr(..) => Yes,
2121
BodyStability { .. } => No,
22+
CoherenceIsCore => No,
2223
Coinductive(..) => No,
2324
Cold(..) => No,
2425
Confusables { .. } => Yes,

compiler/rustc_attr_parsing/src/attributes/traits.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ impl<S: Stage> NoArgsAttributeParser<S> for AllowIncoherentImplParser {
132132
const CREATE: fn(Span) -> AttributeKind = AttributeKind::AllowIncoherentImpl;
133133
}
134134

135+
pub(crate) struct CoherenceIsCoreParser;
136+
impl<S: Stage> NoArgsAttributeParser<S> for CoherenceIsCoreParser {
137+
const PATH: &[Symbol] = &[sym::rustc_coherence_is_core];
138+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
139+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::CoherenceIsCore;
140+
}
141+
135142
pub(crate) struct FundamentalParser;
136143
impl<S: Stage> NoArgsAttributeParser<S> for FundamentalParser {
137144
const PATH: &[Symbol] = &[sym::fundamental];

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ use crate::attributes::stability::{
3737
BodyStabilityParser, ConstStabilityIndirectParser, ConstStabilityParser, StabilityParser,
3838
};
3939
use crate::attributes::traits::{
40-
AllowIncoherentImplParser, CoinductiveParser, ConstTraitParser, DenyExplicitImplParser,
41-
DoNotImplementViaObjectParser, FundamentalParser, MarkerParser, ParenSugarParser,
42-
SkipDuringMethodDispatchParser, SpecializationTraitParser, TypeConstParser,
40+
AllowIncoherentImplParser, CoherenceIsCoreParser, CoinductiveParser, ConstTraitParser,
41+
DenyExplicitImplParser, DoNotImplementViaObjectParser, FundamentalParser, MarkerParser,
42+
ParenSugarParser, SkipDuringMethodDispatchParser, SpecializationTraitParser, TypeConstParser,
4343
UnsafeSpecializationMarkerParser,
4444
};
4545
use crate::attributes::transparency::TransparencyParser;
@@ -143,6 +143,7 @@ attribute_parsers!(
143143
Single<TransparencyParser>,
144144
Single<WithoutArgs<AllowIncoherentImplParser>>,
145145
Single<WithoutArgs<AsPtrParser>>,
146+
Single<WithoutArgs<CoherenceIsCoreParser>>,
146147
Single<WithoutArgs<CoinductiveParser>>,
147148
Single<WithoutArgs<ColdParser>>,
148149
Single<WithoutArgs<ConstContinueParser>>,

compiler/rustc_middle/src/hir/map.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
use rustc_abi::ExternAbi;
66
use rustc_ast::visit::{VisitorResult, walk_list};
7+
use rustc_attr_data_structures::{AttributeKind, find_attr};
78
use rustc_data_structures::fingerprint::Fingerprint;
89
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
910
use rustc_data_structures::svh::Svh;
@@ -15,7 +16,7 @@ use rustc_hir::intravisit::Visitor;
1516
use rustc_hir::*;
1617
use rustc_hir_pretty as pprust_hir;
1718
use rustc_span::def_id::StableCrateId;
18-
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol, kw, sym, with_metavar_spans};
19+
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol, kw, with_metavar_spans};
1920

2021
use crate::hir::{ModuleItems, nested_filter};
2122
use crate::middle::debugger_visualizer::DebuggerVisualizerFile;
@@ -369,7 +370,7 @@ impl<'tcx> TyCtxt<'tcx> {
369370
}
370371

371372
pub fn hir_rustc_coherence_is_core(self) -> bool {
372-
self.hir_krate_attrs().iter().any(|attr| attr.has_name(sym::rustc_coherence_is_core))
373+
find_attr!(self.hir_krate_attrs(), AttributeKind::CoherenceIsCore)
373374
}
374375

375376
pub fn hir_get_module(self, module: LocalModDefId) -> (&'tcx Mod<'tcx>, Span, HirId) {

compiler/rustc_parse/src/validate_attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ fn emit_malformed_attribute(
301301
| sym::rustc_specialization_trait
302302
| sym::rustc_unsafe_specialization_marker
303303
| sym::rustc_allow_incoherent_impl
304+
| sym::rustc_coherence_is_core
304305
| sym::marker
305306
| sym::fundamental
306307
| sym::rustc_paren_sugar

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
143143
&Attribute::Parsed(AttributeKind::Marker(attr_span)) => {
144144
self.check_marker(hir_id, attr_span, span, target)
145145
}
146-
Attribute::Parsed(AttributeKind::Fundamental) => {
146+
Attribute::Parsed(AttributeKind::Fundamental | AttributeKind::CoherenceIsCore) => {
147147
// FIXME: add validation
148148
}
149149
&Attribute::Parsed(AttributeKind::AllowIncoherentImpl(attr_span)) => {

0 commit comments

Comments
 (0)