]>
Commit | Line | Data |
---|---|---|
064997fb FG |
1 | // Regression test for issue #97933. |
2 | // | |
3 | // Test that certain unevaluated constant expressions that are | |
4 | // deemed too verbose or complex and that may leak private or | |
5 | // `doc(hidden)` struct fields are not displayed in the documentation. | |
6 | // | |
7 | // Read the documentation of `rustdoc::clean::utils::print_const_expr` | |
8 | // for further details. | |
9 | ||
10 | // @has hide_complex_unevaluated_consts/trait.Container.html | |
11 | pub trait Container { | |
12 | // A helper constant that prevents const expressions containing it | |
13 | // from getting fully evaluated since it doesn't have a body and | |
14 | // thus is non-reducible. This allows us to specifically test the | |
15 | // pretty-printing of *unevaluated* consts. | |
16 | const ABSTRACT: i32; | |
17 | ||
18 | // Ensure that the private field does not get leaked: | |
19 | // | |
20 | // @has - '//*[@id="associatedconstant.STRUCT0"]' \ | |
21 | // 'const STRUCT0: Struct = _' | |
22 | const STRUCT0: Struct = Struct { private: () }; | |
23 | ||
24 | // @has - '//*[@id="associatedconstant.STRUCT1"]' \ | |
25 | // 'const STRUCT1: (Struct,) = _' | |
26 | const STRUCT1: (Struct,) = (Struct{private: /**/()},); | |
27 | ||
28 | // Although the struct field is public here, check that it is not | |
29 | // displayed. In a future version of rustdoc, we definitely want to | |
30 | // show it. However for the time being, the printing logic is a bit | |
31 | // conservative. | |
32 | // | |
33 | // @has - '//*[@id="associatedconstant.STRUCT2"]' \ | |
34 | // 'const STRUCT2: Record = _' | |
35 | const STRUCT2: Record = Record { public: 5 }; | |
36 | ||
37 | // Test that we do not show the incredibly verbose match expr: | |
38 | // | |
39 | // @has - '//*[@id="associatedconstant.MATCH0"]' \ | |
40 | // 'const MATCH0: i32 = _' | |
41 | const MATCH0: i32 = match 234 { | |
42 | 0 => 1, | |
43 | _ => Self::ABSTRACT, | |
44 | }; | |
45 | ||
46 | // @has - '//*[@id="associatedconstant.MATCH1"]' \ | |
47 | // 'const MATCH1: bool = _' | |
48 | const MATCH1: bool = match Self::ABSTRACT { | |
49 | _ => true, | |
50 | }; | |
51 | ||
52 | // Check that we hide complex (arithmetic) operations. | |
53 | // In this case, it is a bit unfortunate since the expression | |
54 | // is not *that* verbose and it might be quite useful to the reader. | |
55 | // | |
56 | // However in general, the expression might be quite large and | |
57 | // contain match expressions and structs with private fields. | |
58 | // We would need to recurse over the whole expression and even more | |
59 | // importantly respect operator precedence when pretty-printing | |
60 | // the potentially partially censored expression. | |
61 | // For now, the implementation is quite simple and the choices | |
62 | // rather conservative. | |
63 | // | |
64 | // @has - '//*[@id="associatedconstant.ARITH_OPS"]' \ | |
65 | // 'const ARITH_OPS: i32 = _' | |
66 | const ARITH_OPS: i32 = Self::ABSTRACT * 2 + 1; | |
67 | } | |
68 | ||
69 | pub struct Struct { private: () } | |
70 | ||
71 | pub struct Record { pub public: i32 } |