Port #[rustc_dump_def_parents]

This commit is contained in:
Jonathan Brouwer 2026-01-12 19:43:31 +01:00
parent 84d59d0731
commit cf4d480eff
No known key found for this signature in database
GPG key ID: F13E55D38C971DEF
6 changed files with 19 additions and 4 deletions

View file

@ -15,3 +15,12 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpUserArgs {
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Fn)]);
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpUserArgs;
}
pub(crate) struct RustcDumpDefParents;
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpDefParents {
const PATH: &[Symbol] = &[sym::rustc_dump_def_parents];
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Fn)]);
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpDefParents;
}

View file

@ -63,7 +63,7 @@ use crate::attributes::proc_macro_attrs::{
};
use crate::attributes::prototype::CustomMirParser;
use crate::attributes::repr::{AlignParser, AlignStaticParser, ReprParser};
use crate::attributes::rustc_dump::RustcDumpUserArgs;
use crate::attributes::rustc_dump::{RustcDumpUserArgs, RustcDumpDefParents};
use crate::attributes::rustc_internal::{
RustcHasIncoherentInherentImplsParser, RustcLayoutScalarValidRangeEndParser,
RustcLayoutScalarValidRangeStartParser, RustcLegacyConstGenericsParser,
@ -268,6 +268,7 @@ attribute_parsers!(
Single<WithoutArgs<ProcMacroParser>>,
Single<WithoutArgs<PubTransparentParser>>,
Single<WithoutArgs<RustcCoherenceIsCoreParser>>,
Single<WithoutArgs<RustcDumpDefParents >>,
Single<WithoutArgs<RustcDumpUserArgs>>,
Single<WithoutArgs<RustcHasIncoherentInherentImplsParser>>,
Single<WithoutArgs<RustcLintDiagnosticsParser>>,

View file

@ -906,6 +906,9 @@ pub enum AttributeKind {
/// Represents `#[rustc_coherence_is_core]`
RustcCoherenceIsCore(Span),
/// Represents `#[rustc_dump_def_parents]`
RustcDumpDefParents,
/// Represents `#[rustc_dump_user_args]`
RustcDumpUserArgs,

View file

@ -97,6 +97,7 @@ impl AttributeKind {
Repr { .. } => No,
RustcBuiltinMacro { .. } => Yes,
RustcCoherenceIsCore(..) => No,
RustcDumpDefParents => No,
RustcDumpUserArgs => No,
RustcHasIncoherentInherentImpls => Yes,
RustcLayoutScalarValidRangeEnd(..) => Yes,

View file

@ -1,6 +1,7 @@
use rustc_hir as hir;
use rustc_hir::def_id::{CRATE_DEF_ID, LocalDefId};
use rustc_hir::intravisit;
use rustc_hir::{find_attr, intravisit};
use rustc_hir::attrs::AttributeKind;
use rustc_middle::hir::nested_filter;
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt};
use rustc_span::sym;
@ -54,7 +55,7 @@ pub(crate) fn predicates_and_item_bounds(tcx: TyCtxt<'_>) {
pub(crate) fn def_parents(tcx: TyCtxt<'_>) {
for iid in tcx.hir_free_items() {
let did = iid.owner_id.def_id;
if tcx.has_attr(did, sym::rustc_dump_def_parents) {
if find_attr!(tcx.get_all_attrs(did), AttributeKind::RustcDumpDefParents) {
struct AnonConstFinder<'tcx> {
tcx: TyCtxt<'tcx>,
anon_consts: Vec<LocalDefId>,

View file

@ -310,6 +310,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
| AttributeKind::RustcHasIncoherentInherentImpls
| AttributeKind::MustNotSupend { .. }
| AttributeKind::RustcDumpUserArgs
| AttributeKind::RustcDumpDefParents
) => { /* do nothing */ }
Attribute::Unparsed(attr_item) => {
style = Some(attr_item.style);
@ -369,7 +370,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
| sym::rustc_abi
| sym::rustc_layout
| sym::rustc_proc_macro_decls
| sym::rustc_dump_def_parents
| sym::rustc_never_type_options
| sym::rustc_autodiff
| sym::rustc_capture_analysis