]> git.lizzy.rs Git - rust.git/blob - src/test/rustdoc/issue-33302.rs
Rollup merge of #43100 - ids1024:stat2, r=aturon
[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
15 macro_rules! make {
16     ($n:expr) => {
17         pub struct S;
18
19         // @has issue_33302/constant.CST.html \
20         //        '//pre[@class="rust const"]' 'pub const CST: i32 = 4 * 4'
21         pub const CST: i32 = ($n * $n);
22         // @has issue_33302/static.ST.html \
23         //        '//pre[@class="rust static"]' 'pub static ST: i32 = 4 * 4'
24         pub static ST: i32 = ($n * $n);
25
26         pub trait T<X> {
27             fn ignore(_: &X) {}
28             const C: X;
29             // @has issue_33302/trait.T.html \
30             //        '//*[@class="rust trait"]' 'const D: i32'
31             // @has - '//*[@class="docblock"]' 'D: i32 = 4 * 4'
32             // @has - '//*[@id="associatedconstant.D"]' 'const D: i32'
33             const D: i32 = ($n * $n);
34         }
35
36         // @has issue_33302/struct.S.html \
37         //        '//h3[@class="impl"]' 'impl T<[i32; 16]> for S'
38         // @has - '//*[@id="associatedconstant.C"]' 'const C: [i32; 16]'
39         // @has - '//*[@id="associatedconstant.D"]' 'const D: i32'
40         // @has - '//*[@class="docblock"]' 'C: [i32; 16] = [0; 4 * 4]'
41         impl T<[i32; ($n * $n)]> for S {
42             const C: [i32; ($n * $n)] = [0; ($n * $n)];
43         }
44
45         // @has issue_33302/struct.S.html \
46         //        '//h3[@class="impl"]' 'impl T<[i32; 16]> for S'
47         // @has - '//*[@id="associatedconstant.C-1"]' 'const C: (i32,)'
48         // @has - '//*[@id="associatedconstant.D-1"]' 'const D: i32'
49         // @has - '//*[@class="docblock"]' 'C: (i32,) = (4,)'
50         impl T<(i32,)> for S {
51             const C: (i32,) = ($n,);
52         }
53
54         // @has issue_33302/struct.S.html \
55         //        '//h3[@class="impl"]' 'impl T<(i32, i32)> for S'
56         // @has - '//*[@id="associatedconstant.C-2"]' 'const C: (i32, i32)'
57         // @has - '//*[@id="associatedconstant.D-2"]' 'const D: i32'
58         // @has - '//*[@class="docblock"]' 'C: (i32, i32) = (4, 4)'
59         // @has - '//*[@class="docblock"]' 'D: i32 = 4 / 4'
60         impl T<(i32, i32)> for S {
61             const C: (i32, i32) = ($n, $n);
62             const D: i32 = ($n / $n);
63         }
64     }
65 }
66
67 make!(4);