Rollup merge of #121470 - clubby789:anon-struct-in-enum, r=fmease
Don't ICE on anonymous struct in enum variant Fixes #121446 Computing `adt_def` for the anon struct calls `adt_def` on the parent to find its repr. If the parent is a non-item (e.g. an enum variant) we should have already emitted at least one error, so we just use the repr of the anonymous struct to avoid an ICE. cc ``@frank-king``
This commit is contained in:
commit
4d5c4e5205
4 changed files with 41 additions and 1 deletions
|
@ -1025,7 +1025,15 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AdtDef<'_> {
|
|||
|
||||
let is_anonymous = item.ident.name == kw::Empty;
|
||||
let repr = if is_anonymous {
|
||||
tcx.adt_def(tcx.local_parent(def_id)).repr()
|
||||
let parent = tcx.local_parent(def_id);
|
||||
if let Node::Item(item) = tcx.hir_node_by_def_id(parent)
|
||||
&& item.is_struct_or_union()
|
||||
{
|
||||
tcx.adt_def(parent).repr()
|
||||
} else {
|
||||
tcx.dcx().span_delayed_bug(item.span, "anonymous field inside non struct/union");
|
||||
ty::ReprOptions::default()
|
||||
}
|
||||
} else {
|
||||
tcx.repr_options_of_def(def_id)
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue