Skip to content

Commit b8dfccf

Browse files
committed
Fix tests
1 parent a11f31e commit b8dfccf

22 files changed

+86
-276
lines changed

library/core/src/option.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@
577577
#![stable(feature = "rust1", since = "1.0.0")]
578578

579579
use crate::iter::{self, FusedIterator, TrustedLen};
580+
use crate::marker::Destruct;
580581
use crate::ops::{self, ControlFlow, Deref, DerefMut};
581582
use crate::panicking::{panic, panic_display};
582583
use crate::pin::Pin;
@@ -2087,9 +2088,10 @@ const fn expect_failed(msg: &str) -> ! {
20872088
/////////////////////////////////////////////////////////////////////////////
20882089

20892090
#[stable(feature = "rust1", since = "1.0.0")]
2090-
impl<T> Clone for Option<T>
2091+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
2092+
impl<T> const Clone for Option<T>
20912093
where
2092-
T: Clone,
2094+
T: ~const Clone + ~const Destruct,
20932095
{
20942096
#[inline]
20952097
fn clone(&self) -> Self {
@@ -2173,7 +2175,8 @@ impl<'a, T> IntoIterator for &'a mut Option<T> {
21732175
}
21742176

21752177
#[stable(since = "1.12.0", feature = "option_from")]
2176-
impl<T> From<T> for Option<T> {
2178+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
2179+
impl<T> const From<T> for Option<T> {
21772180
/// Moves `val` into a new [`Some`].
21782181
///
21792182
/// # Examples
@@ -2189,7 +2192,8 @@ impl<T> From<T> for Option<T> {
21892192
}
21902193

21912194
#[stable(feature = "option_ref_from_ref_option", since = "1.30.0")]
2192-
impl<'a, T> From<&'a Option<T>> for Option<&'a T> {
2195+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
2196+
impl<'a, T> const From<&'a Option<T>> for Option<&'a T> {
21932197
/// Converts from `&Option<T>` to `Option<&T>`.
21942198
///
21952199
/// # Examples
@@ -2216,7 +2220,8 @@ impl<'a, T> From<&'a Option<T>> for Option<&'a T> {
22162220
}
22172221

22182222
#[stable(feature = "option_ref_from_ref_option", since = "1.30.0")]
2219-
impl<'a, T> From<&'a mut Option<T>> for Option<&'a mut T> {
2223+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
2224+
impl<'a, T> const From<&'a mut Option<T>> for Option<&'a mut T> {
22202225
/// Converts from `&mut Option<T>` to `Option<&mut T>`
22212226
///
22222227
/// # Examples
@@ -2535,7 +2540,8 @@ impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
25352540
}
25362541

25372542
#[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")]
2538-
impl<T> ops::Try for Option<T> {
2543+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
2544+
impl<T> const ops::Try for Option<T> {
25392545
type Output = T;
25402546
type Residual = Option<convert::Infallible>;
25412547

@@ -2554,9 +2560,10 @@ impl<T> ops::Try for Option<T> {
25542560
}
25552561

25562562
#[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")]
2563+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
25572564
// Note: manually specifying the residual type instead of using the default to work around
25582565
// https://github.com/rust-lang/rust/issues/99940
2559-
impl<T> ops::FromResidual<Option<convert::Infallible>> for Option<T> {
2566+
impl<T> const ops::FromResidual<Option<convert::Infallible>> for Option<T> {
25602567
#[inline]
25612568
fn from_residual(residual: Option<convert::Infallible>) -> Self {
25622569
match residual {
@@ -2567,15 +2574,17 @@ impl<T> ops::FromResidual<Option<convert::Infallible>> for Option<T> {
25672574

25682575
#[diagnostic::do_not_recommend]
25692576
#[unstable(feature = "try_trait_v2_yeet", issue = "96374")]
2570-
impl<T> ops::FromResidual<ops::Yeet<()>> for Option<T> {
2577+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
2578+
impl<T> const ops::FromResidual<ops::Yeet<()>> for Option<T> {
25712579
#[inline]
25722580
fn from_residual(ops::Yeet(()): ops::Yeet<()>) -> Self {
25732581
None
25742582
}
25752583
}
25762584

25772585
#[unstable(feature = "try_trait_v2_residual", issue = "91285")]
2578-
impl<T> ops::Residual<T> for Option<convert::Infallible> {
2586+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
2587+
impl<T> const ops::Residual<T> for Option<convert::Infallible> {
25792588
type TryType = Option<T>;
25802589
}
25812590

tests/ui/consts/const-try-feature-gate.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const fn t() -> Option<()> {
44
Some(())?;
55
//~^ ERROR `?` is not allowed
66
//~| ERROR `?` is not allowed
7+
//~| ERROR `Try` is not yet stable as a const trait
8+
//~| ERROR `FromResidual` is not yet stable as a const trait
79
None
810
}
911

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,47 @@
1-
error[E0015]: `?` is not allowed on `Option<()>` in constant functions
1+
error[E0658]: `?` is not allowed on `Option<()>` in constant functions
22
--> $DIR/const-try-feature-gate.rs:4:5
33
|
44
LL | Some(())?;
55
| ^^^^^^^^^
66
|
77
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
8+
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
9+
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
10+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
811

9-
error[E0015]: `?` is not allowed on `Option<()>` in constant functions
12+
error: `Try` is not yet stable as a const trait
13+
--> $DIR/const-try-feature-gate.rs:4:5
14+
|
15+
LL | Some(())?;
16+
| ^^^^^^^^^
17+
|
18+
help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
19+
|
20+
LL + #![feature(const_trait_impl)]
21+
|
22+
23+
error[E0658]: `?` is not allowed on `Option<()>` in constant functions
1024
--> $DIR/const-try-feature-gate.rs:4:5
1125
|
1226
LL | Some(())?;
1327
| ^^^^^^^^^
1428
|
1529
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
30+
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
31+
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
32+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
33+
34+
error: `FromResidual` is not yet stable as a const trait
35+
--> $DIR/const-try-feature-gate.rs:4:5
36+
|
37+
LL | Some(())?;
38+
| ^^^^^^^^^
39+
|
40+
help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
41+
|
42+
LL + #![feature(const_trait_impl)]
43+
|
1644

17-
error: aborting due to 2 previous errors
45+
error: aborting due to 4 previous errors
1846

19-
For more information about this error, try `rustc --explain E0015`.
47+
For more information about this error, try `rustc --explain E0658`.

tests/ui/consts/const-try.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//@ run-pass
12
//@ compile-flags: -Znext-solver
23

34
// Demonstrates what's needed to make use of `?` in const contexts.
@@ -14,7 +15,7 @@ struct Error;
1415

1516
impl const FromResidual<Error> for TryMe {
1617
//~^ ERROR const `impl` for trait `FromResidual` which is not marked with `#[const_trait]`
17-
fn from_residual(residual: Error) -> Self {
18+
fn from_residual(_residual: Error) -> Self {
1819
TryMe
1920
}
2021
}
@@ -23,7 +24,7 @@ impl const Try for TryMe {
2324
//~^ ERROR const `impl` for trait `Try` which is not marked with `#[const_trait]`
2425
type Output = ();
2526
type Residual = Error;
26-
fn from_output(output: Self::Output) -> Self {
27+
fn from_output(_output: Self::Output) -> Self {
2728
TryMe
2829
}
2930
fn branch(self) -> ControlFlow<Self::Residual, Self::Output> {

tests/ui/consts/const-try.stderr

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

tests/ui/consts/control-flow/try.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// The `?` operator is still not const-evaluatable because it calls `From::from` on the error
2-
// variant.
1+
//@ run-pass
2+
3+
#![allow(dead_code)]
4+
#![feature(const_trait_impl)]
35

46
const fn opt() -> Option<i32> {
57
let x = Some(2);
68
x?;
7-
//~^ ERROR: `?` is not allowed
8-
//~| ERROR: `?` is not allowed
99
None
1010
}
1111

tests/ui/consts/control-flow/try.stderr

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

tests/ui/consts/try-operator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
//@ known-bug: #110395
1+
//@ run-pass
2+
// @ known-bug: #110395
23

34
#![feature(try_trait_v2)]
45
#![feature(const_trait_impl)]
56
#![feature(const_try)]
6-
#![feature(const_convert)]
77

88
fn main() {
99
const fn result() -> Result<bool, ()> {

tests/ui/consts/try-operator.stderr

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

tests/ui/specialization/issue-111232.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
struct S;
44

5-
impl From<S> for S {
6-
fn from(s: S) -> S { //~ ERROR `from` specializes an item from a parent `impl`, but that item is not marked `default`
5+
impl From<S> for S { //~ ERROR conflicting implementations of trait `From<S>` for type `S`
6+
fn from(s: S) -> S {
77
s
88
}
99
}

0 commit comments

Comments
 (0)