Skip to content

Commit 351bd34

Browse files
committed
Port #[rustc_allow_incoherent_impl] to the new attribute system
1 parent c4302ae commit 351bd34

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
@@ -200,6 +200,9 @@ pub enum AttributeKind {
200200
/// Represents `#[rustc_allow_const_fn_unstable]`.
201201
AllowConstFnUnstable(ThinVec<Symbol>, Span),
202202

203+
/// Represents `#[rustc_allow_incoherent_impl]`.
204+
AllowIncoherentImpl(Span),
205+
203206
/// Represents `#[allow_internal_unstable]`.
204207
AllowInternalUnstable(ThinVec<(Symbol, Span)>, Span),
205208

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
@@ -38,9 +38,10 @@ use crate::attributes::stability::{
3838
BodyStabilityParser, ConstStabilityIndirectParser, ConstStabilityParser, StabilityParser,
3939
};
4040
use crate::attributes::traits::{
41-
CoinductiveParser, ConstTraitParser, DenyExplicitImplParser, DoNotImplementViaObjectParser,
42-
FundamentalParser, MarkerParser, ParenSugarParser, SkipDuringMethodDispatchParser,
43-
SpecializationTraitParser, TypeConstParser, UnsafeSpecializationMarkerParser,
41+
AllowIncoherentImplParser, CoinductiveParser, ConstTraitParser, DenyExplicitImplParser,
42+
DoNotImplementViaObjectParser, FundamentalParser, MarkerParser, ParenSugarParser,
43+
SkipDuringMethodDispatchParser, SpecializationTraitParser, TypeConstParser,
44+
UnsafeSpecializationMarkerParser,
4445
};
4546
use crate::attributes::transparency::TransparencyParser;
4647
use crate::attributes::{AttributeParser as _, Combine, Single, WithoutArgs};
@@ -141,6 +142,7 @@ attribute_parsers!(
141142
Single<RustcObjectLifetimeDefaultParser>,
142143
Single<SkipDuringMethodDispatchParser>,
143144
Single<TransparencyParser>,
145+
Single<WithoutArgs<AllowIncoherentImplParser>>,
144146
Single<WithoutArgs<AsPtrParser>>,
145147
Single<WithoutArgs<CoinductiveParser>>,
146148
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
@@ -300,6 +300,7 @@ fn emit_malformed_attribute(
300300
| sym::const_trait
301301
| sym::rustc_specialization_trait
302302
| sym::rustc_unsafe_specialization_marker
303+
| sym::rustc_allow_incoherent_impl
303304
| sym::marker
304305
| sym::fundamental
305306
| 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
}
@@ -303,9 +306,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
303306
[sym::rustc_must_implement_one_of, ..] => self.check_must_be_applied_to_trait(attr.span(), span, target),
304307
[sym::collapse_debuginfo, ..] => self.check_collapse_debuginfo(attr, span, target),
305308
[sym::must_not_suspend, ..] => self.check_must_not_suspend(attr, span, target),
306-
[sym::rustc_allow_incoherent_impl, ..] => {
307-
self.check_allow_incoherent_impl(attr, span, target)
308-
}
309309
[sym::rustc_has_incoherent_inherent_impls, ..] => {
310310
self.check_has_incoherent_inherent_impls(attr, span, target)
311311
}
@@ -1485,11 +1485,11 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
14851485
}
14861486
}
14871487

1488-
fn check_allow_incoherent_impl(&self, attr: &Attribute, span: Span, target: Target) {
1488+
fn check_allow_incoherent_impl(&self, attr_span: Span, span: Span, target: Target) {
14891489
match target {
14901490
Target::Method(MethodKind::Inherent) => {}
14911491
_ => {
1492-
self.dcx().emit_err(errors::AllowIncoherentImpl { attr_span: attr.span(), span });
1492+
self.dcx().emit_err(errors::AllowIncoherentImpl { attr_span, span });
14931493
}
14941494
}
14951495
}

0 commit comments

Comments
 (0)