about summary refs log tree commit diff
path: root/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-fail.rs
blob: 8e6ef12810c2ccddc0091b3cfabd19b20448df4d (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
#![allow(incomplete_features)]
#![feature(const_trait_impl)]
#![feature(const_fn)]

pub trait Plus {
    fn plus(self, rhs: Self) -> Self;
}

impl const Plus for i32 {
    fn plus(self, rhs: Self) -> Self {
        self + rhs
    }
}

impl Plus for u32 {
    fn plus(self, rhs: Self) -> Self {
        self + rhs
    }
}

pub const fn add_i32(a: i32, b: i32) -> i32 {
    a.plus(b) // ok
}

pub const fn add_u32(a: u32, b: u32) -> u32 {
    a.plus(b)
    //~^ ERROR calls in constant functions are limited to constant functions
}

fn main() {}