diff --git a/crates/hir-ty/src/next_solver/interner.rs b/crates/hir-ty/src/next_solver/interner.rs index 2e52dcea6c5b..e77b77bf4a90 100644 --- a/crates/hir-ty/src/next_solver/interner.rs +++ b/crates/hir-ty/src/next_solver/interner.rs @@ -690,15 +690,10 @@ impl<'db> inherent::AdtDef> for AdtDef { interner: DbInterner<'db>, sizedness: SizedTraitKind, ) -> Option, Ty<'db>>> { - if self.is_struct() { - let tail_ty = self.all_field_tys(interner).skip_binder().into_iter().last()?; - - let constraint_ty = sizedness_constraint_for_ty(interner, sizedness, tail_ty)?; - - Some(EarlyBinder::bind(constraint_ty)) - } else { - None - } + let tail_ty = self.struct_tail_ty(interner)?; + tail_ty + .map_bound(|tail_ty| sizedness_constraint_for_ty(interner, sizedness, tail_ty)) + .transpose() } fn destructor( diff --git a/crates/hir-ty/src/next_solver/util.rs b/crates/hir-ty/src/next_solver/util.rs index 972c8e2da7b1..bc4b5fdbfc52 100644 --- a/crates/hir-ty/src/next_solver/util.rs +++ b/crates/hir-ty/src/next_solver/util.rs @@ -422,12 +422,10 @@ pub fn sizedness_constraint_for_ty<'db>( .next_back() .and_then(|ty| sizedness_constraint_for_ty(interner, sizedness, ty)), - Adt(adt, args) => { - let tail_ty = - EarlyBinder::bind(adt.all_field_tys(interner).skip_binder().into_iter().last()?) - .instantiate(interner, args); + Adt(adt, args) => adt.struct_tail_ty(interner).and_then(|tail_ty| { + let tail_ty = tail_ty.instantiate(interner, args); sizedness_constraint_for_ty(interner, sizedness, tail_ty) - } + }), Placeholder(..) | Bound(..) | Infer(..) => { panic!("unexpected type `{ty:?}` in sizedness_constraint_for_ty") diff --git a/crates/hir-ty/src/tests/method_resolution.rs b/crates/hir-ty/src/tests/method_resolution.rs index 274d33a211f0..c8ed8aa2584c 100644 --- a/crates/hir-ty/src/tests/method_resolution.rs +++ b/crates/hir-ty/src/tests/method_resolution.rs @@ -2229,3 +2229,32 @@ fn test(x: *mut u8) { "#, ); } + +#[test] +fn unsized_struct() { + check_types( + r#" +//- minicore: sized, phantom_data +use core::marker::PhantomData; + +const UI_DEV_CREATE: Ioctl = Ioctl(PhantomData); + +struct Ioctl(PhantomData); + +struct NoArgs([u8]); + +impl Ioctl { + fn ioctl(self) {} +} + +impl Ioctl { + fn ioctl(self) -> u32 { 0 } +} + +fn main() { + UI_DEV_CREATE.ioctl(); + // ^^^^^^^^^^^^^^^^^^^^^ u32 +} + "#, + ); +}