From 8b4995aad878f6b5d3f322dc161e6b772541151c Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 20 Nov 2024 02:46:56 +0000 Subject: [PATCH] Make PointerLike opt-in as a trait --- alloc/src/boxed.rs | 6 ++++++ alloc/src/lib.rs | 1 + core/src/marker.rs | 12 ++++++++++++ 3 files changed, 19 insertions(+) diff --git a/alloc/src/boxed.rs b/alloc/src/boxed.rs index ac3e4626ee5eb..ee60ec0fbacbe 100644 --- a/alloc/src/boxed.rs +++ b/alloc/src/boxed.rs @@ -191,6 +191,8 @@ use core::error::{self, Error}; use core::fmt; use core::future::Future; use core::hash::{Hash, Hasher}; +#[cfg(not(bootstrap))] +use core::marker::PointerLike; use core::marker::{Tuple, Unsize}; use core::mem::{self, SizedTypeProperties}; use core::ops::{ @@ -2131,3 +2133,7 @@ impl Error for Box { Error::provide(&**self, request); } } + +#[cfg(not(bootstrap))] +#[unstable(feature = "pointer_like_trait", issue = "none")] +impl PointerLike for Box {} diff --git a/alloc/src/lib.rs b/alloc/src/lib.rs index 7839fe04b8d03..041ff37897f05 100644 --- a/alloc/src/lib.rs +++ b/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)] diff --git a/core/src/marker.rs b/core/src/marker.rs index 1c5c58d64a2b2..c8ea52a1fb0b4 100644 --- a/core/src/marker.rs +++ b/core/src/marker.rs @@ -981,6 +981,18 @@ pub trait Tuple {} )] pub trait PointerLike {} +#[cfg(not(bootstrap))] +marker_impls! { + #[unstable(feature = "pointer_like_trait", issue = "none")] + PointerLike for + usize, + {T} &T, + {T} &mut T, + {T} *const T, + {T} *mut T, + {T: PointerLike} crate::pin::Pin, +} + /// A marker for types which can be used as types of `const` generic parameters. /// /// These types must have a proper equivalence relation (`Eq`) and it must be automatically