]> git.lizzy.rs Git - rust.git/blob - src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-pass.rs
Auto merge of #106371 - RalfJung:no-ret-position-noalias, r=nikic
[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 #[const_trait]
25 pub trait Plus {
26     fn plus(self, rhs: Self) -> Self;
27 }
28
29 impl const Plus for i32 {
30     fn plus(self, rhs: Self) -> Self {
31         self + rhs
32     }
33 }
34
35 pub const fn add_i32(a: i32, b: i32) -> i32 {
36     a.plus(b)
37 }
38
39 const ADD_INT: Int = Int(1i32) + Int(2i32);
40
41 fn main() {
42     assert!(ADD_INT == Int(3i32));
43 }