]> git.proxmox.com Git - rustc.git/blob - src/test/ui/rfc-2632-const-trait-impl/stability.rs
New upstream version 1.62.1+dfsg1
[rustc.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 #![stable(feature = "rust1", since = "1.0.0")]
6
7 #[stable(feature = "rust1", since = "1.0.0")]
8 pub struct Int(i32);
9
10 #[stable(feature = "rust1", since = "1.0.0")]
11 #[rustc_const_stable(feature = "rust1", since = "1.0.0")]
12 impl const std::ops::Sub for Int {
13 type Output = Self;
14
15 fn sub(self, rhs: Self) -> Self {
16 //~^ ERROR trait methods cannot be stable const fn
17 Int(self.0 - rhs.0)
18 }
19 }
20
21 #[stable(feature = "rust1", since = "1.0.0")]
22 #[rustc_const_unstable(feature = "const_add", issue = "none")]
23 impl const std::ops::Add for Int {
24 type Output = Self;
25
26 fn add(self, rhs: Self) -> Self {
27 Int(self.0 + rhs.0)
28 }
29 }
30
31 #[stable(feature = "rust1", since = "1.0.0")]
32 #[rustc_const_stable(feature = "rust1", since = "1.0.0")]
33 pub const fn foo() -> Int {
34 Int(1i32) + Int(2i32)
35 //~^ ERROR not yet stable as a const fn
36 }
37
38 // ok
39 #[stable(feature = "rust1", since = "1.0.0")]
40 #[rustc_const_unstable(feature = "bar", issue = "none")]
41 pub const fn bar() -> Int {
42 Int(1i32) + Int(2i32)
43 }
44
45 fn main() {}