Fix #[type_const] attribute placement validation

This commit is contained in:
Noah Lev 2025-11-08 15:43:29 -05:00
parent 72b21e1a64
commit e56de95478
2 changed files with 3 additions and 14 deletions

View file

@ -66,7 +66,8 @@ pub(crate) struct TypeConstParser;
impl<S: Stage> NoArgsAttributeParser<S> for TypeConstParser {
const PATH: &[Symbol] = &[sym::type_const];
const ON_DUPLICATE: OnDuplicate<S> = 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;
}

View file

@ -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)