Skip to content

Commit f1b4c2a

Browse files
committed
Port rustc_insignificant_dtor to the new attribute parser
1 parent 286fbe5 commit f1b4c2a

6 files changed

Lines changed: 22 additions & 4 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,19 @@ impl<S: Stage> CombineAttributeParser<S> for RustcThenThisWouldNeedParser {
739739
}
740740
}
741741

742+
pub(crate) struct RustcInsignificantDtorParser;
743+
744+
impl<S: Stage> NoArgsAttributeParser<S> for RustcInsignificantDtorParser {
745+
const PATH: &[Symbol] = &[sym::rustc_insignificant_dtor];
746+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
747+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
748+
Allow(Target::Enum),
749+
Allow(Target::Struct),
750+
Allow(Target::ForeignTy),
751+
]);
752+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcInsignificantDtor;
753+
}
754+
742755
pub(crate) struct RustcEffectiveVisibilityParser;
743756

744757
impl<S: Stage> NoArgsAttributeParser<S> for RustcEffectiveVisibilityParser {

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ attribute_parsers!(
270270
Single<WithoutArgs<RustcEffectiveVisibilityParser>>,
271271
Single<WithoutArgs<RustcHasIncoherentInherentImplsParser>>,
272272
Single<WithoutArgs<RustcHiddenTypeOfOpaquesParser>>,
273+
Single<WithoutArgs<RustcInsignificantDtorParser>>,
273274
Single<WithoutArgs<RustcIntrinsicConstStableIndirectParser>>,
274275
Single<WithoutArgs<RustcIntrinsicParser>>,
275276
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
@@ -1120,6 +1120,9 @@ pub enum AttributeKind {
11201120
/// Represents `#[rustc_if_this_changed]`
11211121
RustcIfThisChanged(Span, Option<Symbol>),
11221122

1123+
/// Represents `#[rustc_insignificant_dtor]`
1124+
RustcInsignificantDtor,
1125+
11231126
/// Represents `#[rustc_intrinsic]`
11241127
RustcIntrinsic,
11251128

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ impl AttributeKind {
118118
RustcHasIncoherentInherentImpls => Yes,
119119
RustcHiddenTypeOfOpaques => No,
120120
RustcIfThisChanged(..) => No,
121+
RustcInsignificantDtor => Yes,
121122
RustcIntrinsic => Yes,
122123
RustcIntrinsicConstStableIndirect => No,
123124
RustcLayout(..) => No,

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
313313
| AttributeKind::RustcHasIncoherentInherentImpls
314314
| AttributeKind::RustcHiddenTypeOfOpaques
315315
| AttributeKind::RustcIfThisChanged(..)
316+
| AttributeKind::RustcInsignificantDtor
316317
| AttributeKind::RustcIntrinsic
317318
| AttributeKind::RustcIntrinsicConstStableIndirect
318319
| AttributeKind::RustcLayout(..)
@@ -386,7 +387,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
386387
| sym::default_lib_allocator
387388
| sym::rustc_diagnostic_item
388389
| sym::rustc_no_mir_inline
389-
| sym::rustc_insignificant_dtor
390390
| sym::rustc_nonnull_optimization_guaranteed
391391
| sym::rustc_inherit_overflow_checks
392392
| sym::rustc_trivial_field_reads

compiler/rustc_ty_utils/src/needs_drop.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
//! Check whether a type has (potentially) non-trivial drop glue.
22
33
use rustc_data_structures::fx::FxHashSet;
4+
use rustc_hir::attrs::AttributeKind;
45
use rustc_hir::def_id::DefId;
6+
use rustc_hir::find_attr;
57
use rustc_hir::limit::Limit;
68
use rustc_middle::bug;
79
use rustc_middle::query::Providers;
810
use rustc_middle::ty::util::{AlwaysRequiresDrop, needs_drop_components};
911
use rustc_middle::ty::{self, EarlyBinder, GenericArgsRef, Ty, TyCtxt};
10-
use rustc_span::sym;
1112
use tracing::{debug, instrument};
1213

1314
use crate::errors::NeedsDropOverflow;
@@ -396,8 +397,7 @@ fn adt_consider_insignificant_dtor<'tcx>(
396397
tcx: TyCtxt<'tcx>,
397398
) -> impl Fn(ty::AdtDef<'tcx>) -> Option<DtorType> {
398399
move |adt_def: ty::AdtDef<'tcx>| {
399-
let is_marked_insig = tcx.has_attr(adt_def.did(), sym::rustc_insignificant_dtor);
400-
if is_marked_insig {
400+
if find_attr!(tcx.get_all_attrs(adt_def.did()), AttributeKind::RustcInsignificantDtor) {
401401
// In some cases like `std::collections::HashMap` where the struct is a wrapper around
402402
// a type that is a Drop type, and the wrapped type (eg: `hashbrown::HashMap`) lies
403403
// outside stdlib, we might choose to still annotate the wrapper (std HashMap) with

0 commit comments

Comments
 (0)