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