Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split const trait method test and impl
ops::Add
- Loading branch information
1 parent
323ff19
commit d6d6d25
Showing
3 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...trait-impl/call-const-trait-method.stderr → ...-impl/call-const-trait-method-fail.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-pass.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// run-pass | ||
|
||
#![allow(incomplete_features)] | ||
#![feature(const_trait_impl)] | ||
#![feature(const_fn)] | ||
|
||
struct Int(i32); | ||
|
||
impl const std::ops::Add for Int { | ||
type Output = Int; | ||
|
||
fn add(self, rhs: Self) -> Self { | ||
Int(self.0.plus(rhs.0)) | ||
} | ||
} | ||
|
||
impl const PartialEq for Int { | ||
fn eq(&self, rhs: &Self) -> bool { | ||
self.0 == rhs.0 | ||
} | ||
} | ||
|
||
pub trait Plus { | ||
fn plus(self, rhs: Self) -> Self; | ||
} | ||
|
||
impl const Plus for i32 { | ||
fn plus(self, rhs: Self) -> Self { | ||
self + rhs | ||
} | ||
} | ||
|
||
pub const fn add_i32(a: i32, b: i32) -> i32 { | ||
a.plus(b) | ||
} | ||
|
||
const ADD_INT: Int = Int(1i32) + Int(2i32); | ||
|
||
fn main() { | ||
assert!(ADD_INT == Int(3i32)); | ||
} |