1 // Regression test for issue #97933.
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.
7 // Read the documentation of `rustdoc::clean::utils::print_const_expr`
8 // for further details.
10 // @has hide_complex_unevaluated_consts/trait.Container.html
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.
18 // Ensure that the private field does not get leaked:
20 // @has - '//*[@id="associatedconstant.STRUCT0"]' \
21 // 'const STRUCT0: Struct = _'
22 const STRUCT0: Struct = Struct { private: () };
24 // @has - '//*[@id="associatedconstant.STRUCT1"]' \
25 // 'const STRUCT1: (Struct,) = _'
26 const STRUCT1: (Struct,) = (Struct{private: /**/()},);
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
33 // @has - '//*[@id="associatedconstant.STRUCT2"]' \
34 // 'const STRUCT2: Record = _'
35 const STRUCT2: Record = Record { public: 5 };
37 // Test that we do not show the incredibly verbose match expr:
39 // @has - '//*[@id="associatedconstant.MATCH0"]' \
40 // 'const MATCH0: i32 = _'
41 const MATCH0: i32 = match 234 {
46 // @has - '//*[@id="associatedconstant.MATCH1"]' \
47 // 'const MATCH1: bool = _'
48 const MATCH1: bool = match Self::ABSTRACT {
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.
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.
64 // @has - '//*[@id="associatedconstant.ARITH_OPS"]' \
65 // 'const ARITH_OPS: i32 = _'
66 const ARITH_OPS: i32 = Self::ABSTRACT * 2 + 1;
69 pub struct Struct { private: () }
71 pub struct Record { pub public: i32 }