Skip to content

Commit 92f7283

Browse files
committed
Port #[rustc_do_not_implement_via_object] to the new attribute system
1 parent 887e461 commit 92f7283

File tree

7 files changed

+18
-5
lines changed

7 files changed

+18
-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
@@ -245,6 +245,9 @@ pub enum AttributeKind {
245245
/// Represents [`#[deprecated]`](https://doc.rust-lang.org/stable/reference/attributes/diagnostics.html#the-deprecated-attribute).
246246
Deprecation { deprecation: Deprecation, span: Span },
247247

248+
/// Represents `#[rustc_do_not_implement_via_object]`.
249+
DoNotImplementViaObject(Span),
250+
248251
/// Represents [`#[doc]`](https://doc.rust-lang.org/stable/rustdoc/write-documentation/the-doc-attribute.html).
249252
DocComment { style: AttrStyle, kind: CommentKind, span: Span, comment: Symbol },
250253

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ impl AttributeKind {
2626
ConstTrait(..) => No,
2727
DenyExplicitImpl(..) => No,
2828
Deprecation { .. } => Yes,
29+
DoNotImplementViaObject(..) => No,
2930
DocComment { .. } => Yes,
3031
ExportName { .. } => Yes,
3132
Inline(..) => No,

compiler/rustc_attr_parsing/src/attributes/traits.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,10 @@ impl<S: Stage> NoArgsAttributeParser<S> for DenyExplicitImplParser {
6868
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
6969
const CREATE: fn(Span) -> AttributeKind = AttributeKind::DenyExplicitImpl;
7070
}
71+
72+
pub(crate) struct DoNotImplementViaObjectParser;
73+
impl<S: Stage> NoArgsAttributeParser<S> for DoNotImplementViaObjectParser {
74+
const PATH: &[Symbol] = &[sym::rustc_do_not_implement_via_object];
75+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
76+
const CREATE: fn(Span) -> AttributeKind = AttributeKind::DoNotImplementViaObject;
77+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ use crate::attributes::stability::{
3838
BodyStabilityParser, ConstStabilityIndirectParser, ConstStabilityParser, StabilityParser,
3939
};
4040
use crate::attributes::traits::{
41-
ConstTraitParser, DenyExplicitImplParser, SkipDuringMethodDispatchParser,
41+
ConstTraitParser, DenyExplicitImplParser, DoNotImplementViaObjectParser,
42+
SkipDuringMethodDispatchParser,
4243
};
4344
use crate::attributes::transparency::TransparencyParser;
4445
use crate::attributes::{AttributeParser as _, Combine, Single, WithoutArgs};
@@ -145,6 +146,7 @@ attribute_parsers!(
145146
Single<WithoutArgs<ConstStabilityIndirectParser>>,
146147
Single<WithoutArgs<ConstTraitParser>>,
147148
Single<WithoutArgs<DenyExplicitImplParser>>,
149+
Single<WithoutArgs<DoNotImplementViaObjectParser>>,
148150
Single<WithoutArgs<LoopMatchParser>>,
149151
Single<WithoutArgs<MayDangleParser>>,
150152
Single<WithoutArgs<NoImplicitPreludeParser>>,

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -962,8 +962,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
962962
});
963963

964964
let deny_explicit_impl = find_attr!(attrs, AttributeKind::DenyExplicitImpl(_));
965-
let implement_via_object =
966-
!attrs.iter().any(|attr| attr.has_name(sym::rustc_do_not_implement_via_object));
965+
let implement_via_object = !find_attr!(attrs, AttributeKind::DoNotImplementViaObject(_));
967966

968967
ty::TraitDef {
969968
def_id: def_id.to_def_id(),

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_pass_by_value
297297
| sym::rustc_deny_explicit_impl
298+
| sym::rustc_do_not_implement_via_object
298299
| sym::const_trait
299300
| sym::repr
300301
| sym::align

compiler/rustc_passes/src/check_attr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
123123
Attribute::Parsed(
124124
AttributeKind::SkipDuringMethodDispatch { span: attr_span, .. }
125125
| AttributeKind::ConstTrait(attr_span)
126-
| AttributeKind::DenyExplicitImpl(attr_span),
126+
| AttributeKind::DenyExplicitImpl(attr_span)
127+
| AttributeKind::DoNotImplementViaObject(attr_span),
127128
) => {
128129
self.check_must_be_applied_to_trait(*attr_span, span, target);
129130
}
@@ -284,7 +285,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
284285
| [sym::rustc_then_this_would_need, ..] => self.check_rustc_dirty_clean(attr),
285286
[sym::rustc_coinductive, ..]
286287
| [sym::rustc_must_implement_one_of, ..]
287-
| [sym::rustc_do_not_implement_via_object, ..]
288288
=> self.check_must_be_applied_to_trait(attr.span(), span, target),
289289
[sym::collapse_debuginfo, ..] => self.check_collapse_debuginfo(attr, span, target),
290290
[sym::must_not_suspend, ..] => self.check_must_not_suspend(attr, span, target),

0 commit comments

Comments
 (0)