]> git.lizzy.rs Git - rust.git/blob - tests/ui/rfc-2632-const-trait-impl/trait-where-clause-run.rs
Rollup merge of #105172 - alexs-sh:issue-98861-fix-next, r=scottmcm
[rust.git] / tests / ui / rfc-2632-const-trait-impl / trait-where-clause-run.rs
1 // run-pass
2
3 #![feature(const_trait_impl)]
4
5 #[const_trait]
6 trait Bar {
7     fn bar() -> u8;
8 }
9
10 #[const_trait]
11 trait Foo {
12     fn foo() -> u8 where Self: ~const Bar {
13         <Self as Bar>::bar() * 6
14     }
15 }
16
17 struct NonConst;
18 struct Const;
19
20 impl Bar for NonConst {
21     fn bar() -> u8 {
22         3
23     }
24 }
25
26 impl Foo for NonConst {}
27
28 impl const Bar for Const {
29     fn bar() -> u8 {
30         4
31     }
32 }
33
34 impl const Foo for Const {}
35
36 fn main() {
37     const ANS1: u8 = Const::foo();
38     let ans2 = NonConst::foo();
39
40     assert_eq!(ANS1 + ans2, 42);
41 }