Skip to content

Commit 7cb4501

Browse files
authored
Rollup merge of #152291 - jdonszelmann:port-rustc-insignificant-dtor, r=jonathanbrouwer
Port `rustc_insignificant_dtor` r? @JonathanBrouwer Second commit removes it from an impl in std. I looked, and I really think it had no effect in the past. We only look for this attr on ADTs...
2 parents 12f0ef7 + 9d6e120 commit 7cb4501

7 files changed

Lines changed: 23 additions & 5 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
@@ -272,6 +272,7 @@ attribute_parsers!(
272272
Single<WithoutArgs<RustcEvaluateWhereClausesParser>>,
273273
Single<WithoutArgs<RustcHasIncoherentInherentImplsParser>>,
274274
Single<WithoutArgs<RustcHiddenTypeOfOpaquesParser>>,
275+
Single<WithoutArgs<RustcInsignificantDtorParser>>,
275276
Single<WithoutArgs<RustcIntrinsicConstStableIndirectParser>>,
276277
Single<WithoutArgs<RustcIntrinsicParser>>,
277278
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
@@ -1126,6 +1126,9 @@ pub enum AttributeKind {
11261126
/// Represents `#[rustc_if_this_changed]`
11271127
RustcIfThisChanged(Span, Option<Symbol>),
11281128

1129+
/// Represents `#[rustc_insignificant_dtor]`
1130+
RustcInsignificantDtor,
1131+
11291132
/// Represents `#[rustc_intrinsic]`
11301133
RustcIntrinsic,
11311134

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ impl AttributeKind {
120120
RustcHasIncoherentInherentImpls => Yes,
121121
RustcHiddenTypeOfOpaques => No,
122122
RustcIfThisChanged(..) => No,
123+
RustcInsignificantDtor => Yes,
123124
RustcIntrinsic => Yes,
124125
RustcIntrinsicConstStableIndirect => No,
125126
RustcLayout(..) => No,

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
315315
| AttributeKind::RustcHasIncoherentInherentImpls
316316
| AttributeKind::RustcHiddenTypeOfOpaques
317317
| AttributeKind::RustcIfThisChanged(..)
318+
| AttributeKind::RustcInsignificantDtor
318319
| AttributeKind::RustcIntrinsic
319320
| AttributeKind::RustcIntrinsicConstStableIndirect
320321
| AttributeKind::RustcLayout(..)
@@ -390,7 +391,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
390391
| sym::default_lib_allocator
391392
| sym::rustc_diagnostic_item
392393
| sym::rustc_no_mir_inline
393-
| sym::rustc_insignificant_dtor
394394
| sym::rustc_nonnull_optimization_guaranteed
395395
| sym::rustc_inherit_overflow_checks
396396
| 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

library/alloc/src/ffi/c_str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ use crate::vec::Vec;
103103
/// and other memory errors.
104104
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone)]
105105
#[rustc_diagnostic_item = "cstring_type"]
106+
#[rustc_insignificant_dtor]
106107
#[stable(feature = "alloc_c_string", since = "1.64.0")]
107108
pub struct CString {
108109
// Invariant 1: the slice ends with a zero byte and has a length of at least one.
@@ -694,7 +695,6 @@ impl CString {
694695
// memory-unsafe code from working by accident. Inline
695696
// to prevent LLVM from optimizing it away in debug builds.
696697
#[stable(feature = "cstring_drop", since = "1.13.0")]
697-
#[rustc_insignificant_dtor]
698698
impl Drop for CString {
699699
#[inline]
700700
fn drop(&mut self) {

0 commit comments

Comments
 (0)