Make the Step
implementations const.
This commit is contained in:
parent
13afbdaa06
commit
7bc67ef6e0
@ -20,7 +20,8 @@ unsafe_impl_trusted_step![char i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usi
|
|||||||
/// The *successor* operation moves towards values that compare greater.
|
/// The *successor* operation moves towards values that compare greater.
|
||||||
/// The *predecessor* operation moves towards values that compare lesser.
|
/// The *predecessor* operation moves towards values that compare lesser.
|
||||||
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
|
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
|
||||||
pub trait Step: Clone + PartialOrd + Sized {
|
#[const_trait]
|
||||||
|
pub trait Step: ~const Clone + ~const PartialOrd + Sized {
|
||||||
/// Returns the number of *successor* steps required to get from `start` to `end`.
|
/// Returns the number of *successor* steps required to get from `start` to `end`.
|
||||||
///
|
///
|
||||||
/// Returns `None` if the number of steps would overflow `usize`
|
/// Returns `None` if the number of steps would overflow `usize`
|
||||||
@ -234,7 +235,8 @@ macro_rules! step_integer_impls {
|
|||||||
$(
|
$(
|
||||||
#[allow(unreachable_patterns)]
|
#[allow(unreachable_patterns)]
|
||||||
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
|
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
|
||||||
impl Step for $u_narrower {
|
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
|
||||||
|
impl const Step for $u_narrower {
|
||||||
step_identical_methods!();
|
step_identical_methods!();
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -266,7 +268,8 @@ macro_rules! step_integer_impls {
|
|||||||
|
|
||||||
#[allow(unreachable_patterns)]
|
#[allow(unreachable_patterns)]
|
||||||
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
|
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
|
||||||
impl Step for $i_narrower {
|
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
|
||||||
|
impl const Step for $i_narrower {
|
||||||
step_identical_methods!();
|
step_identical_methods!();
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -330,7 +333,8 @@ macro_rules! step_integer_impls {
|
|||||||
$(
|
$(
|
||||||
#[allow(unreachable_patterns)]
|
#[allow(unreachable_patterns)]
|
||||||
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
|
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
|
||||||
impl Step for $u_wider {
|
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
|
||||||
|
impl const Step for $u_wider {
|
||||||
step_identical_methods!();
|
step_identical_methods!();
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -355,7 +359,8 @@ macro_rules! step_integer_impls {
|
|||||||
|
|
||||||
#[allow(unreachable_patterns)]
|
#[allow(unreachable_patterns)]
|
||||||
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
|
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
|
||||||
impl Step for $i_wider {
|
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
|
||||||
|
impl const Step for $i_wider {
|
||||||
step_identical_methods!();
|
step_identical_methods!();
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -405,7 +410,8 @@ step_integer_impls! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
|
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
|
||||||
impl Step for char {
|
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
|
||||||
|
impl const Step for char {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn steps_between(&start: &char, &end: &char) -> Option<usize> {
|
fn steps_between(&start: &char, &end: &char) -> Option<usize> {
|
||||||
let start = start as u32;
|
let start = start as u32;
|
||||||
@ -423,6 +429,7 @@ impl Step for char {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[rustc_allow_const_fn_unstable(const_try)]
|
||||||
fn forward_checked(start: char, count: usize) -> Option<char> {
|
fn forward_checked(start: char, count: usize) -> Option<char> {
|
||||||
let start = start as u32;
|
let start = start as u32;
|
||||||
let mut res = Step::forward_checked(start, count)?;
|
let mut res = Step::forward_checked(start, count)?;
|
||||||
@ -439,6 +446,7 @@ impl Step for char {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[rustc_allow_const_fn_unstable(const_try)]
|
||||||
fn backward_checked(start: char, count: usize) -> Option<char> {
|
fn backward_checked(start: char, count: usize) -> Option<char> {
|
||||||
let start = start as u32;
|
let start = start as u32;
|
||||||
let mut res = Step::backward_checked(start, count)?;
|
let mut res = Step::backward_checked(start, count)?;
|
||||||
|
@ -86,4 +86,5 @@ pub unsafe trait InPlaceIterable: Iterator {}
|
|||||||
/// for details. Consumers are free to rely on the invariants in unsafe code.
|
/// for details. Consumers are free to rely on the invariants in unsafe code.
|
||||||
#[unstable(feature = "trusted_step", issue = "85731")]
|
#[unstable(feature = "trusted_step", issue = "85731")]
|
||||||
#[rustc_specialization_trait]
|
#[rustc_specialization_trait]
|
||||||
pub unsafe trait TrustedStep: Step {}
|
#[const_trait]
|
||||||
|
pub unsafe trait TrustedStep: ~const Step {}
|
||||||
|
@ -126,6 +126,7 @@
|
|||||||
#![feature(const_intrinsic_forget)]
|
#![feature(const_intrinsic_forget)]
|
||||||
#![feature(const_ipv4)]
|
#![feature(const_ipv4)]
|
||||||
#![feature(const_ipv6)]
|
#![feature(const_ipv6)]
|
||||||
|
#![feature(const_iter)]
|
||||||
#![feature(const_likely)]
|
#![feature(const_likely)]
|
||||||
#![feature(const_maybe_uninit_uninit_array)]
|
#![feature(const_maybe_uninit_uninit_array)]
|
||||||
#![feature(const_maybe_uninit_as_mut_ptr)]
|
#![feature(const_maybe_uninit_as_mut_ptr)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user