Skip to content

Commit 26bd904

Browse files
committed
Port rustc_insignificant_dtor to the new attribute parser
1 parent 06cafcb commit 26bd904

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
@@ -722,6 +722,19 @@ impl<S: Stage> CombineAttributeParser<S> for RustcThenThisWouldNeedParser {
722722
}
723723
}
724724

725+
pub(crate) struct RustcInsignificantDtorParser;
726+
727+
impl<S: Stage> NoArgsAttributeParser<S> for RustcInsignificantDtorParser {
728+
const PATH: &[Symbol] = &[sym::rustc_insignificant_dtor];
729+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
730+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
731+
Allow(Target::Enum),
732+
Allow(Target::Struct),
733+
Allow(Target::ForeignTy),
734+
]);
735+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcInsignificantDtor;
736+
}
737+
725738
pub(crate) struct RustcEffectiveVisibilityParser;
726739

727740
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
@@ -264,6 +264,7 @@ attribute_parsers!(
264264
Single<WithoutArgs<RustcEffectiveVisibilityParser>>,
265265
Single<WithoutArgs<RustcHasIncoherentInherentImplsParser>>,
266266
Single<WithoutArgs<RustcHiddenTypeOfOpaquesParser>>,
267+
Single<WithoutArgs<RustcInsignificantDtorParser>>,
267268
Single<WithoutArgs<RustcLintOptTyParser>>,
268269
Single<WithoutArgs<RustcLintQueryInstabilityParser>>,
269270
Single<WithoutArgs<RustcLintUntrackedQueryInformationParser>>,

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_layout]`
11241127
RustcLayout(ThinVec<RustcLayoutType>),
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
RustcLayout(..) => No,
122123
RustcLayoutScalarValidRangeEnd(..) => Yes,
123124
RustcLayoutScalarValidRangeStart(..) => Yes,

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::RustcLayout(..)
317318
| AttributeKind::RustcLayoutScalarValidRangeEnd(..)
318319
| AttributeKind::RustcLayoutScalarValidRangeStart(..)
@@ -383,7 +384,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
383384
| sym::default_lib_allocator
384385
| sym::rustc_diagnostic_item
385386
| sym::rustc_no_mir_inline
386-
| sym::rustc_insignificant_dtor
387387
| sym::rustc_nonnull_optimization_guaranteed
388388
| sym::rustc_intrinsic
389389
| sym::rustc_inherit_overflow_checks

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)