Skip to content

Commit cde8d92

Browse files
authored
Merge pull request rust-lang#19106 from ShoyuVanilla/issue-18682
fix: Resolve projection types before checking casts
2 parents b27a0f4 + bacc9df commit cde8d92

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/tools/rust-analyzer/crates/hir-ty/src/infer/cast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ enum PointerKind {
374374

375375
fn pointer_kind(ty: &Ty, table: &mut InferenceTable<'_>) -> Result<Option<PointerKind>, ()> {
376376
let ty = table.resolve_ty_shallow(ty);
377+
let ty = table.normalize_associated_types_in(ty);
377378

378379
if table.is_sized(&ty) {
379380
return Ok(Some(PointerKind::Thin));

src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/invalid_cast.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,4 +1129,39 @@ fn main() {
11291129
"#,
11301130
);
11311131
}
1132+
1133+
#[test]
1134+
fn regression_18682() {
1135+
check_diagnostics(
1136+
r#"
1137+
//- minicore: coerce_unsized
1138+
struct Flexible {
1139+
body: [u8],
1140+
}
1141+
1142+
trait Field {
1143+
type Type: ?Sized;
1144+
}
1145+
1146+
impl Field for Flexible {
1147+
type Type = [u8];
1148+
}
1149+
1150+
trait KnownLayout {
1151+
type MaybeUninit: ?Sized;
1152+
}
1153+
1154+
1155+
impl<T> KnownLayout for [T] {
1156+
type MaybeUninit = [T];
1157+
}
1158+
1159+
struct ZerocopyKnownLayoutMaybeUninit(<<Flexible as Field>::Type as KnownLayout>::MaybeUninit);
1160+
1161+
fn test(ptr: *mut [u8]) -> *mut ZerocopyKnownLayoutMaybeUninit {
1162+
ptr as *mut _
1163+
}
1164+
"#,
1165+
);
1166+
}
11321167
}

0 commit comments

Comments
 (0)