Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 12 additions & 19 deletions compiler/rustc_attr_ir/src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -55,7 +48,9 @@ pub enum Target {
ForeignFn,
ForeignStatic,
ForeignTy,
GenericParam { kind: GenericParamKind, has_default: bool },
LifetimeParam,
TypeParam,
ConstParam,
MacroDef,
Param,
PatField,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 2 additions & 7 deletions compiler/rustc_attr_parsing/src/attributes/semantics.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
use rustc_attr_ir::target::GenericParamKind;
use rustc_feature::AttributeStability;

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;
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_attr_parsing/src/attributes/stability.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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),
Expand Down
27 changes: 3 additions & 24 deletions compiler/rustc_attr_parsing/src/target_checking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
20 changes: 4 additions & 16 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}
Expand Down
16 changes: 4 additions & 12 deletions compiler/rustc_hir/src/target_impls.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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,
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading