Skip to content

Commit eefd790

Browse files
committed
impl const From<num> for num
1 parent 508b328 commit eefd790

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

library/core/src/convert/num.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ impl_float_to_int!(f64 => u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize);
4545
macro_rules! impl_from {
4646
($Small: ty, $Large: ty, #[$attr:meta], $doc: expr) => {
4747
#[$attr]
48-
impl From<$Small> for $Large {
48+
#[rustc_const_unstable(feature = "const_num_from_num", issue = "87852")]
49+
impl const From<$Small> for $Large {
4950
// Rustdocs on the impl block show a "[+] show undocumented items" toggle.
5051
// Rustdocs on functions do not.
5152
#[doc = $doc]
@@ -172,7 +173,8 @@ impl_from! { f32, f64, #[stable(feature = "lossless_float_conv", since = "1.6.0"
172173
macro_rules! try_from_unbounded {
173174
($source:ty, $($target:ty),*) => {$(
174175
#[stable(feature = "try_from", since = "1.34.0")]
175-
impl TryFrom<$source> for $target {
176+
#[rustc_const_unstable(feature = "const_num_from_num", issue = "87852")]
177+
impl const TryFrom<$source> for $target {
176178
type Error = TryFromIntError;
177179

178180
/// Try to create the target number type from a source
@@ -190,7 +192,8 @@ macro_rules! try_from_unbounded {
190192
macro_rules! try_from_lower_bounded {
191193
($source:ty, $($target:ty),*) => {$(
192194
#[stable(feature = "try_from", since = "1.34.0")]
193-
impl TryFrom<$source> for $target {
195+
#[rustc_const_unstable(feature = "const_num_from_num", issue = "87852")]
196+
impl const TryFrom<$source> for $target {
194197
type Error = TryFromIntError;
195198

196199
/// Try to create the target number type from a source
@@ -212,7 +215,8 @@ macro_rules! try_from_lower_bounded {
212215
macro_rules! try_from_upper_bounded {
213216
($source:ty, $($target:ty),*) => {$(
214217
#[stable(feature = "try_from", since = "1.34.0")]
215-
impl TryFrom<$source> for $target {
218+
#[rustc_const_unstable(feature = "const_num_from_num", issue = "87852")]
219+
impl const TryFrom<$source> for $target {
216220
type Error = TryFromIntError;
217221

218222
/// Try to create the target number type from a source
@@ -234,7 +238,8 @@ macro_rules! try_from_upper_bounded {
234238
macro_rules! try_from_both_bounded {
235239
($source:ty, $($target:ty),*) => {$(
236240
#[stable(feature = "try_from", since = "1.34.0")]
237-
impl TryFrom<$source> for $target {
241+
#[rustc_const_unstable(feature = "const_num_from_num", issue = "87852")]
242+
impl const TryFrom<$source> for $target {
238243
type Error = TryFromIntError;
239244

240245
/// Try to create the target number type from a source

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
#![feature(const_slice_from_raw_parts)]
100100
#![feature(const_slice_ptr_len)]
101101
#![feature(const_swap)]
102+
#![feature(const_trait_impl)]
102103
#![feature(const_type_id)]
103104
#![feature(const_type_name)]
104105
#![feature(const_unreachable_unchecked)]

0 commit comments

Comments
 (0)