about summary refs log tree commit diff
path: root/src/test/ui/rfc-2632-const-trait-impl/stability.rs
blob: 6b54a9eab5205bb904bfb9474b30d7f44f773962 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#![feature(allow_internal_unstable)]
#![feature(const_add)]
#![feature(const_trait_impl)]
#![feature(staged_api)]

pub struct Int(i32);

#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "rust1", since = "1.0.0")]
impl const std::ops::Sub for Int {
    type Output = Self;

    fn sub(self, rhs: Self) -> Self {
        //~^ ERROR trait methods cannot be stable const fn
        Int(self.0 - rhs.0)
    }
}

#[rustc_const_unstable(feature = "const_add", issue = "none")]
impl const std::ops::Add for Int {
    type Output = Self;

    fn add(self, rhs: Self) -> Self {
        Int(self.0 + rhs.0)
    }
}

#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "rust1", since = "1.0.0")]
pub const fn foo() -> Int {
    Int(1i32) + Int(2i32)
    //~^ ERROR not yet stable as a const fn
}

// ok
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "bar", issue = "none")]
pub const fn bar() -> Int {
    Int(1i32) + Int(2i32)
}

fn main() {}