Split const trait method test and impl ops::Add
This commit is contained in:
parent
323ff193b8
commit
d6d6d25c34
3 changed files with 43 additions and 2 deletions
|
@ -0,0 +1,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() {}
|
Loading…
Add table
Add a link
Reference in a new issue