Change:
<!-- Thank you for finding an Internal Compiler Error! If possible, try to provide a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for how to create smaller examples. --glacier <!-- If you're using the stable version of the compiler, you should also check if the bug also exists in the beta or nightly versions. --: Note: you need a build with rustc debug assertions enabled! <!-- Include a backtrace in the code block by setting in your environment. E.g. . --<details<summary<strongBacktrace</strong</summary<p</p</details<!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
claim

Discussion:
// This is a thin pointer. Create a regular pointer type and give it the correct name. debug_assert_eq!( (thin_pointer_size, thin_pointer_align), <del> cx.size_and_align_of(ptr_type) </del> <ins> cx.size_and_align_of(ptr_type), "ptr_type={}, pointee_type={}", ptr_type, pointee_type, </ins> ); unsafe {

use super::CrateDebugContext; use rustc_hir::def_id::DefId; <del> use rustc_middle::ty::layout::LayoutOf; </del> <ins> use rustc_middle::ty::layout::{HasParamEnv, LayoutOf}; </ins> use rustc_middle::ty::{self, DefIdTree, Ty}; <del> use rustc_target::abi::Variants; </del> <ins> use tracing::trace; </ins> use crate::common::CodegenCx; use crate::llvm;

cx: &CodegenCx<'ll, 'tcx>, pointee_ty: Ty<'tcx>, ) -> Option<FatPtrKind> { <del> let layout = cx.layout_of(pointee_ty); </del> <ins> let pointee_tail_ty = cx.tcx.struct_tail_erasing_lifetimes(pointee_ty, cx.param_env()); let layout = cx.layout_of(pointee_tail_ty); trace!( "fat_pointer_kind: {:?} has layout {:?} (is_unsized? {})", pointee_tail_ty, layout, layout.is_unsized() ); </ins> if !layout.is_unsized() { return None; } <del> match *pointee_ty.kind() { </del> <ins> match *pointee_tail_ty.kind() { </ins> ty::Str | ty::Slice(_) => Some(FatPtrKind::Slice), ty::Dynamic(..) => Some(FatPtrKind::Dyn), <del> ty::Adt(..) | ty::Tuple(..) if matches!(layout.variants, Variants::Single { .. }) => { let last_field_index = layout.fields.count() - 1; debug_assert!( (0..last_field_index) .all(|field_index| { !layout.field(cx, field_index).is_unsized() }) ); let unsized_field = layout.field(cx, last_field_index); debug_assert!(unsized_field.is_unsized()); fat_pointer_kind(cx, unsized_field.ty) } </del> ty::Foreign(_) => { // Assert that pointers to foreign types really are thin: debug_assert_eq!( <del> cx.size_of(cx.tcx.mk_imm_ptr(pointee_ty)), </del> <ins> cx.size_of(cx.tcx.mk_imm_ptr(pointee_tail_ty)), </ins> cx.size_of(cx.tcx.mk_imm_ptr(cx.tcx.types.u8)) ); None

_ => { // For all other pointee types we should already have returned None // at the beginning of the function. <del> panic!("fat_pointer_kind() - Encountered unexpected `pointee_ty`: {:?}", pointee_ty) </del> <ins> panic!( "fat_pointer_kind() - Encountered unexpected `pointee_tail_ty`: {:?}", pointee_tail_ty ) </ins> } } }

<del> // build-pass // // compile-flags: -g --emit=llvm-ir -Zunstable-options -Csplit-debuginfo=unpacked // // Make sure that we don't explode with an error if we don't actually end up emitting any `dwo`s, // as would be the case if we don't actually codegen anything. #![crate_type="rlib"] </del>

<ins> // build-pass // // compile-flags: -g --emit=llvm-ir -Zunstable-options -Csplit-debuginfo=unpacked // // Make sure that we don't explode with an error if we don't actually end up emitting any `dwo`s, // as would be the case if we don't actually codegen anything. #![crate_type="rlib"] </ins>

<ins> // check-pass // compile-flags: -Cdebuginfo=2 // fixes issue #94149 #![allow(dead_code)] pub fn main() { let _ = Foo::<dyn FooTrait>::new(); } pub struct Foo<T: FooTrait + ?Sized> { base: FooBase, value: T, } impl<T: FooTrait + ?Sized> Foo<T> { pub fn new() -> Box<Foo<T>> { todo!() } } pub trait FooTrait {} pub struct FooBase { cls: Bar, } // Bar *must* be a fieldless enum pub enum Bar {} </ins>