Skip to content

Commit ba67f0d

Browse files
Rollup merge of rust-lang#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 bcba606 + 071935e commit ba67f0d

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

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

728741
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
@@ -265,6 +265,7 @@ attribute_parsers!(
265265
Single<WithoutArgs<RustcEffectiveVisibilityParser>>,
266266
Single<WithoutArgs<RustcHasIncoherentInherentImplsParser>>,
267267
Single<WithoutArgs<RustcHiddenTypeOfOpaquesParser>>,
268+
Single<WithoutArgs<RustcInsignificantDtorParser>>,
268269
Single<WithoutArgs<RustcLintOptTyParser>>,
269270
Single<WithoutArgs<RustcLintQueryInstabilityParser>>,
270271
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(..)
@@ -384,7 +385,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
384385
| sym::default_lib_allocator
385386
| sym::rustc_diagnostic_item
386387
| sym::rustc_no_mir_inline
387-
| sym::rustc_insignificant_dtor
388388
| sym::rustc_nonnull_optimization_guaranteed
389389
| sym::rustc_intrinsic
390390
| 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

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)