Skip to content

Commit e22fe40

Browse files
committed
Revert "Auto merge of #89450 - usbalbin:const_try_revert, r=oli-obk"
This reverts commit a8387ae, reversing changes made to 6e12110.
1 parent 84b1d85 commit e22fe40

File tree

8 files changed

+54
-15
lines changed

8 files changed

+54
-15
lines changed

library/core/src/convert/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,10 @@ where
534534

535535
// From implies Into
536536
#[stable(feature = "rust1", since = "1.0.0")]
537-
impl<T, U> Into<U> for T
537+
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
538+
impl<T, U> const Into<U> for T
538539
where
539-
U: From<T>,
540+
U: ~const From<T>,
540541
{
541542
fn into(self) -> U {
542543
U::from(self)

library/core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
#![feature(const_float_classify)]
113113
#![feature(const_fmt_arguments_new)]
114114
#![feature(const_heap)]
115+
#![feature(const_convert)]
115116
#![feature(const_inherent_unchecked_arith)]
116117
#![feature(const_int_unchecked_arith)]
117118
#![feature(const_intrinsic_copy)]

library/core/src/option.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2077,7 +2077,8 @@ impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
20772077
}
20782078

20792079
#[unstable(feature = "try_trait_v2", issue = "84277")]
2080-
impl<T> ops::Try for Option<T> {
2080+
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
2081+
impl<T> const ops::Try for Option<T> {
20812082
type Output = T;
20822083
type Residual = Option<convert::Infallible>;
20832084

@@ -2096,6 +2097,7 @@ impl<T> ops::Try for Option<T> {
20962097
}
20972098

20982099
#[unstable(feature = "try_trait_v2", issue = "84277")]
2100+
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
20992101
impl<T> const ops::FromResidual for Option<T> {
21002102
#[inline]
21012103
fn from_residual(residual: Option<convert::Infallible>) -> Self {

library/core/src/result.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,7 +1945,8 @@ impl<A, E, V: FromIterator<A>> FromIterator<Result<A, E>> for Result<V, E> {
19451945
}
19461946

19471947
#[unstable(feature = "try_trait_v2", issue = "84277")]
1948-
impl<T, E> ops::Try for Result<T, E> {
1948+
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
1949+
impl<T, E> const ops::Try for Result<T, E> {
19491950
type Output = T;
19501951
type Residual = Result<convert::Infallible, E>;
19511952

@@ -1964,7 +1965,10 @@ impl<T, E> ops::Try for Result<T, E> {
19641965
}
19651966

19661967
#[unstable(feature = "try_trait_v2", issue = "84277")]
1967-
impl<T, E, F: From<E>> ops::FromResidual<Result<convert::Infallible, E>> for Result<T, F> {
1968+
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
1969+
impl<T, E, F: ~const From<E>> const ops::FromResidual<Result<convert::Infallible, E>>
1970+
for Result<T, F>
1971+
{
19681972
#[inline]
19691973
fn from_residual(residual: Result<convert::Infallible, E>) -> Self {
19701974
match residual {

library/core/tests/convert.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#[test]
2+
fn convert() {
3+
const fn from(x: i32) -> i32 {
4+
i32::from(x)
5+
}
6+
7+
const FOO: i32 = from(42);
8+
assert_eq!(FOO, 42);
9+
10+
const fn into(x: Vec<String>) -> Vec<String> {
11+
x.into()
12+
}
13+
14+
const BAR: Vec<String> = into(Vec::new());
15+
assert_eq!(BAR, Vec::<String>::new());
16+
}

library/core/tests/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
#![feature(const_convert)]
1313
#![feature(const_maybe_uninit_as_mut_ptr)]
1414
#![feature(const_maybe_uninit_assume_init)]
15+
#![feature(const_num_from_num)]
1516
#![feature(const_ptr_read)]
1617
#![feature(const_ptr_write)]
1718
#![feature(const_ptr_offset)]
1819
#![feature(const_trait_impl)]
19-
#![feature(const_num_from_num)]
2020
#![feature(core_intrinsics)]
2121
#![feature(core_private_bignum)]
2222
#![feature(core_private_diy_float)]
@@ -96,6 +96,7 @@ mod char;
9696
mod clone;
9797
mod cmp;
9898
mod const_ptr;
99+
mod convert;
99100
mod fmt;
100101
mod future;
101102
mod hash;

src/test/ui/consts/not_const_clusure_in_const.rs

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/test/ui/consts/try-operator.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// run-pass
2+
3+
#![feature(try_trait_v2)]
4+
#![feature(const_trait_impl)]
5+
#![feature(const_try)]
6+
#![feature(const_convert)]
7+
8+
fn main() {
9+
const fn result() -> Result<bool, ()> {
10+
Err(())?;
11+
Ok(true)
12+
}
13+
14+
const FOO: Result<bool, ()> = result();
15+
assert_eq!(Err(()), FOO);
16+
17+
const fn option() -> Option<()> {
18+
None?;
19+
Some(())
20+
}
21+
const BAR: Option<()> = option();
22+
assert_eq!(None, BAR);
23+
}

0 commit comments

Comments
 (0)