Skip to content

Commit d811def

Browse files
committed
Fix tests
1 parent a6018c2 commit d811def

20 files changed

+80
-246
lines changed

library/core/src/option.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,9 +2144,10 @@ const fn expect_failed(msg: &str) -> ! {
21442144
/////////////////////////////////////////////////////////////////////////////
21452145

21462146
#[stable(feature = "rust1", since = "1.0.0")]
2147-
impl<T> Clone for Option<T>
2147+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
2148+
impl<T> const Clone for Option<T>
21482149
where
2149-
T: Clone,
2150+
T: ~const Clone + ~const Destruct,
21502151
{
21512152
#[inline]
21522153
fn clone(&self) -> Self {
@@ -2230,7 +2231,8 @@ impl<'a, T> IntoIterator for &'a mut Option<T> {
22302231
}
22312232

22322233
#[stable(since = "1.12.0", feature = "option_from")]
2233-
impl<T> From<T> for Option<T> {
2234+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
2235+
impl<T> const From<T> for Option<T> {
22342236
/// Moves `val` into a new [`Some`].
22352237
///
22362238
/// # Examples
@@ -2246,7 +2248,8 @@ impl<T> From<T> for Option<T> {
22462248
}
22472249

22482250
#[stable(feature = "option_ref_from_ref_option", since = "1.30.0")]
2249-
impl<'a, T> From<&'a Option<T>> for Option<&'a T> {
2251+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
2252+
impl<'a, T> const From<&'a Option<T>> for Option<&'a T> {
22502253
/// Converts from `&Option<T>` to `Option<&T>`.
22512254
///
22522255
/// # Examples
@@ -2273,7 +2276,8 @@ impl<'a, T> From<&'a Option<T>> for Option<&'a T> {
22732276
}
22742277

22752278
#[stable(feature = "option_ref_from_ref_option", since = "1.30.0")]
2276-
impl<'a, T> From<&'a mut Option<T>> for Option<&'a mut T> {
2279+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
2280+
impl<'a, T> const From<&'a mut Option<T>> for Option<&'a mut T> {
22772281
/// Converts from `&mut Option<T>` to `Option<&mut T>`
22782282
///
22792283
/// # Examples
@@ -2593,7 +2597,8 @@ impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
25932597
}
25942598

25952599
#[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")]
2596-
impl<T> ops::Try for Option<T> {
2600+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
2601+
impl<T> const ops::Try for Option<T> {
25972602
type Output = T;
25982603
type Residual = Option<convert::Infallible>;
25992604

@@ -2612,9 +2617,10 @@ impl<T> ops::Try for Option<T> {
26122617
}
26132618

26142619
#[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")]
2620+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
26152621
// Note: manually specifying the residual type instead of using the default to work around
26162622
// https://github.com/rust-lang/rust/issues/99940
2617-
impl<T> ops::FromResidual<Option<convert::Infallible>> for Option<T> {
2623+
impl<T> const ops::FromResidual<Option<convert::Infallible>> for Option<T> {
26182624
#[inline]
26192625
fn from_residual(residual: Option<convert::Infallible>) -> Self {
26202626
match residual {
@@ -2625,15 +2631,17 @@ impl<T> ops::FromResidual<Option<convert::Infallible>> for Option<T> {
26252631

26262632
#[diagnostic::do_not_recommend]
26272633
#[unstable(feature = "try_trait_v2_yeet", issue = "96374")]
2628-
impl<T> ops::FromResidual<ops::Yeet<()>> for Option<T> {
2634+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
2635+
impl<T> const ops::FromResidual<ops::Yeet<()>> for Option<T> {
26292636
#[inline]
26302637
fn from_residual(ops::Yeet(()): ops::Yeet<()>) -> Self {
26312638
None
26322639
}
26332640
}
26342641

26352642
#[unstable(feature = "try_trait_v2_residual", issue = "91285")]
2636-
impl<T> ops::Residual<T> for Option<convert::Infallible> {
2643+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
2644+
impl<T> const ops::Residual<T> for Option<convert::Infallible> {
26372645
type TryType = Option<T>;
26382646
}
26392647

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: 1 addition & 0 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.

tests/ui/consts/const-try.stderr

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +0,0 @@
1-
error: const `impl` for trait `FromResidual` which is not `const`
2-
--> $DIR/const-try.rs:15:12
3-
|
4-
LL | impl const FromResidual<Error> for TryMe {
5-
| ^^^^^^^^^^^^^^^^^^^ this trait is not `const`
6-
|
7-
= note: marking a trait with `const` ensures all default method bodies are `const`
8-
= note: adding a non-const method body in the future would be a breaking change
9-
10-
error: const `impl` for trait `Try` which is not `const`
11-
--> $DIR/const-try.rs:22:12
12-
|
13-
LL | impl const Try for TryMe {
14-
| ^^^ this trait is not `const`
15-
|
16-
= note: marking a trait with `const` ensures all default method bodies are `const`
17-
= note: adding a non-const method body in the future would be a breaking change
18-
19-
error[E0015]: `?` is not allowed on `TryMe` in constant functions
20-
--> $DIR/const-try.rs:35:5
21-
|
22-
LL | TryMe?;
23-
| ^^^^^^
24-
|
25-
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
26-
27-
error[E0015]: `?` is not allowed on `TryMe` in constant functions
28-
--> $DIR/const-try.rs:35:5
29-
|
30-
LL | TryMe?;
31-
| ^^^^^^
32-
|
33-
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
34-
35-
error: aborting due to 4 previous errors
36-
37-
For more information about this error, try `rustc --explain E0015`.

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
@@ -11,8 +11,8 @@ impl<T> From<T> for T {
1111

1212
struct S;
1313

14-
impl From<S> for S {
15-
fn from(s: S) -> S { //~ ERROR `from` specializes an item from a parent `impl`, but that item is not marked `default`
14+
impl From<S> for S { //~ ERROR conflicting implementations of trait `From<S>` for type `S`
15+
fn from(s: S) -> S {
1616
s
1717
}
1818
}

0 commit comments

Comments
 (0)