diff --git a/compiler/rustc_attr_parsing/src/attributes/traits.rs b/compiler/rustc_attr_parsing/src/attributes/traits.rs index ced3bcad2293..0765ccf384af 100644 --- a/compiler/rustc_attr_parsing/src/attributes/traits.rs +++ b/compiler/rustc_attr_parsing/src/attributes/traits.rs @@ -66,7 +66,8 @@ pub(crate) struct TypeConstParser; impl NoArgsAttributeParser for TypeConstParser { const PATH: &[Symbol] = &[sym::type_const]; const ON_DUPLICATE: OnDuplicate = OnDuplicate::Error; - const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::AssocConst)]); + const ALLOWED_TARGETS: AllowedTargets = + AllowedTargets::AllowList(&[Allow(Target::Const), Allow(Target::AssocConst)]); const CREATE: fn(Span) -> AttributeKind = AttributeKind::TypeConst; } diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 463338ee1fb5..1a422e308302 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -150,9 +150,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> { Attribute::Parsed(AttributeKind::ProcMacroDerive { .. }) => { self.check_proc_macro(hir_id, target, ProcMacroKind::Derive) } - &Attribute::Parsed(AttributeKind::TypeConst(attr_span)) => { - self.check_type_const(hir_id, attr_span, target) - } Attribute::Parsed( AttributeKind::Stability { span: attr_span, @@ -243,6 +240,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { | AttributeKind::ParenSugar(..) | AttributeKind::AllowIncoherentImpl(..) | AttributeKind::Confusables { .. } + | AttributeKind::TypeConst{..} // `#[doc]` is actually a lot more than just doc comments, so is checked below | AttributeKind::DocComment {..} // handled below this loop and elsewhere @@ -2115,16 +2113,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } } - fn check_type_const(&self, _hir_id: HirId, attr_span: Span, target: Target) { - if matches!(target, Target::AssocConst | Target::Const) { - return; - } else { - self.dcx() - .struct_span_err(attr_span, "`#[type_const]` must only be applied to const items") - .emit(); - } - } - fn check_rustc_pub_transparent(&self, attr_span: Span, span: Span, attrs: &[Attribute]) { if !find_attr!(attrs, AttributeKind::Repr { reprs, .. } => reprs.iter().any(|(r, _)| r == &ReprAttr::ReprTransparent)) .unwrap_or(false)