Port rustc_insignificant_dtor to the new attribute parser

This commit is contained in:
Jana Dönszelmann 2026-02-07 14:42:17 +01:00
parent 286fbe5d84
commit f1b4c2a0e6
No known key found for this signature in database
6 changed files with 22 additions and 4 deletions

View file

@ -739,6 +739,19 @@ impl<S: Stage> CombineAttributeParser<S> for RustcThenThisWouldNeedParser {
}
}
pub(crate) struct RustcInsignificantDtorParser;
impl<S: Stage> NoArgsAttributeParser<S> for RustcInsignificantDtorParser {
const PATH: &[Symbol] = &[sym::rustc_insignificant_dtor];
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
Allow(Target::Enum),
Allow(Target::Struct),
Allow(Target::ForeignTy),
]);
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcInsignificantDtor;
}
pub(crate) struct RustcEffectiveVisibilityParser;
impl<S: Stage> NoArgsAttributeParser<S> for RustcEffectiveVisibilityParser {

View file

@ -270,6 +270,7 @@ attribute_parsers!(
Single<WithoutArgs<RustcEffectiveVisibilityParser>>,
Single<WithoutArgs<RustcHasIncoherentInherentImplsParser>>,
Single<WithoutArgs<RustcHiddenTypeOfOpaquesParser>>,
Single<WithoutArgs<RustcInsignificantDtorParser>>,
Single<WithoutArgs<RustcIntrinsicConstStableIndirectParser>>,
Single<WithoutArgs<RustcIntrinsicParser>>,
Single<WithoutArgs<RustcLintOptTyParser>>,

View file

@ -1120,6 +1120,9 @@ pub enum AttributeKind {
/// Represents `#[rustc_if_this_changed]`
RustcIfThisChanged(Span, Option<Symbol>),
/// Represents `#[rustc_insignificant_dtor]`
RustcInsignificantDtor,
/// Represents `#[rustc_intrinsic]`
RustcIntrinsic,

View file

@ -118,6 +118,7 @@ impl AttributeKind {
RustcHasIncoherentInherentImpls => Yes,
RustcHiddenTypeOfOpaques => No,
RustcIfThisChanged(..) => No,
RustcInsignificantDtor => Yes,
RustcIntrinsic => Yes,
RustcIntrinsicConstStableIndirect => No,
RustcLayout(..) => No,

View file

@ -313,6 +313,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
| AttributeKind::RustcHasIncoherentInherentImpls
| AttributeKind::RustcHiddenTypeOfOpaques
| AttributeKind::RustcIfThisChanged(..)
| AttributeKind::RustcInsignificantDtor
| AttributeKind::RustcIntrinsic
| AttributeKind::RustcIntrinsicConstStableIndirect
| AttributeKind::RustcLayout(..)
@ -386,7 +387,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
| sym::default_lib_allocator
| sym::rustc_diagnostic_item
| sym::rustc_no_mir_inline
| sym::rustc_insignificant_dtor
| sym::rustc_nonnull_optimization_guaranteed
| sym::rustc_inherit_overflow_checks
| sym::rustc_trivial_field_reads

View file

@ -1,13 +1,14 @@
//! Check whether a type has (potentially) non-trivial drop glue.
use rustc_data_structures::fx::FxHashSet;
use rustc_hir::attrs::AttributeKind;
use rustc_hir::def_id::DefId;
use rustc_hir::find_attr;
use rustc_hir::limit::Limit;
use rustc_middle::bug;
use rustc_middle::query::Providers;
use rustc_middle::ty::util::{AlwaysRequiresDrop, needs_drop_components};
use rustc_middle::ty::{self, EarlyBinder, GenericArgsRef, Ty, TyCtxt};
use rustc_span::sym;
use tracing::{debug, instrument};
use crate::errors::NeedsDropOverflow;
@ -396,8 +397,7 @@ fn adt_consider_insignificant_dtor<'tcx>(
tcx: TyCtxt<'tcx>,
) -> impl Fn(ty::AdtDef<'tcx>) -> Option<DtorType> {
move |adt_def: ty::AdtDef<'tcx>| {
let is_marked_insig = tcx.has_attr(adt_def.did(), sym::rustc_insignificant_dtor);
if is_marked_insig {
if find_attr!(tcx.get_all_attrs(adt_def.did()), AttributeKind::RustcInsignificantDtor) {
// In some cases like `std::collections::HashMap` where the struct is a wrapper around
// a type that is a Drop type, and the wrapped type (eg: `hashbrown::HashMap`) lies
// outside stdlib, we might choose to still annotate the wrapper (std HashMap) with