1
Fork 0

Rename ~const Drop to ~const Destruct

This commit is contained in:
Deadbeef 2022-03-21 16:52:41 +11:00
parent 4df2a28aee
commit 1f3ee7f32e
No known key found for this signature in database
GPG key ID: 6D017A96D8E6C2F9
32 changed files with 296 additions and 192 deletions

View file

@ -1,5 +1,7 @@
//! impl bool {}
use crate::marker::Destruct;
#[lang = "bool"]
impl bool {
/// Returns `Some(t)` if the `bool` is [`true`](../std/keyword.true.html),
@ -16,9 +18,10 @@ impl bool {
#[unstable(feature = "bool_to_option", issue = "80967")]
#[rustc_const_unstable(feature = "const_bool_to_option", issue = "91917")]
#[inline]
#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
pub const fn then_some<T>(self, t: T) -> Option<T>
where
T: ~const Drop,
T: ~const Drop + ~const Destruct,
{
if self { Some(t) } else { None }
}
@ -35,10 +38,11 @@ impl bool {
#[stable(feature = "lazy_bool_to_option", since = "1.50.0")]
#[rustc_const_unstable(feature = "const_bool_to_option", issue = "91917")]
#[inline]
#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
pub const fn then<T, F>(self, f: F) -> Option<T>
where
F: ~const FnOnce() -> T,
F: ~const Drop,
F: ~const Drop + ~const Destruct,
{
if self { Some(f()) } else { None }
}

View file

@ -36,6 +36,8 @@
#![stable(feature = "rust1", since = "1.0.0")]
use crate::marker::Destruct;
/// A common trait for the ability to explicitly duplicate an object.
///
/// Differs from [`Copy`] in that [`Copy`] is implicit and an inexpensive bit-wise copy, while
@ -128,9 +130,10 @@ pub trait Clone: Sized {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[default_method_body_is_const]
#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
fn clone_from(&mut self, source: &Self)
where
Self: ~const Drop,
Self: ~const Drop + ~const Destruct,
{
*self = source.clone()
}

View file

@ -54,7 +54,7 @@
)]
#![allow(missing_docs)]
use crate::marker::DiscriminantKind;
use crate::marker::{Destruct, DiscriminantKind};
use crate::mem;
// These imports are used for simplifying intra-doc links
@ -2353,6 +2353,7 @@ pub const unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
#[rustc_const_unstable(feature = "const_eval_select", issue = "none")]
#[lang = "const_eval_select"]
#[rustc_do_not_const_check]
#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
pub const unsafe fn const_eval_select<ARG, F, G, RET>(
arg: ARG,
_called_in_const: F,
@ -2360,7 +2361,7 @@ pub const unsafe fn const_eval_select<ARG, F, G, RET>(
) -> RET
where
F: ~const FnOnce<ARG, Output = RET>,
G: FnOnce<ARG, Output = RET> + ~const Drop,
G: FnOnce<ARG, Output = RET> + ~const Drop + ~const Destruct,
{
called_at_rt.call_once(arg)
}
@ -2372,6 +2373,7 @@ where
)]
#[rustc_const_unstable(feature = "const_eval_select", issue = "none")]
#[lang = "const_eval_select_ct"]
#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
pub const unsafe fn const_eval_select_ct<ARG, F, G, RET>(
arg: ARG,
called_in_const: F,
@ -2379,7 +2381,7 @@ pub const unsafe fn const_eval_select_ct<ARG, F, G, RET>(
) -> RET
where
F: ~const FnOnce<ARG, Output = RET>,
G: FnOnce<ARG, Output = RET> + ~const Drop,
G: FnOnce<ARG, Output = RET> + ~const Drop + ~const Destruct,
{
called_in_const.call_once(arg)
}

View file

@ -794,10 +794,19 @@ impl<T: ?Sized> Unpin for *mut T {}
/// A marker for types that can be dropped.
///
/// The compiler logic for this trait is currently unimplemented.
/// This should be used for `~const` bounds,
/// as non-const bounds will always hold for every type.
#[unstable(feature = "const_trait_impl", issue = "67792")]
#[cfg_attr(not(bootstrap), lang = "destructible")]
pub trait Destructible {}
#[cfg_attr(not(bootstrap), lang = "destruct")]
#[cfg_attr(
not(bootstrap),
rustc_on_unimplemented(message = "can't drop `{Self}`", append_const_msg,)
)]
pub trait Destruct {}
#[cfg(bootstrap)]
#[unstable(feature = "const_trait_impl", issue = "67792")]
impl<T: ?Sized> const Destruct for T {}
/// Implementations of `Copy` for primitive types.
///

View file

@ -503,6 +503,7 @@
#![stable(feature = "rust1", since = "1.0.0")]
use crate::iter::{self, FromIterator, FusedIterator, TrustedLen};
use crate::marker::Destruct;
use crate::panicking::{panic, panic_str};
use crate::pin::Pin;
use crate::{
@ -772,9 +773,10 @@ impl<T> Option<T> {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
pub const fn unwrap_or(self, default: T) -> T
where
T: ~const Drop,
T: ~const Drop + ~const Destruct,
{
match self {
Some(x) => x,
@ -794,10 +796,11 @@ impl<T> Option<T> {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
pub const fn unwrap_or_else<F>(self, f: F) -> T
where
F: ~const FnOnce() -> T,
F: ~const Drop,
F: ~const Drop + ~const Destruct,
{
match self {
Some(x) => x,
@ -899,10 +902,11 @@ impl<T> Option<T> {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
pub const fn map<U, F>(self, f: F) -> Option<U>
where
F: ~const FnOnce(T) -> U,
F: ~const Drop,
F: ~const Drop + ~const Destruct,
{
match self {
Some(x) => Some(f(x)),
@ -928,10 +932,11 @@ impl<T> Option<T> {
#[inline]
#[unstable(feature = "result_option_inspect", issue = "91345")]
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
pub const fn inspect<F>(self, f: F) -> Self
where
F: ~const FnOnce(&T),
F: ~const Drop,
F: ~const Drop + ~const Destruct,
{
if let Some(ref x) = self {
f(x);
@ -961,11 +966,12 @@ impl<T> Option<T> {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
pub const fn map_or<U, F>(self, default: U, f: F) -> U
where
F: ~const FnOnce(T) -> U,
F: ~const Drop,
U: ~const Drop,
F: ~const Drop + ~const Destruct,
U: ~const Drop + ~const Destruct,
{
match self {
Some(t) => f(t),
@ -990,12 +996,13 @@ impl<T> Option<T> {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
pub const fn map_or_else<U, D, F>(self, default: D, f: F) -> U
where
D: ~const FnOnce() -> U,
D: ~const Drop,
D: ~const Drop + ~const Destruct,
F: ~const FnOnce(T) -> U,
F: ~const Drop,
F: ~const Drop + ~const Destruct,
{
match self {
Some(t) => f(t),
@ -1027,9 +1034,10 @@ impl<T> Option<T> {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
pub const fn ok_or<E>(self, err: E) -> Result<T, E>
where
E: ~const Drop,
E: ~const Drop + ~const Destruct,
{
match self {
Some(v) => Ok(v),
@ -1056,10 +1064,11 @@ impl<T> Option<T> {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
pub const fn ok_or_else<E, F>(self, err: F) -> Result<T, E>
where
F: ~const FnOnce() -> E,
F: ~const Drop,
F: ~const Drop + ~const Destruct,
{
match self {
Some(v) => Ok(v),
@ -1190,10 +1199,11 @@ impl<T> Option<T> {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
pub const fn and<U>(self, optb: Option<U>) -> Option<U>
where
T: ~const Drop,
U: ~const Drop,
T: ~const Drop + ~const Destruct,
U: ~const Drop + ~const Destruct,
{
match self {
Some(_) => optb,
@ -1232,10 +1242,11 @@ impl<T> Option<T> {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
pub const fn and_then<U, F>(self, f: F) -> Option<U>
where
F: ~const FnOnce(T) -> Option<U>,
F: ~const Drop,
F: ~const Drop + ~const Destruct,
{
match self {
Some(x) => f(x),
@ -1270,11 +1281,12 @@ impl<T> Option<T> {
#[inline]
#[stable(feature = "option_filter", since = "1.27.0")]
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
pub const fn filter<P>(self, predicate: P) -> Self
where
T: ~const Drop,
T: ~const Drop + ~const Destruct,
P: ~const FnOnce(&T) -> bool,
P: ~const Drop,
P: ~const Drop + ~const Destruct,
{
if let Some(x) = self {
if predicate(&x) {
@ -1314,9 +1326,10 @@ impl<T> Option<T> {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
pub const fn or(self, optb: Option<T>) -> Option<T>
where
T: ~const Drop,
T: ~const Drop + ~const Destruct,
{
match self {
Some(x) => Some(x),
@ -1340,10 +1353,11 @@ impl<T> Option<T> {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
pub const fn or_else<F>(self, f: F) -> Option<T>
where
F: ~const FnOnce() -> Option<T>,
F: ~const Drop,
F: ~const Drop + ~const Destruct,
{
match self {
Some(x) => Some(x),
@ -1375,9 +1389,10 @@ impl<T> Option<T> {
#[inline]
#[stable(feature = "option_xor", since = "1.37.0")]
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
pub const fn xor(self, optb: Option<T>) -> Option<T>
where
T: ~const Drop,
T: ~const Drop + ~const Destruct,
{
match (self, optb) {
(Some(a), None) => Some(a),
@ -1413,9 +1428,10 @@ impl<T> Option<T> {
#[inline]
#[stable(feature = "option_insert", since = "1.53.0")]
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
pub const fn insert(&mut self, value: T) -> &mut T
where
T: ~const Drop,
T: ~const Drop + ~const Destruct,
{
*self = Some(value);
@ -1446,9 +1462,10 @@ impl<T> Option<T> {
#[inline]
#[stable(feature = "option_entry", since = "1.20.0")]
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
pub const fn get_or_insert(&mut self, value: T) -> &mut T
where
T: ~const Drop,
T: ~const Drop + ~const Destruct,
{
if let None = *self {
*self = Some(value);
@ -1513,10 +1530,11 @@ impl<T> Option<T> {
#[inline]
#[stable(feature = "option_entry", since = "1.20.0")]
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
pub const fn get_or_insert_with<F>(&mut self, f: F) -> &mut T
where
F: ~const FnOnce() -> T,
F: ~const Drop,
F: ~const Drop + ~const Destruct,
{
if let None = *self {
// the compiler isn't smart enough to know that we are not dropping a `T`
@ -1627,10 +1645,11 @@ impl<T> Option<T> {
/// ```
#[stable(feature = "option_zip_option", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
pub const fn zip<U>(self, other: Option<U>) -> Option<(T, U)>
where
T: ~const Drop,
U: ~const Drop,
T: ~const Drop + ~const Destruct,
U: ~const Drop + ~const Destruct,
{
match (self, other) {
(Some(a), Some(b)) => Some((a, b)),
@ -1668,12 +1687,13 @@ impl<T> Option<T> {
/// ```
#[unstable(feature = "option_zip", issue = "70086")]
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
pub const fn zip_with<U, F, R>(self, other: Option<U>, f: F) -> Option<R>
where
F: ~const FnOnce(T, U) -> R,
F: ~const Drop,
T: ~const Drop,
U: ~const Drop,
F: ~const Drop + ~const Destruct,
T: ~const Drop + ~const Destruct,
U: ~const Drop + ~const Destruct,
{
match (self, other) {
(Some(a), Some(b)) => Some(f(a, b)),
@ -1860,9 +1880,10 @@ const fn expect_failed(msg: &str) -> ! {
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_clone", issue = "91805")]
#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
impl<T> const Clone for Option<T>
where
T: ~const Clone + ~const Drop,
T: ~const Clone + ~const Drop + ~const Destruct,
{
#[inline]
fn clone(&self) -> Self {

View file

@ -490,6 +490,7 @@
#![stable(feature = "rust1", since = "1.0.0")]
use crate::iter::{self, FromIterator, FusedIterator, TrustedLen};
use crate::marker::Destruct;
use crate::ops::{self, ControlFlow, Deref, DerefMut};
use crate::{convert, fmt, hint};
@ -635,7 +636,7 @@ impl<T, E> Result<T, E> {
#[rustc_const_unstable(feature = "const_result_drop", issue = "92384")]
pub const fn ok(self) -> Option<T>
where
E: ~const Drop,
E: ~const Drop + ~const Destruct,
{
match self {
Ok(x) => Some(x),
@ -666,7 +667,7 @@ impl<T, E> Result<T, E> {
#[rustc_const_unstable(feature = "const_result_drop", issue = "92384")]
pub const fn err(self) -> Option<E>
where
T: ~const Drop,
T: ~const Drop + ~const Destruct,
{
match self {
// FIXME: ~const Drop doesn't quite work right yet
@ -1282,9 +1283,9 @@ impl<T, E> Result<T, E> {
#[stable(feature = "rust1", since = "1.0.0")]
pub const fn and<U>(self, res: Result<U, E>) -> Result<U, E>
where
T: ~const Drop,
U: ~const Drop,
E: ~const Drop,
T: ~const Drop + ~const Destruct,
U: ~const Drop + ~const Destruct,
E: ~const Drop + ~const Destruct,
{
match self {
// FIXME: ~const Drop doesn't quite work right yet
@ -1367,9 +1368,9 @@ impl<T, E> Result<T, E> {
#[stable(feature = "rust1", since = "1.0.0")]
pub const fn or<F>(self, res: Result<T, F>) -> Result<T, F>
where
T: ~const Drop,
E: ~const Drop,
F: ~const Drop,
T: ~const Drop + ~const Destruct,
E: ~const Drop + ~const Destruct,
F: ~const Drop + ~const Destruct,
{
match self {
Ok(v) => Ok(v),
@ -1431,8 +1432,8 @@ impl<T, E> Result<T, E> {
#[stable(feature = "rust1", since = "1.0.0")]
pub const fn unwrap_or(self, default: T) -> T
where
T: ~const Drop,
E: ~const Drop,
T: ~const Drop + ~const Destruct,
E: ~const Drop + ~const Destruct,
{
match self {
Ok(t) => t,
@ -1802,10 +1803,11 @@ fn unwrap_failed<T>(_msg: &str, _error: &T) -> ! {
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_clone", issue = "91805")]
#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
impl<T, E> const Clone for Result<T, E>
where
T: ~const Clone + ~const Drop,
E: ~const Clone + ~const Drop,
T: ~const Clone + ~const Drop + ~const Destruct,
E: ~const Clone + ~const Drop + ~const Destruct,
{
#[inline]
fn clone(&self) -> Self {