Skip to content

Commit e9e6495

Browse files
committed
Port #[rustc_allow_incoherent_impl] to the new attribute system
1 parent a6bc816 commit e9e6495

File tree

7 files changed

+31
-10
lines changed

7 files changed

+31
-10
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ pub enum AttributeKind {
198198
/// Represents `#[rustc_allow_const_fn_unstable]`.
199199
AllowConstFnUnstable(ThinVec<Symbol>, Span),
200200

201+
/// Represents `#[rustc_allow_incoherent_impl]`.
202+
AllowIncoherentImpl(Span),
203+
201204
/// Represents `#[allow_internal_unstable]`.
202205
AllowInternalUnstable(ThinVec<(Symbol, Span)>, Span),
203206

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ impl AttributeKind {
1515
// tidy-alphabetical-start
1616
Align { .. } => No,
1717
AllowConstFnUnstable(..) => No,
18+
AllowIncoherentImpl(..) => No,
1819
AllowInternalUnstable(..) => Yes,
1920
AsPtr(..) => Yes,
2021
BodyStability { .. } => No,

compiler/rustc_attr_parsing/src/attributes/traits.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ impl<S: Stage> NoArgsAttributeParser<S> for CoinductiveParser {
125125
const CREATE: fn(Span) -> AttributeKind = AttributeKind::Coinductive;
126126
}
127127

128+
pub(crate) struct AllowIncoherentImplParser;
129+
impl<S: Stage> NoArgsAttributeParser<S> for AllowIncoherentImplParser {
130+
const PATH: &[Symbol] = &[sym::rustc_allow_incoherent_impl];
131+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
132+
const CREATE: fn(Span) -> AttributeKind = AttributeKind::AllowIncoherentImpl;
133+
}
134+
128135
pub(crate) struct FundamentalParser;
129136
impl<S: Stage> NoArgsAttributeParser<S> for FundamentalParser {
130137
const PATH: &[Symbol] = &[sym::fundamental];

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ use crate::attributes::stability::{
4444
};
4545
use crate::attributes::test_attrs::IgnoreParser;
4646
use crate::attributes::traits::{
47-
CoinductiveParser, ConstTraitParser, DenyExplicitImplParser, DoNotImplementViaObjectParser,
48-
FundamentalParser, MarkerParser, ParenSugarParser, SkipDuringMethodDispatchParser,
49-
SpecializationTraitParser, TypeConstParser, UnsafeSpecializationMarkerParser,
47+
AllowIncoherentImplParser, CoinductiveParser, ConstTraitParser, DenyExplicitImplParser,
48+
DoNotImplementViaObjectParser, FundamentalParser, MarkerParser, ParenSugarParser,
49+
SkipDuringMethodDispatchParser, SpecializationTraitParser, TypeConstParser,
50+
UnsafeSpecializationMarkerParser,
5051
};
5152
use crate::attributes::transparency::TransparencyParser;
5253
use crate::attributes::{AttributeParser as _, Combine, Single, WithoutArgs};
@@ -150,6 +151,7 @@ attribute_parsers!(
150151
Single<RustcObjectLifetimeDefaultParser>,
151152
Single<SkipDuringMethodDispatchParser>,
152153
Single<TransparencyParser>,
154+
Single<WithoutArgs<AllowIncoherentImplParser>>,
153155
Single<WithoutArgs<AsPtrParser>>,
154156
Single<WithoutArgs<CoinductiveParser>>,
155157
Single<WithoutArgs<ColdParser>>,

compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//! `tcx.inherent_impls(def_id)`). That value, however,
88
//! is computed by selecting an idea from this table.
99
10+
use rustc_attr_data_structures::{AttributeKind, find_attr};
1011
use rustc_hir as hir;
1112
use rustc_hir::def::DefKind;
1213
use rustc_hir::def_id::{DefId, LocalDefId};
@@ -85,7 +86,10 @@ impl<'tcx> InherentCollect<'tcx> {
8586
}
8687

8788
for &impl_item in items {
88-
if !self.tcx.has_attr(impl_item, sym::rustc_allow_incoherent_impl) {
89+
if !find_attr!(
90+
self.tcx.get_all_attrs(impl_item),
91+
AttributeKind::AllowIncoherentImpl(_)
92+
) {
8993
let impl_span = self.tcx.def_span(impl_def_id);
9094
return Err(self.tcx.dcx().emit_err(errors::InherentTyOutsideRelevant {
9195
span: impl_span,
@@ -116,7 +120,10 @@ impl<'tcx> InherentCollect<'tcx> {
116120
if !self.tcx.hir_rustc_coherence_is_core() {
117121
if self.tcx.features().rustc_attrs() {
118122
for &impl_item in items {
119-
if !self.tcx.has_attr(impl_item, sym::rustc_allow_incoherent_impl) {
123+
if !find_attr!(
124+
self.tcx.get_all_attrs(impl_item),
125+
AttributeKind::AllowIncoherentImpl(_)
126+
) {
120127
let span = self.tcx.def_span(impl_def_id);
121128
return Err(self.tcx.dcx().emit_err(errors::InherentTyOutsidePrimitive {
122129
span,

compiler/rustc_parse/src/validate_attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ pub fn check_builtin_meta_item(
289289
| sym::const_trait
290290
| sym::rustc_specialization_trait
291291
| sym::rustc_unsafe_specialization_marker
292+
| sym::rustc_allow_incoherent_impl
292293
| sym::marker
293294
| sym::fundamental
294295
| sym::rustc_paren_sugar

compiler/rustc_passes/src/check_attr.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
146146
Attribute::Parsed(AttributeKind::Fundamental) => {
147147
// FIXME: add validation
148148
}
149+
&Attribute::Parsed(AttributeKind::AllowIncoherentImpl(attr_span)) => {
150+
self.check_allow_incoherent_impl(attr_span, span, target)
151+
}
149152
Attribute::Parsed(AttributeKind::Confusables { first_span, .. }) => {
150153
self.check_confusables(*first_span, target);
151154
}
@@ -319,9 +322,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
319322
[sym::rustc_must_implement_one_of, ..] => self.check_must_be_applied_to_trait(attr.span(), span, target),
320323
[sym::collapse_debuginfo, ..] => self.check_collapse_debuginfo(attr, span, target),
321324
[sym::must_not_suspend, ..] => self.check_must_not_suspend(attr, span, target),
322-
[sym::rustc_allow_incoherent_impl, ..] => {
323-
self.check_allow_incoherent_impl(attr, span, target)
324-
}
325325
[sym::rustc_has_incoherent_inherent_impls, ..] => {
326326
self.check_has_incoherent_inherent_impls(attr, span, target)
327327
}
@@ -1498,11 +1498,11 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
14981498
}
14991499
}
15001500

1501-
fn check_allow_incoherent_impl(&self, attr: &Attribute, span: Span, target: Target) {
1501+
fn check_allow_incoherent_impl(&self, attr_span: Span, span: Span, target: Target) {
15021502
match target {
15031503
Target::Method(MethodKind::Inherent) => {}
15041504
_ => {
1505-
self.dcx().emit_err(errors::AllowIncoherentImpl { attr_span: attr.span(), span });
1505+
self.dcx().emit_err(errors::AllowIncoherentImpl { attr_span, span });
15061506
}
15071507
}
15081508
}

0 commit comments

Comments
 (0)