Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking Issue for const_num_from_num #87852

Closed
2 of 4 tasks
usbalbin opened this issue Aug 7, 2021 · 4 comments
Closed
2 of 4 tasks

Tracking Issue for const_num_from_num #87852

usbalbin opened this issue Aug 7, 2021 · 4 comments
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. F-const_trait_impl `#![feature(const_trait_impl)]` T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@usbalbin
Copy link
Contributor

usbalbin commented Aug 7, 2021

Feature gate: #![feature(const_num_from_num)]

This is a tracking issue for constifying the impl From<U> for T and impl TryFrom<U> for T for conversions between the basic built in numeric types(both T and U are one of f32, f64, iX, uX). It also constifies the corresponding From conversions for NonZeroUX and NonZeroIX and from NonZeroUX/NonZeroIX to uX/iX of same type and signedness. Additionally AtomicUX from uX and AtomicIX from iX, this is however only for types of same size.

Note that all of this does not add any new implementations, it only constifies the existing ones.

In short, this will enable things like below without having to use as casts

const FOO_U32: u32 = u32::from(bar_returing_u16()); // u16 -> u32
const BAZ_F32: f32 = f32::from(bar_returing_u8());  // u8 -> f32

const FROM_NONZERO_U8: u8 = u8::from(bar_returing_nonzero_u8()); // NonZeroU8 -> u8
const NONZERO_FROM_SMALLER: NonZeroU32 = NonZeroU32::from(bar_returing_nonzero_u8()); // NonZeroU8 -> NonZeroU32

const ATOMIC_FROM_U8: AtomicU8 = AtomicU8::from(bar_returing_u8()); // u8 -> AtomicU8

Public API

# TODO

Steps / History

Unresolved Questions

  • None yet.
@usbalbin usbalbin added C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Aug 7, 2021
@jonas-schievink jonas-schievink added the F-const_trait_impl `#![feature(const_trait_impl)]` label Aug 7, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this issue Oct 21, 2021
Make `From` impls of NonZero integer const.

I also changed the feature gate added to `From` impls of Atomic integer to `const_num_from_num` from `const_convert`.

Tracking issue: rust-lang#87852
JohnTitor added a commit to JohnTitor/rust that referenced this issue Oct 21, 2021
Make `From` impls of NonZero integer const.

I also changed the feature gate added to `From` impls of Atomic integer to `const_num_from_num` from `const_convert`.

Tracking issue: rust-lang#87852
@lilasta
Copy link
Contributor

lilasta commented Oct 21, 2021

From implementations of atomic and non-zero integers is now const (Integers from non-zero integers and atomic integers from normal integers).

@chrisbouchard
Copy link

Is this still feature a thing? Rust doesn't recognize the feature name when I enable it on the latest nightly.

error[E0635]: unknown feature `const_num_from_num`
 --> src/lib.rs:1:12
  |
1 | #![feature(const_num_from_num)]
  |            ^^^^^^^^^^^^^^^^^^

But also numeric From and TryFroms are still non-const.

Playground Link

@oli-obk
Copy link
Contributor

oli-obk commented Jul 5, 2024

All const trait impls are currently disabled while the backing implementation is being reworked

@RalfJung
Copy link
Member

RalfJung commented Sep 8, 2024

This has been removed by #110393.

@RalfJung RalfJung closed this as completed Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. F-const_trait_impl `#![feature(const_trait_impl)]` T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants