]> git.lizzy.rs Git - rust.git/blob - src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-pass.rs
Rollup merge of #86852 - Amanieu:remove_doc_aliases, r=joshtriplett
[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     fn ne(&self, other: &Self) -> bool {
21         !self.eq(other)
22     }
23 }
24
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 }