]> git.lizzy.rs Git - rust.git/blob - src/test/rustdoc/issue-33302.rs
Rollup merge of #69599 - Centril:typeck-tweak-wording, r=davidtwco
[rust.git] / src / test / rustdoc / issue-33302.rs
1 // Ensure constant and array length values are not taken from source
2 // code, which wreaks havoc with macros.
3
4
5 macro_rules! make {
6     ($n:expr) => {
7         pub struct S;
8
9         // @has issue_33302/constant.CST.html \
10         //        '//pre[@class="rust const"]' 'pub const CST: i32'
11         pub const CST: i32 = ($n * $n);
12         // @has issue_33302/static.ST.html \
13         //        '//pre[@class="rust static"]' 'pub static ST: i32'
14         pub static ST: i32 = ($n * $n);
15
16         pub trait T<X> {
17             fn ignore(_: &X) {}
18             const C: X;
19             // @has issue_33302/trait.T.html \
20             //        '//*[@class="rust trait"]' 'const D: i32'
21             // @has - '//*[@id="associatedconstant.D"]' 'const D: i32'
22             const D: i32 = ($n * $n);
23         }
24
25         // @has issue_33302/struct.S.html \
26         //        '//h3[@class="impl"]' 'impl T<[i32; 16]> for S'
27         // @has - '//*[@id="associatedconstant.C"]' 'const C: [i32; 16]'
28         // @has - '//*[@id="associatedconstant.D"]' 'const D: i32'
29         impl T<[i32; ($n * $n)]> for S {
30             const C: [i32; ($n * $n)] = [0; ($n * $n)];
31         }
32
33         // @has issue_33302/struct.S.html \
34         //        '//h3[@class="impl"]' 'impl T<[i32; 16]> for S'
35         // @has - '//*[@id="associatedconstant.C-1"]' 'const C: (i32,)'
36         // @has - '//*[@id="associatedconstant.D-1"]' 'const D: i32'
37         impl T<(i32,)> for S {
38             const C: (i32,) = ($n,);
39         }
40
41         // @has issue_33302/struct.S.html \
42         //        '//h3[@class="impl"]' 'impl T<(i32, i32)> for S'
43         // @has - '//*[@id="associatedconstant.C-2"]' 'const C: (i32, i32)'
44         // @has - '//*[@id="associatedconstant.D-2"]' 'const D: i32'
45         impl T<(i32, i32)> for S {
46             const C: (i32, i32) = ($n, $n);
47             const D: i32 = ($n / $n);
48         }
49     }
50 }
51
52 make!(4);