Change:
<!-- [31mICE[0m: Rustc '' 'thread 'rustc' panicked at 'attempted .defid() on invalid res: Err'', 'thread 'rustc' panicked at 'attempted .defid() on invalid res: Err'' File: --auto-reduced (treereduce-rust): &lt;details&lt;summary&lt;strongoriginal code&lt;/strong&lt;/summary&lt;poriginal: </p</detailsVersion information ` Command: <!-- Include a backtrace in the code block by setting in your environment. E.g. . --<details<summary<strongProgram output</strong</summary<p</p</details<!-- query stack: [adtdef] computing ADT definition for [inferredoutlivescrate] computing the inferred outlives predicates for items in this crate [inferredoutlivesof] computing inferred outlives predicates of [predicatesdefinedon] computing predicates of [predicatesof] computing predicates of [collectmoditem_types] collecting item types in top-level module [analysis] running analysis passes on this crate --
Lol, what's up with all the unnecessary whitespace in your treereduce reproducers? Could you teach treereduce to reduce that? :P
Also I would probably place the MCVE from into the issue description and the original reproducer inside a (or omit it entirely) since this GitHub issue is super hard to read imo
<!-- [31mICE[0m: Rustc '' 'thread 'rustc' panicked at 'attempted .defid() on invalid res: PrimTy(Uint(Usize))'', 'thread 'rustc' panicked at 'attempted .defid() on invalid res: PrimTy(Uint(Usize))'' File: --auto-reduced (treereduce-rust): original: Version information ` Command: <!-- Include a backtrace in the code block by setting in your environment. E.g. . --<details<summary<strongProgram output</strong</summary<p</p</details<!-- query stack: [adtdef] computing ADT definition for [typeof] computing type of [collectmoditem_types] collecting item types in top-level module [analysis] running analysis passes on this crate --
im actually running rustfmt after reducing before generating the report, but treereduce sometimes slighlty misreduces the code (e.g. to or sth, so that rustfmt bails out due to syntax error and no longer squashes empty lines :/ Also likely to encounter code that rustfmt does not know about yet, sometimes it also just removes the part that would ICE lol. I can see if I can add some kind of self-coded cleanup after rustfmt even.
Right now the report is generated fully automatic, the "reduced" mvce is never put into details, the one only if its bigger than X lines, also the should match the mvce imo, mmh
All of the examples in here no longer ICE so I'm pretty sure got this too

Discussion:
ItemId { owner_id: self.owner_id } } <ins> /// Check if this is an [`ItemKind::Enum`], [`ItemKind::Struct`] or /// [`ItemKind::Union`]. pub fn is_adt(&self) -> bool { matches!(self.kind, ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..)) } </ins> expect_methods_self_kind! { expect_extern_crate, Option<Symbol>, ItemKind::ExternCrate(s), *s;

hir_analysis_invalid_union_field_sugg = wrap the field type in `ManuallyDrop<...>` <ins> hir_analysis_invalid_unnamed_field_ty = unnamed fields can only have struct or union types </ins> hir_analysis_late_bound_const_in_apit = `impl Trait` can only mention const parameters from an fn or impl .label = const parameter declared here

for field in variant.fields.iter().filter(|f| f.is_unnamed()) { let field_ty = tcx.type_of(field.did).instantiate_identity(); if let Some(adt) = field_ty.ty_adt_def() <del> && !adt.is_anonymous() && !adt.repr().c() </del> <ins> && !adt.is_enum() </ins> { <del> let field_ty_span = tcx.def_span(adt.did()); tcx.dcx().emit_err(errors::UnnamedFieldsRepr::FieldMissingReprC { span: tcx.def_span(field.did), field_ty_span, field_ty, field_adt_kind: adt.descr(), sugg_span: field_ty_span.shrink_to_lo(), }); </del> <ins> if !adt.is_anonymous() && !adt.repr().c() { let field_ty_span = tcx.def_span(adt.did()); tcx.dcx().emit_err(errors::UnnamedFieldsRepr::FieldMissingReprC { span: tcx.def_span(field.did), field_ty_span, field_ty, field_adt_kind: adt.descr(), sugg_span: field_ty_span.shrink_to_lo(), }); } } else { tcx.dcx().emit_err(errors::InvalidUnnamedFieldTy { span: tcx.def_span(field.did) }); </ins> } } }

} } hir::TyKind::Path(hir::QPath::Resolved(_, hir::Path { res, .. })) => { <del> self.check_field_in_nested_adt(self.tcx.adt_def(res.def_id()), field.span); </del> <ins> // If this is a direct path to an ADT, we can check it // If this is a type alias or non-ADT, `check_unnamed_fields` should verify it if let Some(def_id) = res.opt_def_id() && let Some(local) = def_id.as_local() && let Node::Item(item) = self.tcx.hir_node_by_def_id(local) && item.is_adt() { self.check_field_in_nested_adt(self.tcx.adt_def(def_id), field.span); } </ins> } // Abort due to errors (there must be an error if an unnamed field //  has any type kind other than an anonymous adt or a named adt)

} #[derive(Diagnostic)] <ins> #[diag(hir_analysis_invalid_unnamed_field_ty)] pub struct InvalidUnnamedFieldTy { #[primary_span] pub span: Span, } #[derive(Diagnostic)] </ins> #[diag(hir_analysis_return_type_notation_on_non_rpitit)] pub(crate) struct ReturnTypeNotationOnNonRpitit<'tcx> { #[primary_span]

<ins> #[repr(C)] pub struct GoodStruct(()); pub struct BadStruct(()); pub enum BadEnum { A, B, } #[repr(C)] pub enum BadEnum2 { A, B, } pub type GoodAlias = GoodStruct; pub type BadAlias = i32; </ins>

<ins> //@ aux-build:dep.rs // test for #121151 #![allow(incomplete_features)] #![feature(unnamed_fields)] extern crate dep; #[repr(C)] struct A { a: u8, } enum BadEnum { A, B, } #[repr(C)] enum BadEnum2 { A, B, } type MyStruct = A; type MyI32 = i32; #[repr(C)] struct L { _: i32, //~ ERROR unnamed fields can only have struct or union types _: MyI32, //~ ERROR unnamed fields can only have struct or union types _: BadEnum, //~ ERROR unnamed fields can only have struct or union types _: BadEnum2, //~ ERROR unnamed fields can only have struct or union types _: MyStruct, _: dep::BadStruct, //~ ERROR named type of unnamed field must have `#[repr(C)]` representation _: dep::BadEnum, //~ ERROR unnamed fields can only have struct or union types _: dep::BadEnum2, //~ ERROR unnamed fields can only have struct or union types _: dep::BadAlias, //~ ERROR unnamed fields can only have struct or union types _: dep::GoodAlias, _: dep::GoodStruct, } fn main() {} </ins>

<ins> error: unnamed fields can only have struct or union types --> $DIR/restrict_type_hir.rs:31:5 | LL |     _: i32, |     ^^^^^^ error: unnamed fields can only have struct or union types --> $DIR/restrict_type_hir.rs:32:5 | LL |     _: MyI32, |     ^^^^^^^^ error: unnamed fields can only have struct or union types --> $DIR/restrict_type_hir.rs:33:5 | LL |     _: BadEnum, |     ^^^^^^^^^^ error: unnamed fields can only have struct or union types --> $DIR/restrict_type_hir.rs:34:5 | LL |     _: BadEnum2, |     ^^^^^^^^^^^ error: named type of unnamed field must have `#[repr(C)]` representation --> $DIR/restrict_type_hir.rs:36:5 | LL |     _: dep::BadStruct, |     ^^^^^^^^^^^^^^^^^ unnamed field defined here | ::: $DIR/auxiliary/dep.rs:4:1 | LL | pub struct BadStruct(()); | -------------------- `BadStruct` defined here | help: add `#[repr(C)]` to this struct --> $DIR/auxiliary/dep.rs:4:1 | LL + #[repr(C)] LL | pub struct BadStruct(()); | error: unnamed fields can only have struct or union types --> $DIR/restrict_type_hir.rs:37:5 | LL |     _: dep::BadEnum, |     ^^^^^^^^^^^^^^^ error: unnamed fields can only have struct or union types --> $DIR/restrict_type_hir.rs:38:5 | LL |     _: dep::BadEnum2, |     ^^^^^^^^^^^^^^^^ error: unnamed fields can only have struct or union types --> $DIR/restrict_type_hir.rs:39:5 | LL |     _: dep::BadAlias, |     ^^^^^^^^^^^^^^^^ error: aborting due to 8 previous errors </ins>