]> git.lizzy.rs Git - rust.git/blob - src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-pass.rs
cf38bc3c9645321cafbcf9f9e3e279e07e01a3a7
[rust.git] / src / test / ui / rfc-2632-const-trait-impl / call-const-trait-method-pass.rs
1 // run-pass
2
3 #![feature(const_trait_impl)]
4
5 struct Int(i32);
6
7 impl const std::ops::Add for Int {
8     type Output = Int;
9
10     fn add(self, rhs: Self) -> Self {
11         Int(self.0.plus(rhs.0))
12     }
13 }
14
15 impl const PartialEq for Int {
16     fn eq(&self, rhs: &Self) -> bool {
17         self.0 == rhs.0
18     }
19     fn ne(&self, other: &Self) -> bool {
20         !self.eq(other)
21     }
22 }
23
24 pub trait Plus {
25     fn plus(self, rhs: Self) -> Self;
26 }
27
28 impl const Plus for i32 {
29     fn plus(self, rhs: Self) -> Self {
30         self + rhs
31     }
32 }
33
34 pub const fn add_i32(a: i32, b: i32) -> i32 {
35     a.plus(b)
36 }
37
38 const ADD_INT: Int = Int(1i32) + Int(2i32);
39
40 fn main() {
41     assert!(ADD_INT == Int(3i32));
42 }