about summary refs log tree commit diff
path: root/library/alloc/src/lib.rs
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-11-20 20:10:13 +0100
committerGitHub <noreply@github.com>2024-11-20 20:10:13 +0100
commitfbed195b4df1a21aee835e68efa88e8f4c4e0d4a (patch)
treeae03424afdc87650c5c89f5d417674da47b88f06 /library/alloc/src/lib.rs
parent7fc2b337229dfb4bc2e410317af271c1b8dbfe6b (diff)
parent228068bc6efb16f359b5318e66fa789c2f58ce60 (diff)
downloadrust-fbed195b4df1a21aee835e68efa88e8f4c4e0d4a.tar.gz
rust-fbed195b4df1a21aee835e68efa88e8f4c4e0d4a.zip
Rollup merge of #133226 - compiler-errors:opt-in-pointer-like, r=lcnr
Make `PointerLike` opt-in instead of built-in

The `PointerLike` trait currently is a built-in trait that computes the layout of the type. This is a bit problematic, because types implement this trait automatically. Since this can be broken due to semver-compatible changes to a type's layout, this is undesirable. Also, calling `layout_of` in the trait system also causes cycles.

This PR makes the trait implemented via regular impls, and adds additional validation on top to make sure that those impls are valid. This could eventually be `derive()`d for custom smart pointers, and we can trust *that* as a semver promise rather than risking library authors accidentally breaking it.

On the other hand, we may never expose `PointerLike`, but at least now the implementation doesn't invoke `layout_of` which could cause ICEs or cause cycles.

Right now for a `PointerLike` impl to be valid, it must be an ADT that is `repr(transparent)` and the non-1zst field needs to implement `PointerLike`. There are also some primitive impls for `&T`/ `&mut T`/`*const T`/`*mut T`/`Box<T>`.
Diffstat (limited to 'library/alloc/src/lib.rs')
-rw-r--r--library/alloc/src/lib.rs1
1 files changed, 1 insertions, 0 deletions
diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs
index 7839fe04b8d..041ff37897f 100644
--- a/library/alloc/src/lib.rs
+++ b/library/alloc/src/lib.rs
@@ -136,6 +136,7 @@
 #![feature(panic_internals)]
 #![feature(pattern)]
 #![feature(pin_coerce_unsized_trait)]
+#![feature(pointer_like_trait)]
 #![feature(ptr_internals)]
 #![feature(ptr_metadata)]
 #![feature(ptr_sub_ptr)]