]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/associated-const-use-impl-of-same-trait.rs
62658470baa525631c3429f8b703a5b2d85b1492
[rust.git] / src / test / run-pass / associated-const-use-impl-of-same-trait.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![feature(associated_consts)]
12
13 // The main purpose of this test is to ensure that different impls of the same
14 // trait can refer to each other without setting off the static recursion check
15 // (as long as there's no actual recursion).
16
17 trait Foo {
18     const BAR: u32;
19 }
20
21 struct IsFoo1;
22
23 impl Foo for IsFoo1 {
24     const BAR: u32 = 1;
25 }
26
27 struct IsFoo2;
28
29 impl Foo for IsFoo2 {
30     const BAR: u32 = <IsFoo1 as Foo>::BAR;
31 }
32
33 fn main() {
34     assert_eq!(<IsFoo1>::BAR, <IsFoo2 as Foo>::BAR);
35 }