Skip to content

Commit c64453e

Browse files
committed
Fix #[type_const] attribute placement validation
1 parent 45391bd commit c64453e

File tree

2 files changed

+3
-14
lines changed

2 files changed

+3
-14
lines changed

compiler/rustc_attr_parsing/src/attributes/traits.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ pub(crate) struct TypeConstParser;
6666
impl<S: Stage> NoArgsAttributeParser<S> for TypeConstParser {
6767
const PATH: &[Symbol] = &[sym::type_const];
6868
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
69-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::AssocConst)]);
69+
const ALLOWED_TARGETS: AllowedTargets =
70+
AllowedTargets::AllowList(&[Allow(Target::Const), Allow(Target::AssocConst)]);
7071
const CREATE: fn(Span) -> AttributeKind = AttributeKind::TypeConst;
7172
}
7273

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
150150
Attribute::Parsed(AttributeKind::ProcMacroDerive { .. }) => {
151151
self.check_proc_macro(hir_id, target, ProcMacroKind::Derive)
152152
}
153-
&Attribute::Parsed(AttributeKind::TypeConst(attr_span)) => {
154-
self.check_type_const(hir_id, attr_span, target)
155-
}
156153
Attribute::Parsed(
157154
AttributeKind::Stability {
158155
span: attr_span,
@@ -243,6 +240,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
243240
| AttributeKind::ParenSugar(..)
244241
| AttributeKind::AllowIncoherentImpl(..)
245242
| AttributeKind::Confusables { .. }
243+
| AttributeKind::TypeConst{..}
246244
// `#[doc]` is actually a lot more than just doc comments, so is checked below
247245
| AttributeKind::DocComment {..}
248246
// handled below this loop and elsewhere
@@ -2102,16 +2100,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
21022100
}
21032101
}
21042102

2105-
fn check_type_const(&self, _hir_id: HirId, attr_span: Span, target: Target) {
2106-
if matches!(target, Target::AssocConst | Target::Const) {
2107-
return;
2108-
} else {
2109-
self.dcx()
2110-
.struct_span_err(attr_span, "`#[type_const]` must only be applied to const items")
2111-
.emit();
2112-
}
2113-
}
2114-
21152103
fn check_rustc_pub_transparent(&self, attr_span: Span, span: Span, attrs: &[Attribute]) {
21162104
if !find_attr!(attrs, AttributeKind::Repr { reprs, .. } => reprs.iter().any(|(r, _)| r == &ReprAttr::ReprTransparent))
21172105
.unwrap_or(false)

0 commit comments

Comments
 (0)