diff --git a/compiler/rustc_attr_ir/src/target.rs b/compiler/rustc_attr_ir/src/target.rs index aa36df24f7f78..c41e78c4a96e0 100644 --- a/compiler/rustc_attr_ir/src/target.rs +++ b/compiler/rustc_attr_ir/src/target.rs @@ -6,13 +6,6 @@ pub use rustc_ast::visit::AssocCtxt; use rustc_ast::{AssocItemKind, ForeignItemKind, ast}; use rustc_macros::StableHash; -#[derive(Copy, Clone, PartialEq, Debug, Eq, StableHash)] -pub enum GenericParamKind { - Type, - Lifetime, - Const, -} - #[derive(Copy, Clone, PartialEq, Debug, Eq, StableHash)] pub enum MethodKind { /// Method in a `trait Trait` block @@ -55,7 +48,9 @@ pub enum Target { ForeignFn, ForeignStatic, ForeignTy, - GenericParam { kind: GenericParamKind, has_default: bool }, + LifetimeParam, + TypeParam, + ConstParam, MacroDef, Param, PatField, @@ -106,7 +101,9 @@ impl Target { | Target::ForeignFn | Target::ForeignStatic | Target::ForeignTy - | Target::GenericParam { .. } + | Target::TypeParam + | Target::LifetimeParam + | Target::ConstParam | Target::MacroDef | Target::Param | Target::PatField @@ -222,11 +219,9 @@ impl Target { Target::ForeignFn => "foreign function", Target::ForeignStatic => "foreign static item", Target::ForeignTy => "foreign type", - Target::GenericParam { kind, .. } => match kind { - GenericParamKind::Type => "type parameter", - GenericParamKind::Lifetime => "lifetime parameter", - GenericParamKind::Const => "const parameter", - }, + Target::TypeParam => "type parameter", + Target::LifetimeParam => "lifetime parameter", + Target::ConstParam => "const parameter", Target::MacroDef => "macro def", Target::Param => "function param", Target::PatField => "pattern field", @@ -277,11 +272,9 @@ impl Target { Target::ForeignFn => "foreign functions", Target::ForeignStatic => "foreign statics", Target::ForeignTy => "foreign types", - Target::GenericParam { kind, has_default: _ } => match kind { - GenericParamKind::Type => "type parameters", - GenericParamKind::Lifetime => "lifetime parameters", - GenericParamKind::Const => "const parameters", - }, + Target::TypeParam => "type parameters", + Target::LifetimeParam => "lifetime parameters", + Target::ConstParam => "const parameters", Target::MacroDef => "macro defs", Target::Param => "function params", Target::PatField => "pattern fields", diff --git a/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs b/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs index 0df3d9a626bee..ec233705c46d3 100644 --- a/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs +++ b/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs @@ -2,7 +2,6 @@ use std::path::PathBuf; use rustc_ast::{LitIntType, LitKind, MetaItemLit}; use rustc_attr_ir::lang_items::LangItem; -use rustc_attr_ir::target::GenericParamKind; use rustc_attr_ir::{ BorrowckGraphvizFormatKind, CguFields, CguKind, RustcCleanAttribute, RustcCleanQueries, RustcMirKind, @@ -109,10 +108,8 @@ pub(crate) struct RustcPanicsWhenZeroParser; impl NoArgsAttributeParser for RustcPanicsWhenZeroParser { const PATH: &[Symbol] = &[sym::rustc_panics_when_zero]; - const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[ - Allow(Target::GenericParam { kind: GenericParamKind::Const, has_default: true }), - Allow(Target::GenericParam { kind: GenericParamKind::Const, has_default: false }), - ]); + const ALLOWED_TARGETS: AllowedTargets<'_> = + AllowedTargets::AllowList(&[Allow(Target::ConstParam)]); const STABILITY: AttributeStability = unstable!(rustc_attrs); const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcPanicsWhenZero; diff --git a/compiler/rustc_attr_parsing/src/attributes/semantics.rs b/compiler/rustc_attr_parsing/src/attributes/semantics.rs index 7a8475c12eada..013ef2221bcc0 100644 --- a/compiler/rustc_attr_parsing/src/attributes/semantics.rs +++ b/compiler/rustc_attr_parsing/src/attributes/semantics.rs @@ -1,4 +1,3 @@ -use rustc_attr_ir::target::GenericParamKind; use rustc_feature::AttributeStability; use super::prelude::*; @@ -6,12 +5,8 @@ use super::prelude::*; pub(crate) struct MayDangleParser; impl NoArgsAttributeParser for MayDangleParser { const PATH: &[Symbol] = &[sym::may_dangle]; - const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[ - Allow(Target::GenericParam { kind: GenericParamKind::Type, has_default: false }), - Allow(Target::GenericParam { kind: GenericParamKind::Type, has_default: true }), - Allow(Target::GenericParam { kind: GenericParamKind::Lifetime, has_default: false }), - Allow(Target::GenericParam { kind: GenericParamKind::Lifetime, has_default: true }), - ]); + const ALLOWED_TARGETS: AllowedTargets<'_> = + AllowedTargets::AllowList(&[Allow(Target::TypeParam), Allow(Target::LifetimeParam)]); const STABILITY: AttributeStability = unstable!(dropck_eyepatch); const CREATE: fn(span: Span) -> AttributeKind = AttributeKind::MayDangle; } diff --git a/compiler/rustc_attr_parsing/src/attributes/stability.rs b/compiler/rustc_attr_parsing/src/attributes/stability.rs index 29e288d858c37..f14934ab76547 100644 --- a/compiler/rustc_attr_parsing/src/attributes/stability.rs +++ b/compiler/rustc_attr_parsing/src/attributes/stability.rs @@ -1,6 +1,6 @@ use std::num::NonZero; -use rustc_attr_ir::target::{AssocCtxt, GenericParamKind, MethodKind, Target}; +use rustc_attr_ir::target::{AssocCtxt, MethodKind, Target}; use rustc_attr_ir::{ DefaultBodyStability, PartialConstStability, Stability, StabilityLevel, StableSince, UnstableReason, UnstableRemovedFeature, VERSION_PLACEHOLDER, @@ -40,7 +40,7 @@ const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[ Allow(Target::TyAlias), Allow(Target::Variant), Allow(Target::Field), - Allow(Target::GenericParam { kind: GenericParamKind::Type, has_default: true }), + Allow(Target::TypeParam), Allow(Target::Static), Allow(Target::ForeignFn), Allow(Target::ForeignStatic), diff --git a/compiler/rustc_attr_parsing/src/target_checking.rs b/compiler/rustc_attr_parsing/src/target_checking.rs index 1e272b9674dab..5fc0b248110f7 100644 --- a/compiler/rustc_attr_parsing/src/target_checking.rs +++ b/compiler/rustc_attr_parsing/src/target_checking.rs @@ -532,30 +532,9 @@ pub(crate) const ALL_TARGETS: &[Policy] = { Allow(Target::Crate), Allow(Target::Delegation { mac: false }), Allow(Target::Delegation { mac: true }), - Allow(Target::GenericParam { - kind: rustc_attr_ir::target::GenericParamKind::Const, - has_default: false, - }), - Allow(Target::GenericParam { - kind: rustc_attr_ir::target::GenericParamKind::Const, - has_default: true, - }), - Allow(Target::GenericParam { - kind: rustc_attr_ir::target::GenericParamKind::Lifetime, - has_default: false, - }), - Allow(Target::GenericParam { - kind: rustc_attr_ir::target::GenericParamKind::Lifetime, - has_default: true, - }), - Allow(Target::GenericParam { - kind: rustc_attr_ir::target::GenericParamKind::Type, - has_default: false, - }), - Allow(Target::GenericParam { - kind: rustc_attr_ir::target::GenericParamKind::Type, - has_default: true, - }), + Allow(Target::ConstParam), + Allow(Target::LifetimeParam), + Allow(Target::TypeParam), Allow(Target::Loop), Allow(Target::ForLoop), Allow(Target::While), diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index c58629111ac00..9a435b8e783dd 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -1748,22 +1748,10 @@ impl InvocationCollectorNode for ast::GenericParam { walk_flat_map_generic_param(collector, self) } fn as_target(&self) -> Target { - let mut has_default = false; - Target::GenericParam { - kind: match &self.kind { - rustc_ast::GenericParamKind::Lifetime => { - rustc_attr_ir::target::GenericParamKind::Lifetime - } - rustc_ast::GenericParamKind::Type { default } => { - has_default = default.is_some(); - rustc_attr_ir::target::GenericParamKind::Type - } - rustc_ast::GenericParamKind::Const { default, .. } => { - has_default = default.is_some(); - rustc_attr_ir::target::GenericParamKind::Const - } - }, - has_default, + match self.kind { + rustc_ast::GenericParamKind::Lifetime => Target::LifetimeParam, + rustc_ast::GenericParamKind::Type { .. } => Target::TypeParam, + rustc_ast::GenericParamKind::Const { .. } => Target::ConstParam, } } } diff --git a/compiler/rustc_hir/src/target_impls.rs b/compiler/rustc_hir/src/target_impls.rs index d2959cf46fda0..d437925278927 100644 --- a/compiler/rustc_hir/src/target_impls.rs +++ b/compiler/rustc_hir/src/target_impls.rs @@ -1,6 +1,6 @@ //! Implements conversions from HIR types to Target. -use rustc_attr_ir::target::{AssocCtxt, GenericParamKind, MethodKind, Target}; +use rustc_attr_ir::target::{AssocCtxt, MethodKind, Target}; use crate::def::DefKind; use crate::{self as hir, ItemKind, TraitItemKind}; @@ -18,17 +18,9 @@ impl From<&hir::ForeignItem<'_>> for Target { impl From<&hir::GenericParam<'_>> for Target { fn from(generic_param: &hir::GenericParam<'_>) -> Target { match generic_param.kind { - hir::GenericParamKind::Type { default, .. } => Target::GenericParam { - kind: GenericParamKind::Type, - has_default: default.is_some(), - }, - hir::GenericParamKind::Lifetime { .. } => { - Target::GenericParam { kind: GenericParamKind::Lifetime, has_default: false } - } - hir::GenericParamKind::Const { default, .. } => Target::GenericParam { - kind: GenericParamKind::Const, - has_default: default.is_some(), - }, + hir::GenericParamKind::Type { .. } => Target::TypeParam, + hir::GenericParamKind::Lifetime { .. } => Target::LifetimeParam, + hir::GenericParamKind::Const { .. } => Target::ConstParam, } } } diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index cd7f422fb72f3..0543697191762 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -872,7 +872,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> { | Target::ForeignFn | Target::ForeignStatic | Target::ForeignTy - | Target::GenericParam { .. } + | Target::TypeParam + | Target::LifetimeParam + | Target::ConstParam | Target::MacroDef | Target::PatField | Target::ExprField