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...
This commit is contained in:
commit
7cb4501916
7 changed files with 23 additions and 5 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -272,6 +272,7 @@ attribute_parsers!(
|
|||
Single<WithoutArgs<RustcEvaluateWhereClausesParser>>,
|
||||
Single<WithoutArgs<RustcHasIncoherentInherentImplsParser>>,
|
||||
Single<WithoutArgs<RustcHiddenTypeOfOpaquesParser>>,
|
||||
Single<WithoutArgs<RustcInsignificantDtorParser>>,
|
||||
Single<WithoutArgs<RustcIntrinsicConstStableIndirectParser>>,
|
||||
Single<WithoutArgs<RustcIntrinsicParser>>,
|
||||
Single<WithoutArgs<RustcLintOptTyParser>>,
|
||||
|
|
|
|||
|
|
@ -1126,6 +1126,9 @@ pub enum AttributeKind {
|
|||
/// Represents `#[rustc_if_this_changed]`
|
||||
RustcIfThisChanged(Span, Option<Symbol>),
|
||||
|
||||
/// Represents `#[rustc_insignificant_dtor]`
|
||||
RustcInsignificantDtor,
|
||||
|
||||
/// Represents `#[rustc_intrinsic]`
|
||||
RustcIntrinsic,
|
||||
|
||||
|
|
|
|||
|
|
@ -120,6 +120,7 @@ impl AttributeKind {
|
|||
RustcHasIncoherentInherentImpls => Yes,
|
||||
RustcHiddenTypeOfOpaques => No,
|
||||
RustcIfThisChanged(..) => No,
|
||||
RustcInsignificantDtor => Yes,
|
||||
RustcIntrinsic => Yes,
|
||||
RustcIntrinsicConstStableIndirect => No,
|
||||
RustcLayout(..) => No,
|
||||
|
|
|
|||
|
|
@ -315,6 +315,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||
| AttributeKind::RustcHasIncoherentInherentImpls
|
||||
| AttributeKind::RustcHiddenTypeOfOpaques
|
||||
| AttributeKind::RustcIfThisChanged(..)
|
||||
| AttributeKind::RustcInsignificantDtor
|
||||
| AttributeKind::RustcIntrinsic
|
||||
| AttributeKind::RustcIntrinsicConstStableIndirect
|
||||
| AttributeKind::RustcLayout(..)
|
||||
|
|
@ -390,7 +391,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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -103,6 +103,7 @@ use crate::vec::Vec;
|
|||
/// and other memory errors.
|
||||
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone)]
|
||||
#[rustc_diagnostic_item = "cstring_type"]
|
||||
#[rustc_insignificant_dtor]
|
||||
#[stable(feature = "alloc_c_string", since = "1.64.0")]
|
||||
pub struct CString {
|
||||
// Invariant 1: the slice ends with a zero byte and has a length of at least one.
|
||||
|
|
@ -694,7 +695,6 @@ impl CString {
|
|||
// memory-unsafe code from working by accident. Inline
|
||||
// to prevent LLVM from optimizing it away in debug builds.
|
||||
#[stable(feature = "cstring_drop", since = "1.13.0")]
|
||||
#[rustc_insignificant_dtor]
|
||||
impl Drop for CString {
|
||||
#[inline]
|
||||
fn drop(&mut self) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue