diff options
| author | Shoyu Vanilla <modulo641@gmail.com> | 2025-02-07 09:50:03 +0900 |
|---|---|---|
| committer | Shoyu Vanilla <modulo641@gmail.com> | 2025-02-07 09:51:32 +0900 |
| commit | bacc9dfa4b2f85a002e491a0592bf61b01d4caf4 (patch) | |
| tree | 548aae6778e130fd9c98a22381bdaa165434f8fa | |
| parent | d18dd4dc18f544b79152579d4e27f3969602cf5e (diff) | |
| download | rust-bacc9dfa4b2f85a002e491a0592bf61b01d4caf4.tar.gz rust-bacc9dfa4b2f85a002e491a0592bf61b01d4caf4.zip | |
fix: Resolve projection types before checking casts
| -rw-r--r-- | src/tools/rust-analyzer/crates/hir-ty/src/infer/cast.rs | 1 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/invalid_cast.rs | 35 |
2 files changed, 36 insertions, 0 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/infer/cast.rs b/src/tools/rust-analyzer/crates/hir-ty/src/infer/cast.rs index 21d0be6ed5f..eb193686e96 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/infer/cast.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/infer/cast.rs @@ -374,6 +374,7 @@ enum PointerKind { fn pointer_kind(ty: &Ty, table: &mut InferenceTable<'_>) -> Result<Option<PointerKind>, ()> { 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/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/invalid_cast.rs b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/invalid_cast.rs index c7cdcf49820..5730508436d 100644 --- a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/invalid_cast.rs +++ b/src/tools/rust-analyzer/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<T> KnownLayout for [T] { + type MaybeUninit = [T]; +} + +struct ZerocopyKnownLayoutMaybeUninit(<<Flexible as Field>::Type as KnownLayout>::MaybeUninit); + +fn test(ptr: *mut [u8]) -> *mut ZerocopyKnownLayoutMaybeUninit { + ptr as *mut _ +} +"#, + ); + } } |
