]> git.lizzy.rs Git - rust.git/blob - src/test/rustdoc/issue-33302.rs
a34ee908ef295adff271c5ef0aa09044fc29ac78
[rust.git] / src / test / rustdoc / issue-33302.rs
1 // Copyright 2016 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 // Ensure constant and array length values are not taken from source
12 // code, which wreaks havoc with macros.
13
14 #![feature(associated_consts)]
15
16 macro_rules! make {
17     ($n:expr) => {
18         pub struct S;
19
20         // @has issue_33302/constant.CST.html \
21         //        '//pre[@class="rust const"]' 'pub const CST: i32 = 4 * 4'
22         pub const CST: i32 = ($n * $n);
23         // @has issue_33302/static.ST.html \
24         //        '//pre[@class="rust static"]' 'pub static ST: i32 = 4 * 4'
25         pub static ST: i32 = ($n * $n);
26
27         pub trait T<X> {
28             fn ignore(_: &X) {}
29             const C: X;
30             // @has issue_33302/trait.T.html \
31             //        '//*[@class="rust trait"]' 'const D: i32'
32             // @has - '//*[@class="docblock"]' 'D: i32 = 4 * 4'
33             // @has - '//*[@id="associatedconstant.D"]' 'const D: i32'
34             const D: i32 = ($n * $n);
35         }
36
37         // @has issue_33302/struct.S.html \
38         //        '//h3[@class="impl"]' 'impl T<[i32; 16]> for S'
39         // @has - '//*[@id="associatedconstant.C"]' 'const C: [i32; 16]'
40         // @has - '//*[@id="associatedconstant.D"]' 'const D: i32'
41         // @has - '//*[@class="docblock"]' 'C: [i32; 16] = [0; 4 * 4]'
42         impl T<[i32; ($n * $n)]> for S {
43             const C: [i32; ($n * $n)] = [0; ($n * $n)];
44         }
45
46         // @has issue_33302/struct.S.html \
47         //        '//h3[@class="impl"]' 'impl T<[i32; 16]> for S'
48         // @has - '//*[@id="associatedconstant.C-1"]' 'const C: (i32,)'
49         // @has - '//*[@id="associatedconstant.D-1"]' 'const D: i32'
50         // @has - '//*[@class="docblock"]' 'C: (i32,) = (4,)'
51         impl T<(i32,)> for S {
52             const C: (i32,) = ($n,);
53         }
54
55         // @has issue_33302/struct.S.html \
56         //        '//h3[@class="impl"]' 'impl T<(i32, i32)> for S'
57         // @has - '//*[@id="associatedconstant.C-2"]' 'const C: (i32, i32)'
58         // @has - '//*[@id="associatedconstant.D-2"]' 'const D: i32'
59         // @has - '//*[@class="docblock"]' 'C: (i32, i32) = (4, 4)'
60         // @has - '//*[@class="docblock"]' 'D: i32 = 4 / 4'
61         impl T<(i32, i32)> for S {
62             const C: (i32, i32) = ($n, $n);
63             const D: i32 = ($n / $n);
64         }
65     }
66 }
67
68 make!(4);