-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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_convert #88674
Comments
Constify ?-operator for Result and Option Try to make `?`-operator usable in `const fn` with `Result` and `Option`, see rust-lang#74935 . Note that the try-operator itself was constified in rust-lang#87237. TODO * [x] Add tests for const T -> T conversions * [x] cleanup commits * [x] Remove `#![allow(incomplete_features)]` * [?] Await decision in rust-lang#86808 - I'm not sure * [x] Await support for parsing `~const` in bootstrapping compiler * [x] Tracking issue(s)? - rust-lang#88674
Make more `From` impls `const` (libcore) Adding `const` to `From` implementations in the core. `rustc_const_unstable` attribute is not added to unstable implementations. Tracking issue: rust-lang#88674 <details> <summary>Done</summary><div> - `T` from `T` - `T` from `!` - `Option<T>` from `T` - `Option<&T>` from `&Option<T>` - `Option<&mut T>` from `&mut Option<T>` - `Cell<T>` from `T` - `RefCell<T>` from `T` - `UnsafeCell<T>` from `T` - `OnceCell<T>` from `T` - `Poll<T>` from `T` - `u32` from `char` - `u64` from `char` - `u128` from `char` - `char` from `u8` - `AtomicBool` from `bool` - `AtomicPtr<T>` from `*mut T` - `AtomicI(bits)` from `i(bits)` - `AtomicU(bits)` from `u(bits)` - `i(bits)` from `NonZeroI(bits)` - `u(bits)` from `NonZeroU(bits)` - `NonNull<T>` from `Unique<T>` - `NonNull<T>` from `&T` - `NonNull<T>` from `&mut T` - `Unique<T>` from `&mut T` - `Infallible` from `!` - `TryIntError` from `!` - `TryIntError` from `Infallible` - `TryFromSliceError` from `Infallible` - `FromResidual for Option<T>` </div></details> <details> <summary>Remaining</summary><dev> - `NonZero` from `NonZero` These can't be made const at this time because these use Into::into. https://github.com/rust-lang/rust/blob/master/library/core/src/convert/num.rs#L393 - `std`, `alloc` There may still be many implementations that can be made `const`. </div></details>
Make more `From` impls `const` (libcore) Adding `const` to `From` implementations in the core. `rustc_const_unstable` attribute is not added to unstable implementations. Tracking issue: rust-lang#88674 <details> <summary>Done</summary><div> - `T` from `T` - `T` from `!` - `Option<T>` from `T` - `Option<&T>` from `&Option<T>` - `Option<&mut T>` from `&mut Option<T>` - `Cell<T>` from `T` - `RefCell<T>` from `T` - `UnsafeCell<T>` from `T` - `OnceCell<T>` from `T` - `Poll<T>` from `T` - `u32` from `char` - `u64` from `char` - `u128` from `char` - `char` from `u8` - `AtomicBool` from `bool` - `AtomicPtr<T>` from `*mut T` - `AtomicI(bits)` from `i(bits)` - `AtomicU(bits)` from `u(bits)` - `i(bits)` from `NonZeroI(bits)` - `u(bits)` from `NonZeroU(bits)` - `NonNull<T>` from `Unique<T>` - `NonNull<T>` from `&T` - `NonNull<T>` from `&mut T` - `Unique<T>` from `&mut T` - `Infallible` from `!` - `TryIntError` from `!` - `TryIntError` from `Infallible` - `TryFromSliceError` from `Infallible` - `FromResidual for Option<T>` </div></details> <details> <summary>Remaining</summary><dev> - `NonZero` from `NonZero` These can't be made const at this time because these use Into::into. https://github.com/rust-lang/rust/blob/master/library/core/src/convert/num.rs#L393 - `std`, `alloc` There may still be many implementations that can be made `const`. </div></details>
Just kidding; I forgot to rebase when I thought I had. >< |
Extend const_convert to rest of blanket core::convert impls This adds constness to all the blanket impls in `core::convert` under the existing `const_convert` feature, tracked by rust-lang#88674. Existing impls under that feature: ```rust impl<T> const From<T> for T; impl<T, U> const Into<U> for T where U: ~const From<T>; impl<T> const ops::Try for Option<T>; impl<T> const ops::FromResidual for Option<T>; impl<T, E> const ops::Try for Result<T, E>; impl<T, E, F> const ops::FromResidual<Result<convert::Infallible, E>> for Result<T, F> where F: ~const From<E>; ``` Additional impls: ```rust impl<T: ?Sized, U: ?Sized> const AsRef<U> for &T where T: ~const AsRef<U>; impl<T: ?Sized, U: ?Sized> const AsRef<U> for &mut T where T: ~const AsRef<U>; impl<T: ?Sized, U: ?Sized> const AsMut<U> for &mut T where T: ~const AsMut<U>; impl<T, U> const TryInto<U> for T where U: ~const TryFrom<T>; impl<T, U> const TryFrom<U> for T where U: ~const Into<T>; ```
Extend const_convert to rest of blanket core::convert impls This adds constness to all the blanket impls in `core::convert` under the existing `const_convert` feature, tracked by rust-lang#88674. Existing impls under that feature: ```rust impl<T> const From<T> for T; impl<T, U> const Into<U> for T where U: ~const From<T>; impl<T> const ops::Try for Option<T>; impl<T> const ops::FromResidual for Option<T>; impl<T, E> const ops::Try for Result<T, E>; impl<T, E, F> const ops::FromResidual<Result<convert::Infallible, E>> for Result<T, F> where F: ~const From<E>; ``` Additional impls: ```rust impl<T: ?Sized, U: ?Sized> const AsRef<U> for &T where T: ~const AsRef<U>; impl<T: ?Sized, U: ?Sized> const AsRef<U> for &mut T where T: ~const AsRef<U>; impl<T: ?Sized, U: ?Sized> const AsMut<U> for &mut T where T: ~const AsMut<U>; impl<T, U> const TryInto<U> for T where U: ~const TryFrom<T>; impl<T, U> const TryFrom<U> for T where U: ~const Into<T>; ```
These implementations are trivially const - since they only create the enum structure without running any non-const code. const_convert is tracked by rust-lang#88674
…low, r=scottmcm Extend const_convert with const {FormResidual, Try} for ControlFlow. Very small change so I just used the existing `const_convert` feature flag. rust-lang#88674 Newly const API: ``` impl<B, C> const ops::Try for ControlFlow<B, C>; impl<B, C> const ops::FromResidual for ControlFlow<B, C>; ``` `@usbalbin` I hope it is ok that I added to your feature.
With commit 76dbe29 the feature Does anybody know more about this? |
I believe that might be #110395 |
This has been entirely removed by #110393. |
Feature gate:
#![feature(const_convert)]
This is a tracking issue for constifying some conversions (see #87852 for numeric conversions). Among other things this enables using the
?
-operator onOption
andResult
in const contexts for trivial conversions. Note that this does not add any new implementations, it only constifies the existing ones.Simple example:
Public API
Constifies the following impls
Steps / History
impl const Trait for Ty
and~const
(tilde const) syntax #67792 and Tracking Issue fortry_trait_v2
, A new design for the?
desugaring (RFC#3058) #84277Unresolved Questions
The text was updated successfully, but these errors were encountered: