Skip to content

Commit a24b1c4

Browse files
committed
Port #[rustc_coinductive] to the new attribute system
1 parent 0b97865 commit a24b1c4

File tree

7 files changed

+17
-5
lines changed

7 files changed

+17
-5
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ pub enum AttributeKind {
213213
span: Span,
214214
},
215215

216+
/// Represents `#[rustc_coinductive]`.
217+
Coinductive(Span),
218+
216219
/// Represents `#[cold]`.
217220
Cold(Span),
218221

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

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

compiler/rustc_attr_parsing/src/attributes/traits.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,10 @@ impl<S: Stage> NoArgsAttributeParser<S> for DoNotImplementViaObjectParser {
7575
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
7676
const CREATE: fn(Span) -> AttributeKind = AttributeKind::DoNotImplementViaObject;
7777
}
78+
79+
pub(crate) struct CoinductiveParser;
80+
impl<S: Stage> NoArgsAttributeParser<S> for CoinductiveParser {
81+
const PATH: &[Symbol] = &[sym::rustc_coinductive];
82+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
83+
const CREATE: fn(Span) -> AttributeKind = AttributeKind::Coinductive;
84+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use crate::attributes::stability::{
3636
BodyStabilityParser, ConstStabilityIndirectParser, ConstStabilityParser, StabilityParser,
3737
};
3838
use crate::attributes::traits::{
39-
ConstTraitParser, DenyExplicitImplParser, DoNotImplementViaObjectParser,
39+
CoinductiveParser, ConstTraitParser, DenyExplicitImplParser, DoNotImplementViaObjectParser,
4040
SkipDuringMethodDispatchParser,
4141
};
4242
use crate::attributes::transparency::TransparencyParser;
@@ -139,6 +139,7 @@ attribute_parsers!(
139139
Single<SkipDuringMethodDispatchParser>,
140140
Single<TransparencyParser>,
141141
Single<WithoutArgs<AsPtrParser>>,
142+
Single<WithoutArgs<CoinductiveParser>>,
142143
Single<WithoutArgs<ColdParser>>,
143144
Single<WithoutArgs<ConstContinueParser>>,
144145
Single<WithoutArgs<ConstStabilityIndirectParser>>,

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
871871
// Only regular traits can be marker.
872872
let is_marker = !is_alias && attrs.iter().any(|attr| attr.has_name(sym::marker));
873873

874-
let rustc_coinductive = attrs.iter().any(|attr| attr.has_name(sym::rustc_coinductive));
874+
let rustc_coinductive = find_attr!(attrs, AttributeKind::Coinductive(_));
875875
let is_fundamental = attrs.iter().any(|attr| attr.has_name(sym::fundamental));
876876

877877
let [skip_array_during_method_dispatch, skip_boxed_slice_during_method_dispatch] = find_attr!(

compiler/rustc_parse/src/validate_attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ fn emit_malformed_attribute(
295295
| sym::rustc_skip_during_method_dispatch
296296
| sym::rustc_deny_explicit_impl
297297
| sym::rustc_do_not_implement_via_object
298+
| sym::rustc_coinductive
298299
| sym::const_trait
299300
| sym::repr
300301
| sym::align

compiler/rustc_passes/src/check_attr.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
122122
match attr {
123123
Attribute::Parsed(
124124
AttributeKind::SkipDuringMethodDispatch { span: attr_span, .. }
125+
| AttributeKind::Coinductive(attr_span)
125126
| AttributeKind::ConstTrait(attr_span)
126127
| AttributeKind::DenyExplicitImpl(attr_span)
127128
| AttributeKind::DoNotImplementViaObject(attr_span),
@@ -270,9 +271,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
270271
| [sym::rustc_dirty, ..]
271272
| [sym::rustc_if_this_changed, ..]
272273
| [sym::rustc_then_this_would_need, ..] => self.check_rustc_dirty_clean(attr),
273-
[sym::rustc_coinductive, ..]
274-
| [sym::rustc_must_implement_one_of, ..]
275-
=> self.check_must_be_applied_to_trait(attr.span(), span, target),
274+
[sym::rustc_must_implement_one_of, ..] => self.check_must_be_applied_to_trait(attr.span(), span, target),
276275
[sym::collapse_debuginfo, ..] => self.check_collapse_debuginfo(attr, span, target),
277276
[sym::must_not_suspend, ..] => self.check_must_not_suspend(attr, span, target),
278277
[sym::rustc_pass_by_value, ..] => self.check_pass_by_value(attr, span, target),

0 commit comments

Comments
 (0)