Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #19413 from ShoyuVanilla/issue-19399
fix: Properly calculate the layouts of tuple ptrs whose last fields are DST
Lukas Wirth 2025-03-22
parent 32fa60f · parent b07a76d · commit dab1329
-rw-r--r--crates/hir-ty/src/layout.rs9
-rw-r--r--crates/hir-ty/src/layout/tests.rs10
2 files changed, 19 insertions, 0 deletions
diff --git a/crates/hir-ty/src/layout.rs b/crates/hir-ty/src/layout.rs
index 0cb868d273..81aa16bfdc 100644
--- a/crates/hir-ty/src/layout.rs
+++ b/crates/hir-ty/src/layout.rs
@@ -388,6 +388,15 @@ fn struct_tail_erasing_lifetimes(db: &dyn HirDatabase, pointee: Ty) -> Ty {
None => pointee,
}
}
+ TyKind::Tuple(_, subst) => {
+ if let Some(last_field_ty) =
+ subst.iter(Interner).last().and_then(|arg| arg.ty(Interner))
+ {
+ struct_tail_erasing_lifetimes(db, last_field_ty.clone())
+ } else {
+ pointee
+ }
+ }
_ => pointee,
}
}
diff --git a/crates/hir-ty/src/layout/tests.rs b/crates/hir-ty/src/layout/tests.rs
index f671b30380..aac4e94ee3 100644
--- a/crates/hir-ty/src/layout/tests.rs
+++ b/crates/hir-ty/src/layout/tests.rs
@@ -469,6 +469,16 @@ fn tuple() {
}
#[test]
+fn tuple_ptr_with_dst_tail() {
+ size_and_align!(
+ struct Goal(*const ([u8],));
+ );
+ size_and_align!(
+ struct Goal(*const (u128, [u8]));
+ );
+}
+
+#[test]
fn non_zero_and_non_null() {
size_and_align! {
minicore: non_zero, non_null, option;