2024-10-29 18:24:16 +00:00
|
|
|
//@ compile-flags: -Znext-solver -Cpanic=abort
|
|
|
|
|
//@ no-prefer-dynamic
|
|
|
|
|
|
|
|
|
|
#![crate_type = "rlib"]
|
2024-10-30 18:03:44 +00:00
|
|
|
#![feature(
|
|
|
|
|
no_core,
|
|
|
|
|
lang_items,
|
|
|
|
|
unboxed_closures,
|
|
|
|
|
auto_traits,
|
|
|
|
|
intrinsics,
|
|
|
|
|
rustc_attrs,
|
|
|
|
|
fundamental,
|
|
|
|
|
marker_trait_attr,
|
2024-11-19 17:08:52 +00:00
|
|
|
const_trait_impl,
|
2025-01-22 18:06:08 +00:00
|
|
|
const_destruct,
|
2024-10-30 18:03:44 +00:00
|
|
|
)]
|
2024-07-07 11:18:35 +00:00
|
|
|
#![allow(internal_features, incomplete_features)]
|
2023-10-15 08:51:54 +00:00
|
|
|
#![no_std]
|
|
|
|
|
#![no_core]
|
|
|
|
|
|
2025-02-27 23:30:16 +00:00
|
|
|
#[lang = "pointee_sized"]
|
|
|
|
|
pub trait PointeeSized {}
|
|
|
|
|
|
|
|
|
|
#[lang = "meta_sized"]
|
|
|
|
|
pub trait MetaSized: PointeeSized {}
|
|
|
|
|
|
2023-10-15 08:51:54 +00:00
|
|
|
#[lang = "sized"]
|
2025-02-27 23:30:16 +00:00
|
|
|
pub trait Sized: MetaSized {}
|
|
|
|
|
|
2023-10-15 08:51:54 +00:00
|
|
|
#[lang = "copy"]
|
2024-10-29 18:24:16 +00:00
|
|
|
pub trait Copy {}
|
|
|
|
|
|
|
|
|
|
impl Copy for bool {}
|
|
|
|
|
impl Copy for u8 {}
|
2025-01-22 18:06:08 +00:00
|
|
|
impl<T: PointeeSized> Copy for &T {}
|
2023-10-15 08:51:54 +00:00
|
|
|
|
|
|
|
|
#[lang = "add"]
|
|
|
|
|
#[const_trait]
|
2024-10-29 18:24:16 +00:00
|
|
|
pub trait Add<Rhs = Self> {
|
2023-10-15 08:51:54 +00:00
|
|
|
type Output;
|
|
|
|
|
|
|
|
|
|
fn add(self, rhs: Rhs) -> Self::Output;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-04 15:08:14 +00:00
|
|
|
impl const Add for i32 {
|
2023-10-15 08:51:54 +00:00
|
|
|
type Output = i32;
|
|
|
|
|
fn add(self, rhs: i32) -> i32 {
|
|
|
|
|
loop {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn foo() {
|
|
|
|
|
let x = 42_i32 + 43_i32;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const fn bar() {
|
|
|
|
|
let x = 42_i32 + 43_i32;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[lang = "Try"]
|
|
|
|
|
#[const_trait]
|
2024-10-29 18:24:16 +00:00
|
|
|
pub trait Try: FromResidual<Self::Residual> {
|
2023-10-15 08:51:54 +00:00
|
|
|
type Output;
|
|
|
|
|
type Residual;
|
|
|
|
|
|
|
|
|
|
#[lang = "from_output"]
|
|
|
|
|
fn from_output(output: Self::Output) -> Self;
|
|
|
|
|
|
|
|
|
|
#[lang = "branch"]
|
|
|
|
|
fn branch(self) -> ControlFlow<Self::Residual, Self::Output>;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-29 18:24:16 +00:00
|
|
|
#[const_trait]
|
|
|
|
|
pub trait FromResidual<R = <Self as Try>::Residual> {
|
2023-10-15 08:51:54 +00:00
|
|
|
#[lang = "from_residual"]
|
|
|
|
|
fn from_residual(residual: R) -> Self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum ControlFlow<B, C = ()> {
|
|
|
|
|
#[lang = "Continue"]
|
|
|
|
|
Continue(C),
|
|
|
|
|
#[lang = "Break"]
|
|
|
|
|
Break(B),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[const_trait]
|
|
|
|
|
#[lang = "fn"]
|
|
|
|
|
#[rustc_paren_sugar]
|
2025-03-11 12:08:45 +00:00
|
|
|
pub trait Fn<Args: Tuple>: [const] FnMut<Args> {
|
2023-10-15 08:51:54 +00:00
|
|
|
extern "rust-call" fn call(&self, args: Args) -> Self::Output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[const_trait]
|
|
|
|
|
#[lang = "fn_mut"]
|
|
|
|
|
#[rustc_paren_sugar]
|
2025-03-11 12:08:45 +00:00
|
|
|
pub trait FnMut<Args: Tuple>: [const] FnOnce<Args> {
|
2023-10-15 08:51:54 +00:00
|
|
|
extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[const_trait]
|
|
|
|
|
#[lang = "fn_once"]
|
|
|
|
|
#[rustc_paren_sugar]
|
2024-10-29 18:24:16 +00:00
|
|
|
pub trait FnOnce<Args: Tuple> {
|
2023-12-16 19:21:43 +00:00
|
|
|
#[lang = "fn_once_output"]
|
2023-10-15 08:51:54 +00:00
|
|
|
type Output;
|
|
|
|
|
|
|
|
|
|
extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[lang = "tuple_trait"]
|
2024-10-29 18:24:16 +00:00
|
|
|
pub trait Tuple {}
|
2023-10-15 08:51:54 +00:00
|
|
|
|
2024-09-11 12:27:08 +00:00
|
|
|
#[lang = "legacy_receiver"]
|
2024-10-29 18:24:16 +00:00
|
|
|
pub trait LegacyReceiver {}
|
2023-10-15 08:51:54 +00:00
|
|
|
|
2025-01-22 18:06:08 +00:00
|
|
|
impl<T: PointeeSized> LegacyReceiver for &T {}
|
2023-10-15 08:51:54 +00:00
|
|
|
|
2025-01-22 18:06:08 +00:00
|
|
|
impl<T: PointeeSized> LegacyReceiver for &mut T {}
|
2023-10-15 08:51:54 +00:00
|
|
|
|
Arbitrary self types v2: use Receiver trait
In this new version of Arbitrary Self Types, we no longer use the Deref trait
exclusively when working out which self types are valid. Instead, we follow a
chain of Receiver traits. This enables methods to be called on smart pointer
types which fundamentally cannot support Deref (for instance because they are
wrappers for pointers that don't follow Rust's aliasing rules).
This includes:
* Changes to tests appropriately
* New tests for:
* The basics of the feature
* Ensuring lifetime elision works properly
* Generic Receivers
* A copy of the method subst test enhanced with Receiver
This is really the heart of the 'arbitrary self types v2' feature, and
is the most critical commit in the current PR.
Subsequent commits are focused on:
* Detecting "shadowing" problems, where a smart pointer type can hide
methods in the pointee.
* Diagnostics and cleanup.
Naming: in this commit, the "Autoderef" type is modified so that it no
longer solely focuses on the "Deref" trait, but can now consider the
"Receiver" trait instead. Should it be renamed, to something like
"TraitFollower"? This was considered, but rejected, because
* even in the Receiver case, it still considers built-in derefs
* the name Autoderef is short and snappy.
2024-10-25 11:08:58 +00:00
|
|
|
#[lang = "receiver"]
|
|
|
|
|
pub trait Receiver {
|
|
|
|
|
#[lang = "receiver_target"]
|
2025-01-22 18:06:08 +00:00
|
|
|
type Target: MetaSized;
|
Arbitrary self types v2: use Receiver trait
In this new version of Arbitrary Self Types, we no longer use the Deref trait
exclusively when working out which self types are valid. Instead, we follow a
chain of Receiver traits. This enables methods to be called on smart pointer
types which fundamentally cannot support Deref (for instance because they are
wrappers for pointers that don't follow Rust's aliasing rules).
This includes:
* Changes to tests appropriately
* New tests for:
* The basics of the feature
* Ensuring lifetime elision works properly
* Generic Receivers
* A copy of the method subst test enhanced with Receiver
This is really the heart of the 'arbitrary self types v2' feature, and
is the most critical commit in the current PR.
Subsequent commits are focused on:
* Detecting "shadowing" problems, where a smart pointer type can hide
methods in the pointee.
* Diagnostics and cleanup.
Naming: in this commit, the "Autoderef" type is modified so that it no
longer solely focuses on the "Deref" trait, but can now consider the
"Receiver" trait instead. Should it be renamed, to something like
"TraitFollower"? This was considered, but rejected, because
* even in the Receiver case, it still considers built-in derefs
* the name Autoderef is short and snappy.
2024-10-25 11:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-22 18:06:08 +00:00
|
|
|
impl<T: Deref + MetaSized> Receiver for T {
|
Arbitrary self types v2: use Receiver trait
In this new version of Arbitrary Self Types, we no longer use the Deref trait
exclusively when working out which self types are valid. Instead, we follow a
chain of Receiver traits. This enables methods to be called on smart pointer
types which fundamentally cannot support Deref (for instance because they are
wrappers for pointers that don't follow Rust's aliasing rules).
This includes:
* Changes to tests appropriately
* New tests for:
* The basics of the feature
* Ensuring lifetime elision works properly
* Generic Receivers
* A copy of the method subst test enhanced with Receiver
This is really the heart of the 'arbitrary self types v2' feature, and
is the most critical commit in the current PR.
Subsequent commits are focused on:
* Detecting "shadowing" problems, where a smart pointer type can hide
methods in the pointee.
* Diagnostics and cleanup.
Naming: in this commit, the "Autoderef" type is modified so that it no
longer solely focuses on the "Deref" trait, but can now consider the
"Receiver" trait instead. Should it be renamed, to something like
"TraitFollower"? This was considered, but rejected, because
* even in the Receiver case, it still considers built-in derefs
* the name Autoderef is short and snappy.
2024-10-25 11:08:58 +00:00
|
|
|
type Target = <T as Deref>::Target;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-15 08:51:54 +00:00
|
|
|
#[lang = "destruct"]
|
|
|
|
|
#[const_trait]
|
2024-10-29 18:24:16 +00:00
|
|
|
pub trait Destruct {}
|
2023-10-15 08:51:54 +00:00
|
|
|
|
|
|
|
|
#[lang = "freeze"]
|
2024-10-29 18:24:16 +00:00
|
|
|
pub unsafe auto trait Freeze {}
|
2023-10-15 08:51:54 +00:00
|
|
|
|
|
|
|
|
#[lang = "drop"]
|
|
|
|
|
#[const_trait]
|
2024-10-29 18:24:16 +00:00
|
|
|
pub trait Drop {
|
2023-10-15 08:51:54 +00:00
|
|
|
fn drop(&mut self);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[const_trait]
|
2024-10-29 18:24:16 +00:00
|
|
|
pub trait Residual<O> {
|
2025-03-11 12:08:45 +00:00
|
|
|
type TryType: [const] Try<Output = O, Residual = Self> + Try<Output = O, Residual = Self>;
|
2023-10-15 08:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const fn size_of<T>() -> usize {
|
|
|
|
|
42
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl usize {
|
|
|
|
|
#[rustc_allow_incoherent_impl]
|
|
|
|
|
const fn repeat_u8(x: u8) -> usize {
|
|
|
|
|
usize::from_ne_bytes([x; size_of::<usize>()])
|
|
|
|
|
}
|
|
|
|
|
#[rustc_allow_incoherent_impl]
|
|
|
|
|
const fn from_ne_bytes(bytes: [u8; size_of::<Self>()]) -> Self {
|
|
|
|
|
loop {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[rustc_do_not_const_check] // hooked by const-eval
|
|
|
|
|
const fn panic_display() {
|
|
|
|
|
panic_fmt();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn panic_fmt() {}
|
|
|
|
|
|
|
|
|
|
#[lang = "index"]
|
|
|
|
|
#[const_trait]
|
2025-01-22 18:06:08 +00:00
|
|
|
pub trait Index<Idx: PointeeSized> {
|
|
|
|
|
type Output: MetaSized;
|
2023-10-15 08:51:54 +00:00
|
|
|
|
|
|
|
|
fn index(&self, index: Idx) -> &Self::Output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[const_trait]
|
2025-01-22 18:06:08 +00:00
|
|
|
pub unsafe trait SliceIndex<T: PointeeSized> {
|
|
|
|
|
type Output: MetaSized;
|
2023-10-15 08:51:54 +00:00
|
|
|
fn index(self, slice: &T) -> &Self::Output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T, I> const Index<I> for [T]
|
|
|
|
|
where
|
2025-03-11 12:08:45 +00:00
|
|
|
I: [const] SliceIndex<[T]>,
|
2023-10-15 08:51:54 +00:00
|
|
|
{
|
|
|
|
|
type Output = I::Output;
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn index(&self, index: I) -> &I::Output {
|
|
|
|
|
index.index(self)
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-29 18:24:16 +00:00
|
|
|
|
2023-10-15 08:51:54 +00:00
|
|
|
impl<T, I, const N: usize> const Index<I> for [T; N]
|
|
|
|
|
where
|
2025-03-11 12:08:45 +00:00
|
|
|
[T]: [const] Index<I>,
|
2023-10-15 08:51:54 +00:00
|
|
|
{
|
|
|
|
|
type Output = <[T] as Index<I>>::Output;
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn index(&self, index: I) -> &<[T] as Index<I>>::Output {
|
|
|
|
|
Index::index(self as &[T], index)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[lang = "unsize"]
|
2025-01-22 18:06:08 +00:00
|
|
|
pub trait Unsize<T: PointeeSized>: PointeeSized {}
|
2023-10-15 08:51:54 +00:00
|
|
|
|
|
|
|
|
#[lang = "coerce_unsized"]
|
2025-01-22 18:06:08 +00:00
|
|
|
pub trait CoerceUnsized<T: PointeeSized> {}
|
2023-10-15 08:51:54 +00:00
|
|
|
|
2025-01-22 18:06:08 +00:00
|
|
|
impl<'a, 'b: 'a, T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<&'a U> for &'b T {}
|
2023-10-15 08:51:54 +00:00
|
|
|
|
|
|
|
|
#[lang = "deref"]
|
2024-10-29 18:24:16 +00:00
|
|
|
#[const_trait]
|
|
|
|
|
pub trait Deref {
|
2023-10-15 08:51:54 +00:00
|
|
|
#[lang = "deref_target"]
|
2025-01-22 18:06:08 +00:00
|
|
|
type Target: MetaSized;
|
2023-10-15 08:51:54 +00:00
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-22 18:06:08 +00:00
|
|
|
impl<T: MetaSized> const Deref for &T {
|
2023-10-15 08:51:54 +00:00
|
|
|
type Target = T;
|
|
|
|
|
|
|
|
|
|
fn deref(&self) -> &T {
|
|
|
|
|
*self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-22 18:06:08 +00:00
|
|
|
impl<T: MetaSized> const Deref for &mut T {
|
2023-10-15 08:51:54 +00:00
|
|
|
type Target = T;
|
|
|
|
|
|
|
|
|
|
fn deref(&self) -> &T {
|
|
|
|
|
*self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum Option<T> {
|
|
|
|
|
#[lang = "None"]
|
|
|
|
|
None,
|
|
|
|
|
#[lang = "Some"]
|
|
|
|
|
Some(T),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T> Option<T> {
|
|
|
|
|
const fn as_ref(&self) -> Option<&T> {
|
|
|
|
|
match *self {
|
|
|
|
|
Some(ref x) => Some(x),
|
|
|
|
|
None => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const fn as_mut(&mut self) -> Option<&mut T> {
|
|
|
|
|
match *self {
|
|
|
|
|
Some(ref mut x) => Some(x),
|
|
|
|
|
None => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
use Option::*;
|
|
|
|
|
|
|
|
|
|
const fn as_deref<T>(opt: &Option<T>) -> Option<&T::Target>
|
|
|
|
|
where
|
2025-03-11 12:08:45 +00:00
|
|
|
T: [const] Deref,
|
2023-10-15 08:51:54 +00:00
|
|
|
{
|
|
|
|
|
match opt {
|
|
|
|
|
Option::Some(t) => Option::Some(t.deref()),
|
|
|
|
|
Option::None => Option::None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[const_trait]
|
2024-10-29 18:24:16 +00:00
|
|
|
pub trait Into<T>: Sized {
|
2023-10-15 08:51:54 +00:00
|
|
|
fn into(self) -> T;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[const_trait]
|
2024-10-29 18:24:16 +00:00
|
|
|
pub trait From<T>: Sized {
|
2023-10-15 08:51:54 +00:00
|
|
|
fn from(value: T) -> Self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T, U> const Into<U> for T
|
|
|
|
|
where
|
2025-03-11 12:08:45 +00:00
|
|
|
U: [const] From<T>,
|
2023-10-15 08:51:54 +00:00
|
|
|
{
|
|
|
|
|
fn into(self) -> U {
|
|
|
|
|
U::from(self)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T> const From<T> for T {
|
|
|
|
|
fn from(t: T) -> T {
|
|
|
|
|
t
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum Result<T, E> {
|
|
|
|
|
Ok(T),
|
|
|
|
|
Err(E),
|
|
|
|
|
}
|
|
|
|
|
use Result::*;
|
|
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<bool, ()> {
|
|
|
|
|
match s {
|
|
|
|
|
"true" => Ok(true),
|
|
|
|
|
"false" => Ok(false),
|
|
|
|
|
_ => Err(()),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[lang = "eq"]
|
2023-11-27 16:05:48 +00:00
|
|
|
#[const_trait]
|
2025-01-22 18:06:08 +00:00
|
|
|
pub trait PartialEq<Rhs: PointeeSized = Self>: PointeeSized {
|
2023-10-15 08:51:54 +00:00
|
|
|
fn eq(&self, other: &Rhs) -> bool;
|
|
|
|
|
fn ne(&self, other: &Rhs) -> bool {
|
|
|
|
|
!self.eq(other)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-22 18:06:08 +00:00
|
|
|
impl<A: PointeeSized, B: PointeeSized> const PartialEq<&B> for &A
|
2023-11-27 16:25:36 +00:00
|
|
|
where
|
2025-03-11 12:08:45 +00:00
|
|
|
A: [const] PartialEq<B>,
|
2023-11-27 16:25:36 +00:00
|
|
|
{
|
|
|
|
|
fn eq(&self, other: &&B) -> bool {
|
|
|
|
|
PartialEq::eq(*self, *other)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-04 15:08:14 +00:00
|
|
|
impl PartialEq for str {
|
2023-10-15 08:51:54 +00:00
|
|
|
fn eq(&self, other: &str) -> bool {
|
|
|
|
|
loop {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[lang = "not"]
|
|
|
|
|
#[const_trait]
|
2024-10-29 18:24:16 +00:00
|
|
|
pub trait Not {
|
2023-10-15 08:51:54 +00:00
|
|
|
type Output;
|
|
|
|
|
fn not(self) -> Self::Output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl const Not for bool {
|
|
|
|
|
type Output = bool;
|
|
|
|
|
fn not(self) -> bool {
|
|
|
|
|
!self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[lang = "pin"]
|
|
|
|
|
#[fundamental]
|
|
|
|
|
#[repr(transparent)]
|
|
|
|
|
struct Pin<P> {
|
|
|
|
|
pointer: P,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<P> Pin<P> {
|
|
|
|
|
#[lang = "new_unchecked"]
|
|
|
|
|
const unsafe fn new_unchecked(pointer: P) -> Pin<P> {
|
|
|
|
|
Pin { pointer }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-22 18:06:08 +00:00
|
|
|
impl<'a, T: PointeeSized> Pin<&'a T> {
|
2023-10-15 08:51:54 +00:00
|
|
|
const fn get_ref(self) -> &'a T {
|
|
|
|
|
self.pointer
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<P: Deref> Pin<P> {
|
2024-10-29 18:24:16 +00:00
|
|
|
const fn as_ref(&self) -> Pin<&P::Target>
|
2023-10-15 08:51:54 +00:00
|
|
|
where
|
2025-03-11 12:08:45 +00:00
|
|
|
P: [const] Deref,
|
2023-10-15 08:51:54 +00:00
|
|
|
{
|
|
|
|
|
unsafe { Pin::new_unchecked(&*self.pointer) }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-22 18:06:08 +00:00
|
|
|
impl<'a, T: PointeeSized> Pin<&'a mut T> {
|
2023-10-15 08:51:54 +00:00
|
|
|
const unsafe fn get_unchecked_mut(self) -> &'a mut T {
|
|
|
|
|
self.pointer
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-29 18:24:16 +00:00
|
|
|
|
2023-10-15 08:51:54 +00:00
|
|
|
impl<T> Option<T> {
|
|
|
|
|
const fn as_pin_ref(self: Pin<&Self>) -> Option<Pin<&T>> {
|
|
|
|
|
match Pin::get_ref(self).as_ref() {
|
|
|
|
|
Some(x) => unsafe { Some(Pin::new_unchecked(x)) },
|
|
|
|
|
None => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const fn as_pin_mut(self: Pin<&mut Self>) -> Option<Pin<&mut T>> {
|
|
|
|
|
unsafe {
|
|
|
|
|
match Pin::get_unchecked_mut(self).as_mut() {
|
|
|
|
|
Some(x) => Some(Pin::new_unchecked(x)),
|
|
|
|
|
None => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-11 12:08:45 +00:00
|
|
|
impl<P: [const] Deref> const Deref for Pin<P> {
|
2023-10-15 08:51:54 +00:00
|
|
|
type Target = P::Target;
|
|
|
|
|
fn deref(&self) -> &P::Target {
|
|
|
|
|
Pin::get_ref(Pin::as_ref(self))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-29 18:24:16 +00:00
|
|
|
impl<T> const Deref for Option<T> {
|
2023-10-15 08:51:54 +00:00
|
|
|
type Target = T;
|
|
|
|
|
fn deref(&self) -> &T {
|
|
|
|
|
loop {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-11 12:27:08 +00:00
|
|
|
impl<P: LegacyReceiver> LegacyReceiver for Pin<P> {}
|
2023-10-15 08:51:54 +00:00
|
|
|
|
|
|
|
|
impl<T: Clone> Clone for RefCell<T> {
|
|
|
|
|
fn clone(&self) -> RefCell<T> {
|
|
|
|
|
RefCell::new(self.borrow().clone())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-22 18:06:08 +00:00
|
|
|
struct RefCell<T: PointeeSized> {
|
2023-10-15 08:51:54 +00:00
|
|
|
borrow: UnsafeCell<()>,
|
|
|
|
|
value: UnsafeCell<T>,
|
|
|
|
|
}
|
|
|
|
|
impl<T> RefCell<T> {
|
|
|
|
|
const fn new(value: T) -> RefCell<T> {
|
|
|
|
|
loop {}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-01-22 18:06:08 +00:00
|
|
|
impl<T: PointeeSized> RefCell<T> {
|
2023-10-15 08:51:54 +00:00
|
|
|
fn borrow(&self) -> Ref<'_, T> {
|
|
|
|
|
loop {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[lang = "unsafe_cell"]
|
|
|
|
|
#[repr(transparent)]
|
2025-01-22 18:06:08 +00:00
|
|
|
struct UnsafeCell<T: PointeeSized> {
|
2023-10-15 08:51:54 +00:00
|
|
|
value: T,
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-22 18:06:08 +00:00
|
|
|
struct Ref<'b, T: PointeeSized + 'b> {
|
2023-10-15 08:51:54 +00:00
|
|
|
value: *const T,
|
|
|
|
|
borrow: &'b UnsafeCell<()>,
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-22 18:06:08 +00:00
|
|
|
impl<T: MetaSized> Deref for Ref<'_, T> {
|
2023-10-15 08:51:54 +00:00
|
|
|
type Target = T;
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn deref(&self) -> &T {
|
|
|
|
|
loop {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[lang = "clone"]
|
|
|
|
|
#[rustc_trivial_field_reads]
|
2024-10-29 20:08:55 +00:00
|
|
|
#[const_trait]
|
2024-10-29 18:24:16 +00:00
|
|
|
pub trait Clone: Sized {
|
2023-10-15 08:51:54 +00:00
|
|
|
fn clone(&self) -> Self;
|
|
|
|
|
fn clone_from(&mut self, source: &Self)
|
|
|
|
|
where
|
2025-03-11 12:08:45 +00:00
|
|
|
Self: [const] Destruct,
|
2023-10-15 08:51:54 +00:00
|
|
|
{
|
|
|
|
|
*self = source.clone()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[lang = "structural_peq"]
|
2024-10-29 18:24:16 +00:00
|
|
|
pub trait StructuralPartialEq {}
|
2023-10-15 08:51:54 +00:00
|
|
|
|
2025-03-11 12:08:45 +00:00
|
|
|
pub const fn drop<T: [const] Destruct>(_: T) {}
|
2023-12-16 19:21:43 +00:00
|
|
|
|
2024-03-05 17:39:04 +00:00
|
|
|
#[rustc_intrinsic]
|
|
|
|
|
const fn const_eval_select<ARG: Tuple, F, G, RET>(
|
|
|
|
|
arg: ARG,
|
|
|
|
|
called_in_const: F,
|
|
|
|
|
called_at_rt: G,
|
|
|
|
|
) -> RET
|
|
|
|
|
where
|
|
|
|
|
F: const FnOnce<ARG, Output = RET>,
|
2025-01-04 11:41:51 +01:00
|
|
|
G: FnOnce<ARG, Output = RET>;
|