Skip to content

Commit da5ea0a

Browse files
committed
Port #[rustc_coherence_is_core] to the new attribute system
1 parent d22b4c7 commit da5ea0a

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
@@ -214,6 +214,9 @@ pub enum AttributeKind {
214214
span: Span,
215215
},
216216

217+
/// Represents `#[rustc_coherence_is_core]`.
218+
CoherenceIsCore,
219+
217220
/// Represents `#[rustc_coinductive]`.
218221
Coinductive(Span),
219222

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
@@ -40,9 +40,9 @@ use crate::attributes::stability::{
4040
};
4141
use crate::attributes::test_attrs::IgnoreParser;
4242
use crate::attributes::traits::{
43-
AllowIncoherentImplParser, CoinductiveParser, ConstTraitParser, DenyExplicitImplParser,
44-
DoNotImplementViaObjectParser, FundamentalParser, MarkerParser, ParenSugarParser,
45-
SkipDuringMethodDispatchParser, SpecializationTraitParser, TypeConstParser,
43+
AllowIncoherentImplParser, CoherenceIsCoreParser, CoinductiveParser, ConstTraitParser,
44+
DenyExplicitImplParser, DoNotImplementViaObjectParser, FundamentalParser, MarkerParser,
45+
ParenSugarParser, SkipDuringMethodDispatchParser, SpecializationTraitParser, TypeConstParser,
4646
UnsafeSpecializationMarkerParser,
4747
};
4848
use crate::attributes::transparency::TransparencyParser;
@@ -148,6 +148,7 @@ attribute_parsers!(
148148
Single<TransparencyParser>,
149149
Single<WithoutArgs<AllowIncoherentImplParser>>,
150150
Single<WithoutArgs<AsPtrParser>>,
151+
Single<WithoutArgs<CoherenceIsCoreParser>>,
151152
Single<WithoutArgs<CoinductiveParser>>,
152153
Single<WithoutArgs<ColdParser>>,
153154
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
@@ -286,6 +286,7 @@ pub fn check_builtin_meta_item(
286286
| sym::rustc_specialization_trait
287287
| sym::rustc_unsafe_specialization_marker
288288
| sym::rustc_allow_incoherent_impl
289+
| sym::rustc_coherence_is_core
289290
| sym::marker
290291
| sym::fundamental
291292
| 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)