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