about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-01-04 06:28:05 +0000
committerbors <bors@rust-lang.org>2023-01-04 06:28:05 +0000
commitddad1e1f15f77074738bb3d7fb7688a9177b6450 (patch)
tree805c0c24682e69fc40fba1ff446aa1a8a8f8d6ee /src/test
parentc361616c3ca3e3e3069dbdf90557181233387444 (diff)
parenta5d39cf290d9762d982b6930f10fb4dd34119c3f (diff)
downloadrust-ddad1e1f15f77074738bb3d7fb7688a9177b6450.tar.gz
rust-ddad1e1f15f77074738bb3d7fb7688a9177b6450.zip
Auto merge of #104376 - compiler-errors:thin-metadata-implies-thin-ptr, r=wesleywiser
layout_of: `T: Thin` implies `sizeof(&T) == sizeof(usize)`

Use the `<T as Pointee>::Metadata` associated type to calculate the layout of a pointee's metadata, instead of hard-coding rules about certain types.

Maybe this approach is overkill -- we could instead hard-code this approach as a fallback, with the matching on `Slice`/`Dynamic`/etc. happening first

Fixes this issue here https://github.com/rust-lang/rust/pull/104338#issuecomment-1312595844 .. But is also useful with transmutes, for example, given the UI test I added below.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/layout/thin-meta-implies-thin-ptr.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/test/ui/layout/thin-meta-implies-thin-ptr.rs b/src/test/ui/layout/thin-meta-implies-thin-ptr.rs
new file mode 100644
index 00000000000..972579ea8be
--- /dev/null
+++ b/src/test/ui/layout/thin-meta-implies-thin-ptr.rs
@@ -0,0 +1,11 @@
+// check-pass
+
+#![feature(ptr_metadata)]
+
+use std::ptr::Thin;
+
+fn main() {}
+
+fn foo<T: ?Sized + Thin>(t: *const T) -> *const () {
+    unsafe { std::mem::transmute(t) }
+}