Auto merge of #103578 - petrochenkov:nofict, r=nagisa
Unreserve braced enum variants in value namespace With this PR braced enum variants (`enum E { V { /*...*/ } }`) no longer take a slot in value namespace, so the special case mentioned in the note in https://github.com/rust-lang/rfcs/blob/master/text/1506-adt-kinds.md#braced-structs is removed. Report - https://github.com/rust-lang/rust/pull/103578#issuecomment-1292594900.
This commit is contained in:
commit
b7463e8bdb
71 changed files with 364 additions and 642 deletions
|
@ -1165,7 +1165,7 @@ fn check_enum<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) {
|
|||
}
|
||||
|
||||
if def.repr().int.is_none() {
|
||||
let is_unit = |var: &ty::VariantDef| matches!(var.ctor_kind, CtorKind::Const);
|
||||
let is_unit = |var: &ty::VariantDef| matches!(var.ctor_kind(), Some(CtorKind::Const));
|
||||
let has_disr = |var: &ty::VariantDef| matches!(var.discr, ty::VariantDiscr::Explicit(_));
|
||||
|
||||
let has_non_units = def.variants().iter().any(|var| !is_unit(var));
|
||||
|
|
|
@ -24,7 +24,6 @@ use rustc_data_structures::captures::Captures;
|
|||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed, StashKey};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::CtorKind;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE};
|
||||
use rustc_hir::intravisit::{self, Visitor};
|
||||
use rustc_hir::weak_lang_items::WEAK_LANG_ITEMS;
|
||||
|
@ -794,7 +793,7 @@ fn convert_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId) {
|
|||
|
||||
// Convert the ctor, if any. This also registers the variant as
|
||||
// an item.
|
||||
if let Some(ctor_def_id) = variant.ctor_def_id {
|
||||
if let Some(ctor_def_id) = variant.ctor_def_id() {
|
||||
convert_variant_ctor(tcx, ctor_def_id.expect_local());
|
||||
}
|
||||
}
|
||||
|
@ -803,7 +802,6 @@ fn convert_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId) {
|
|||
fn convert_variant(
|
||||
tcx: TyCtxt<'_>,
|
||||
variant_did: Option<LocalDefId>,
|
||||
ctor_did: Option<LocalDefId>,
|
||||
ident: Ident,
|
||||
discr: ty::VariantDiscr,
|
||||
def: &hir::VariantData<'_>,
|
||||
|
@ -840,10 +838,9 @@ fn convert_variant(
|
|||
ty::VariantDef::new(
|
||||
ident.name,
|
||||
variant_did.map(LocalDefId::to_def_id),
|
||||
ctor_did.map(LocalDefId::to_def_id),
|
||||
def.ctor().map(|(kind, _, def_id)| (kind, def_id.to_def_id())),
|
||||
discr,
|
||||
fields,
|
||||
CtorKind::from_hir(def),
|
||||
adt_kind,
|
||||
parent_did.to_def_id(),
|
||||
recovered,
|
||||
|
@ -882,7 +879,6 @@ fn adt_def<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::AdtDef<'tcx> {
|
|||
convert_variant(
|
||||
tcx,
|
||||
Some(v.def_id),
|
||||
v.data.ctor_def_id(),
|
||||
v.ident,
|
||||
discr,
|
||||
&v.data,
|
||||
|
@ -894,35 +890,23 @@ fn adt_def<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::AdtDef<'tcx> {
|
|||
|
||||
(AdtKind::Enum, variants)
|
||||
}
|
||||
ItemKind::Struct(ref def, _) => {
|
||||
ItemKind::Struct(ref def, _) | ItemKind::Union(ref def, _) => {
|
||||
let adt_kind = match item.kind {
|
||||
ItemKind::Struct(..) => AdtKind::Struct,
|
||||
_ => AdtKind::Union,
|
||||
};
|
||||
let variants = std::iter::once(convert_variant(
|
||||
tcx,
|
||||
None,
|
||||
def.ctor_def_id(),
|
||||
item.ident,
|
||||
ty::VariantDiscr::Relative(0),
|
||||
def,
|
||||
AdtKind::Struct,
|
||||
adt_kind,
|
||||
def_id,
|
||||
))
|
||||
.collect();
|
||||
|
||||
(AdtKind::Struct, variants)
|
||||
}
|
||||
ItemKind::Union(ref def, _) => {
|
||||
let variants = std::iter::once(convert_variant(
|
||||
tcx,
|
||||
None,
|
||||
def.ctor_def_id(),
|
||||
item.ident,
|
||||
ty::VariantDiscr::Relative(0),
|
||||
def,
|
||||
AdtKind::Union,
|
||||
def_id,
|
||||
))
|
||||
.collect();
|
||||
|
||||
(AdtKind::Union, variants)
|
||||
(adt_kind, variants)
|
||||
}
|
||||
_ => bug!(),
|
||||
};
|
||||
|
@ -1171,7 +1155,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
|
|||
compute_sig_of_foreign_fn_decl(tcx, def_id.to_def_id(), fn_decl, abi)
|
||||
}
|
||||
|
||||
Ctor(data) | Variant(hir::Variant { data, .. }) if data.ctor_hir_id().is_some() => {
|
||||
Ctor(data) | Variant(hir::Variant { data, .. }) if data.ctor().is_some() => {
|
||||
let ty = tcx.type_of(tcx.hir().get_parent_item(hir_id));
|
||||
let inputs = data.fields().iter().map(|f| tcx.type_of(f.def_id));
|
||||
ty::Binder::dummy(tcx.mk_fn_sig(
|
||||
|
|
|
@ -72,8 +72,8 @@ pub fn add_constraints_from_crate<'a, 'tcx>(
|
|||
|
||||
let adt = tcx.adt_def(def_id);
|
||||
for variant in adt.variants() {
|
||||
if let Some(ctor) = variant.ctor_def_id {
|
||||
constraint_cx.build_constraints_for_item(ctor.expect_local());
|
||||
if let Some(ctor_def_id) = variant.ctor_def_id() {
|
||||
constraint_cx.build_constraints_for_item(ctor_def_id.expect_local());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,8 +91,8 @@ pub fn determine_parameters_to_be_inferred<'a, 'tcx>(
|
|||
|
||||
let adt = tcx.adt_def(def_id);
|
||||
for variant in adt.variants() {
|
||||
if let Some(ctor) = variant.ctor_def_id {
|
||||
terms_cx.add_inferreds_for_item(ctor.expect_local());
|
||||
if let Some(ctor_def_id) = variant.ctor_def_id() {
|
||||
terms_cx.add_inferreds_for_item(ctor_def_id.expect_local());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue