Skip to content

Commit

Permalink
fix: Resolve projection types before checking casts
Browse files Browse the repository at this point in the history
  • Loading branch information
ShoyuVanilla committed Feb 7, 2025
1 parent d18dd4d commit bacc9df
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/tools/rust-analyzer/crates/hir-ty/src/infer/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 _
}
"#,
);
}
}

0 comments on commit bacc9df

Please sign in to comment.