]> git.lizzy.rs Git - rust.git/blob - src/test/ui/rfc-2632-const-trait-impl/trait-default-body-stability.rs
Auto merge of #105651 - tgross35:once-cell-inline, r=m-ou-se
[rust.git] / src / test / ui / rfc-2632-const-trait-impl / trait-default-body-stability.rs
1 // check-pass
2
3 #![feature(staged_api)]
4 #![feature(const_trait_impl)]
5 #![feature(const_t_try)]
6 #![feature(const_try)]
7 #![feature(try_trait_v2)]
8
9 #![stable(feature = "foo", since = "1.0")]
10
11 use std::ops::{ControlFlow, FromResidual, Try};
12
13 #[stable(feature = "foo", since = "1.0")]
14 pub struct T;
15
16 #[stable(feature = "foo", since = "1.0")]
17 #[rustc_const_unstable(feature = "const_t_try", issue = "none")]
18 impl const Try for T {
19     type Output = T;
20     type Residual = T;
21
22     fn from_output(t: T) -> T {
23         t
24     }
25
26     fn branch(self) -> ControlFlow<T, T> {
27         ControlFlow::Continue(self)
28     }
29 }
30
31 #[stable(feature = "foo", since = "1.0")]
32 #[rustc_const_unstable(feature = "const_t_try", issue = "none")]
33 impl const FromResidual for T {
34     fn from_residual(t: T) -> T {
35         t
36     }
37 }
38
39 #[stable(feature = "foo", since = "1.0")]
40 #[const_trait]
41 pub trait Tr {
42     #[stable(feature = "foo", since = "1.0")]
43     fn bar() -> T {
44         T?
45         // Should be allowed.
46         // Must enable unstable features to call this trait fn in const contexts.
47     }
48 }
49
50 fn main() {}