]> git.lizzy.rs Git - rust.git/blob - src/test/ui/rfc-2632-const-trait-impl/stability.rs
Rollup merge of #87180 - notriddle:notriddle/sidebar-keyboard-mobile, r=GuillaumeGomez
[rust.git] / src / test / ui / rfc-2632-const-trait-impl / stability.rs
1 #![feature(allow_internal_unstable)]
2 #![feature(const_add)]
3 #![feature(const_trait_impl)]
4 #![feature(staged_api)]
5
6 pub struct Int(i32);
7
8 #[stable(feature = "rust1", since = "1.0.0")]
9 #[rustc_const_stable(feature = "rust1", since = "1.0.0")]
10 impl const std::ops::Sub for Int {
11     type Output = Self;
12
13     fn sub(self, rhs: Self) -> Self {
14         //~^ ERROR trait methods cannot be stable const fn
15         Int(self.0 - rhs.0)
16     }
17 }
18
19 #[rustc_const_unstable(feature = "const_add", issue = "none")]
20 impl const std::ops::Add for Int {
21     type Output = Self;
22
23     fn add(self, rhs: Self) -> Self {
24         Int(self.0 + rhs.0)
25     }
26 }
27
28 #[stable(feature = "rust1", since = "1.0.0")]
29 #[rustc_const_stable(feature = "rust1", since = "1.0.0")]
30 pub const fn foo() -> Int {
31     Int(1i32) + Int(2i32)
32     //~^ ERROR not yet stable as a const fn
33 }
34
35 // ok
36 #[stable(feature = "rust1", since = "1.0.0")]
37 #[rustc_const_unstable(feature = "bar", issue = "none")]
38 pub const fn bar() -> Int {
39     Int(1i32) + Int(2i32)
40 }
41
42 fn main() {}