Skip to content

Commit b411784

Browse files
committed
Port #[rustc_coinductive] to the new attribute system
1 parent 92f7283 commit b411784

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
@@ -38,7 +38,7 @@ use crate::attributes::stability::{
3838
BodyStabilityParser, ConstStabilityIndirectParser, ConstStabilityParser, StabilityParser,
3939
};
4040
use crate::attributes::traits::{
41-
ConstTraitParser, DenyExplicitImplParser, DoNotImplementViaObjectParser,
41+
CoinductiveParser, ConstTraitParser, DenyExplicitImplParser, DoNotImplementViaObjectParser,
4242
SkipDuringMethodDispatchParser,
4343
};
4444
use crate::attributes::transparency::TransparencyParser;
@@ -141,6 +141,7 @@ attribute_parsers!(
141141
Single<SkipDuringMethodDispatchParser>,
142142
Single<TransparencyParser>,
143143
Single<WithoutArgs<AsPtrParser>>,
144+
Single<WithoutArgs<CoinductiveParser>>,
144145
Single<WithoutArgs<ColdParser>>,
145146
Single<WithoutArgs<ConstContinueParser>>,
146147
Single<WithoutArgs<ConstStabilityIndirectParser>>,

compiler/rustc_hir_analysis/src/collect.rs

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

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

874874
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
@@ -296,6 +296,7 @@ fn emit_malformed_attribute(
296296
| sym::rustc_pass_by_value
297297
| sym::rustc_deny_explicit_impl
298298
| sym::rustc_do_not_implement_via_object
299+
| sym::rustc_coinductive
299300
| sym::const_trait
300301
| sym::repr
301302
| 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),
@@ -283,9 +284,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
283284
| [sym::rustc_dirty, ..]
284285
| [sym::rustc_if_this_changed, ..]
285286
| [sym::rustc_then_this_would_need, ..] => self.check_rustc_dirty_clean(attr),
286-
[sym::rustc_coinductive, ..]
287-
| [sym::rustc_must_implement_one_of, ..]
288-
=> self.check_must_be_applied_to_trait(attr.span(), span, target),
287+
[sym::rustc_must_implement_one_of, ..] => self.check_must_be_applied_to_trait(attr.span(), span, target),
289288
[sym::collapse_debuginfo, ..] => self.check_collapse_debuginfo(attr, span, target),
290289
[sym::must_not_suspend, ..] => self.check_must_not_suspend(attr, span, target),
291290
[sym::rustc_allow_incoherent_impl, ..] => {

0 commit comments

Comments
 (0)