Skip to content

Commit 14b90b7

Browse files
committed
Auto merge of rust-lang#91549 - fee1-dead:const_env, r=spastorino
Eliminate ConstnessAnd again Closes rust-lang#91489. Closes rust-lang#89432. Reverts rust-lang#91491. Reverts rust-lang#89450. r? `@spastorino`
2 parents 2a9aa72 + 8aa9a01 commit 14b90b7

File tree

6 files changed

+31
-6
lines changed

6 files changed

+31
-6
lines changed

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)

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)]

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 {

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 {

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+
}

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;

0 commit comments

Comments
 (0)