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