Skip to content

Commit 6f8e92d

Browse files
committed
Port #[rustc_coinductive] to the new attribute system
1 parent adb325f commit 6f8e92d

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
@@ -211,6 +211,9 @@ pub enum AttributeKind {
211211
span: Span,
212212
},
213213

214+
/// Represents `#[rustc_coinductive]`.
215+
Coinductive(Span),
216+
214217
/// Represents `#[cold]`.
215218
Cold(Span),
216219

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
@@ -44,7 +44,7 @@ use crate::attributes::stability::{
4444
};
4545
use crate::attributes::test_attrs::IgnoreParser;
4646
use crate::attributes::traits::{
47-
ConstTraitParser, DenyExplicitImplParser, DoNotImplementViaObjectParser,
47+
CoinductiveParser, ConstTraitParser, DenyExplicitImplParser, DoNotImplementViaObjectParser,
4848
SkipDuringMethodDispatchParser,
4949
};
5050
use crate::attributes::transparency::TransparencyParser;
@@ -150,6 +150,7 @@ attribute_parsers!(
150150
Single<SkipDuringMethodDispatchParser>,
151151
Single<TransparencyParser>,
152152
Single<WithoutArgs<AsPtrParser>>,
153+
Single<WithoutArgs<CoinductiveParser>>,
153154
Single<WithoutArgs<ColdParser>>,
154155
Single<WithoutArgs<ConstContinueParser>>,
155156
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
@@ -285,6 +285,7 @@ pub fn check_builtin_meta_item(
285285
| sym::rustc_pass_by_value
286286
| sym::rustc_deny_explicit_impl
287287
| sym::rustc_do_not_implement_via_object
288+
| sym::rustc_coinductive
288289
| sym::const_trait
289290
| sym::repr
290291
| 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),
@@ -299,9 +300,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
299300
| [sym::rustc_dirty, ..]
300301
| [sym::rustc_if_this_changed, ..]
301302
| [sym::rustc_then_this_would_need, ..] => self.check_rustc_dirty_clean(attr),
302-
[sym::rustc_coinductive, ..]
303-
| [sym::rustc_must_implement_one_of, ..]
304-
=> self.check_must_be_applied_to_trait(attr.span(), span, target),
303+
[sym::rustc_must_implement_one_of, ..] => self.check_must_be_applied_to_trait(attr.span(), span, target),
305304
[sym::collapse_debuginfo, ..] => self.check_collapse_debuginfo(attr, span, target),
306305
[sym::must_not_suspend, ..] => self.check_must_not_suspend(attr, span, target),
307306
[sym::rustc_allow_incoherent_impl, ..] => {

0 commit comments

Comments
 (0)