Skip to content

Commit 4935b73

Browse files
committed
Port rustc_effective_visibility to the new attribute parser
1 parent 0a13b43 commit 4935b73

6 files changed

Lines changed: 64 additions & 2 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,3 +721,60 @@ impl<S: Stage> CombineAttributeParser<S> for RustcThenThisWouldNeedParser {
721721
Some(ident)
722722
}
723723
}
724+
725+
pub(crate) struct RustcIntrinsicParser;
726+
727+
impl<S: Stage> NoArgsAttributeParser<S> for RustcIntrinsicParser {
728+
const PATH: &'static [Symbol] = &[sym::rustc_intrinsic];
729+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
730+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Fn)]);
731+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcIntrinsic;
732+
}
733+
734+
pub(crate) struct RustcIntrinsicConstStableIndirectParser;
735+
736+
impl<S: Stage> NoArgsAttributeParser<S> for RustcIntrinsicConstStableIndirectParser {
737+
const PATH: &'static [Symbol] = &[sym::rustc_intrinsic_const_stable_indirect];
738+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
739+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Fn)]);
740+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcIntrinsicConstStableIndirect;
741+
}
742+
743+
pub(crate) struct RustcEffectiveVisibilityParser;
744+
745+
impl<S: Stage> NoArgsAttributeParser<S> for RustcEffectiveVisibilityParser {
746+
const PATH: &'static [Symbol] = &[sym::rustc_effective_visibility];
747+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
748+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
749+
Allow(Target::Use),
750+
Allow(Target::Static),
751+
Allow(Target::Const),
752+
Allow(Target::Fn),
753+
Allow(Target::Closure),
754+
Allow(Target::Mod),
755+
Allow(Target::ForeignMod),
756+
Allow(Target::TyAlias),
757+
Allow(Target::Enum),
758+
Allow(Target::Variant),
759+
Allow(Target::Struct),
760+
Allow(Target::Field),
761+
Allow(Target::Union),
762+
Allow(Target::Trait),
763+
Allow(Target::TraitAlias),
764+
Allow(Target::Impl { of_trait: false }),
765+
Allow(Target::Impl { of_trait: true }),
766+
Allow(Target::AssocConst),
767+
Allow(Target::Method(MethodKind::Inherent)),
768+
Allow(Target::Method(MethodKind::Trait { body: false })),
769+
Allow(Target::Method(MethodKind::Trait { body: true })),
770+
Allow(Target::Method(MethodKind::TraitImpl)),
771+
Allow(Target::AssocTy),
772+
Allow(Target::ForeignFn),
773+
Allow(Target::ForeignStatic),
774+
Allow(Target::ForeignTy),
775+
Allow(Target::MacroDef),
776+
Allow(Target::PatField),
777+
Allow(Target::Crate),
778+
]);
779+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcEffectiveVisibility;
780+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ attribute_parsers!(
258258
Single<WithoutArgs<RustcDumpPredicatesParser>>,
259259
Single<WithoutArgs<RustcDumpUserArgsParser>>,
260260
Single<WithoutArgs<RustcDumpVtableParser>>,
261+
Single<WithoutArgs<RustcEffectiveVisibilityParser>>,
261262
Single<WithoutArgs<RustcHasIncoherentInherentImplsParser>>,
262263
Single<WithoutArgs<RustcHiddenTypeOfOpaquesParser>>,
263264
Single<WithoutArgs<RustcLintOptTyParser>>,

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,9 @@ pub enum AttributeKind {
10941094
/// Represents `#[rustc_dyn_incompatible_trait]`.
10951095
RustcDynIncompatibleTrait(Span),
10961096

1097+
/// Represents `#[rustc_effective_visibility]`.
1098+
RustcEffectiveVisibility,
1099+
10971100
/// Represents `#[rustc_has_incoherent_inherent_impls]`
10981101
RustcHasIncoherentInherentImpls,
10991102

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ impl AttributeKind {
112112
RustcDumpUserArgs => No,
113113
RustcDumpVtable(..) => No,
114114
RustcDynIncompatibleTrait(..) => No,
115+
RustcEffectiveVisibility => Yes,
115116
RustcHasIncoherentInherentImpls => Yes,
116117
RustcHiddenTypeOfOpaques => No,
117118
RustcIfThisChanged(..) => No,

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
307307
| AttributeKind::RustcDumpUserArgs
308308
| AttributeKind::RustcDumpVtable(..)
309309
| AttributeKind::RustcDynIncompatibleTrait(..)
310+
| AttributeKind::RustcEffectiveVisibility
310311
| AttributeKind::RustcHasIncoherentInherentImpls
311312
| AttributeKind::RustcHiddenTypeOfOpaques
312313
| AttributeKind::RustcIfThisChanged(..)
@@ -401,7 +402,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
401402
| sym::rustc_regions
402403
| sym::rustc_strict_coherence
403404
| sym::rustc_mir
404-
| sym::rustc_effective_visibility
405405
| sym::rustc_outlives
406406
| sym::rustc_symbol_name
407407
| sym::rustc_evaluate_where_clauses

compiler/rustc_privacy/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ pub struct TestReachabilityVisitor<'a, 'tcx> {
876876

877877
impl<'a, 'tcx> TestReachabilityVisitor<'a, 'tcx> {
878878
fn effective_visibility_diagnostic(&self, def_id: LocalDefId) {
879-
if self.tcx.has_attr(def_id, sym::rustc_effective_visibility) {
879+
if find_attr!(self.tcx.get_all_attrs(def_id), AttributeKind::RustcEffectiveVisibility) {
880880
let mut error_msg = String::new();
881881
let span = self.tcx.def_span(def_id.to_def_id());
882882
if let Some(effective_vis) = self.effective_visibilities.effective_vis(def_id) {

0 commit comments

Comments
 (0)