diff --git a/crates/hir-ty/src/infer/cast.rs b/crates/hir-ty/src/infer/cast.rs index 21d0be6ed5f7..eb193686e967 100644 --- a/crates/hir-ty/src/infer/cast.rs +++ b/crates/hir-ty/src/infer/cast.rs @@ -374,6 +374,7 @@ enum PointerKind { fn pointer_kind(ty: &Ty, table: &mut InferenceTable<'_>) -> Result, ()> { let ty = table.resolve_ty_shallow(ty); + let ty = table.normalize_associated_types_in(ty); if table.is_sized(&ty) { return Ok(Some(PointerKind::Thin)); diff --git a/crates/ide-diagnostics/src/handlers/invalid_cast.rs b/crates/ide-diagnostics/src/handlers/invalid_cast.rs index c7cdcf498202..5730508436d2 100644 --- a/crates/ide-diagnostics/src/handlers/invalid_cast.rs +++ b/crates/ide-diagnostics/src/handlers/invalid_cast.rs @@ -1129,4 +1129,39 @@ fn main() { "#, ); } + + #[test] + fn regression_18682() { + check_diagnostics( + r#" +//- minicore: coerce_unsized +struct Flexible { + body: [u8], +} + +trait Field { + type Type: ?Sized; +} + +impl Field for Flexible { + type Type = [u8]; +} + +trait KnownLayout { + type MaybeUninit: ?Sized; +} + + +impl KnownLayout for [T] { + type MaybeUninit = [T]; +} + +struct ZerocopyKnownLayoutMaybeUninit(<::Type as KnownLayout>::MaybeUninit); + +fn test(ptr: *mut [u8]) -> *mut ZerocopyKnownLayoutMaybeUninit { + ptr as *mut _ +} +"#, + ); + } }