Skip to content

Commit 11cf5c9

Browse files
Rollup merge of rust-lang#152170 - jdonszelmann:port-rustc-effective-visibility, r=JonathanBrouwer
Port `rustc_effective_visibility` to the new attribute parser r? @JonathanBrouwer
2 parents 210b672 + 9112039 commit 11cf5c9

File tree

6 files changed

+46
-2
lines changed

6 files changed

+46
-2
lines changed

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

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

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)