usbalbin · GitHub

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 on Option and Result in const contexts for trivial conversions. Note that this does not add any new implementations, it only constifies the existing ones.

Simple example:

const fn foo() -> Result<(), FooError> {
    let bar = try_thing()?; // A function that returns Result<_, FooError>
    do_stuff_with(bar)?;    // A function that returns Result<_, FooError>
    Ok(())
}

Public API

Constifies the following impls

impl<T, U> const Into<U> for T where U: ~const From<T>;
impl<T> const From<T> for 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>;
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>;

Steps / History

Unresolved Questions

  • None yet.

Read the original on github.com ↗