diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index 910402d5499fd..c5461471be8b1 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -654,7 +654,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ // Internal attributes: Type system related: // ========================================================================== - gated!(fundamental, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes, experimental!(fundamental)), + gated!(fundamental, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No, experimental!(fundamental)), gated!( may_dangle, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No, dropck_eyepatch, diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 843e4d41e001e..64f33c980f80b 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -1180,7 +1180,7 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AdtDef<'_> { } _ => bug!("{:?} is not an ADT", item.owner_id.def_id), }; - tcx.mk_adt_def(def_id.to_def_id(), kind, variants, repr, is_anonymous) + tcx.mk_adt_def(def_id, kind, variants, repr, is_anonymous) } fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef { diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 83b41e0540edf..3dfe88c327b28 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -1151,7 +1151,9 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { DefKind::Union => ty::AdtKind::Union, _ => bug!("get_adt_def called on a non-ADT {:?}", did), }; + let repr = self.root.tables.repr_options.get(self, item_id).unwrap().decode(self); + let flags = self.root.tables.adt_flags.get(self, item_id).unwrap().decode(self); let mut variants: Vec<_> = if let ty::AdtKind::Enum = adt_kind { self.root @@ -1174,12 +1176,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { variants.sort_by_key(|(idx, _)| *idx); - tcx.mk_adt_def( + tcx.mk_adt_def_from_flags( did, - adt_kind, variants.into_iter().map(|(_, variant)| variant).collect(), + flags, repr, - false, ) } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 209316ca20fdb..77aba3ce6da34 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1533,6 +1533,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { let tcx = self.tcx; let adt_def = tcx.adt_def(def_id); record!(self.tables.repr_options[def_id] <- adt_def.repr()); + record!(self.tables.adt_flags[def_id] <- adt_def.flags()); let params_in_repr = self.tcx.params_in_repr(def_id); record!(self.tables.params_in_repr[def_id] <- params_in_repr); diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 2a44b3423ae2f..eea548149ff9e 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -452,6 +452,7 @@ define_tables! { expn_that_defined: Table>, params_in_repr: Table>>, repr_options: Table>, + adt_flags: Table>, // `def_keys` and `def_path_hashes` represent a lazy version of a // `DefPathTable`. This allows us to avoid deserializing an entire // `DefPathTable` up front, since we may only ever use a few diff --git a/compiler/rustc_middle/src/ty/adt.rs b/compiler/rustc_middle/src/ty/adt.rs index 88ee32eae9529..ea8f3065d1638 100644 --- a/compiler/rustc_middle/src/ty/adt.rs +++ b/compiler/rustc_middle/src/ty/adt.rs @@ -9,7 +9,7 @@ use rustc_data_structures::stable_hasher::HashingControls; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_errors::ErrorGuaranteed; use rustc_hir::def::{CtorKind, DefKind, Res}; -use rustc_hir::def_id::DefId; +use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::{self as hir, LangItem}; use rustc_index::{IndexSlice, IndexVec}; use rustc_macros::{HashStable, TyDecodable, TyEncodable}; @@ -253,15 +253,25 @@ impl Into for AdtKind { } impl AdtDefData { + pub(super) fn new_from_flags( + did: DefId, + variants: IndexVec, + flags: AdtFlags, + repr: ReprOptions, + ) -> Self { + AdtDefData { did, variants, flags, repr } + } + /// Creates a new `AdtDefData`. pub(super) fn new( tcx: TyCtxt<'_>, - did: DefId, + did: LocalDefId, kind: AdtKind, variants: IndexVec, repr: ReprOptions, is_anonymous: bool, ) -> Self { + let did = did.to_def_id(); debug!( "AdtDef::new({:?}, {:?}, {:?}, {:?}, {:?})", did, kind, variants, repr, is_anonymous diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index aee42bfe3aaca..2b2caa642150b 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1408,9 +1408,19 @@ impl<'tcx> TyCtxt<'tcx> { self.arena.alloc(Steal::new(promoted)) } - pub fn mk_adt_def( + pub fn mk_adt_def_from_flags( self, did: DefId, + variants: IndexVec, + flags: ty::AdtFlags, + repr: ReprOptions, + ) -> ty::AdtDef<'tcx> { + self.mk_adt_def_from_data(ty::AdtDefData::new_from_flags(did, variants, flags, repr)) + } + + pub fn mk_adt_def( + self, + did: LocalDefId, kind: AdtKind, variants: IndexVec, repr: ReprOptions, diff --git a/compiler/rustc_middle/src/ty/parameterized.rs b/compiler/rustc_middle/src/ty/parameterized.rs index f394b3c990ce5..95756d7aa60ae 100644 --- a/compiler/rustc_middle/src/ty/parameterized.rs +++ b/compiler/rustc_middle/src/ty/parameterized.rs @@ -63,6 +63,7 @@ trivially_parameterized_over_tcx! { crate::middle::lib_features::FeatureStability, crate::middle::resolve_bound_vars::ObjectLifetimeDefault, crate::mir::ConstQualifs, + ty::AdtFlags, ty::AssocItemContainer, ty::Asyncness, ty::DeducedParamAttrs,