diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2025-05-05 17:01:08 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2025-05-05 17:47:18 +0200 |
| commit | b84f4cc39e99f801dcd37125dffa67eb796c85b8 (patch) | |
| tree | 071def2349dabae166fd66b06ee9346aa825abb9 /tests/rustdoc/hide-complex-unevaluated-const-arguments.rs | |
| parent | be71d8b24f1aebe9c45279d95a76db8fa6a62574 (diff) | |
| download | rust-b84f4cc39e99f801dcd37125dffa67eb796c85b8.tar.gz rust-b84f4cc39e99f801dcd37125dffa67eb796c85b8.zip | |
Created `tests/rustdoc/impl` subfolder to limit number of files at the top level
Diffstat (limited to 'tests/rustdoc/hide-complex-unevaluated-const-arguments.rs')
| -rw-r--r-- | tests/rustdoc/hide-complex-unevaluated-const-arguments.rs | 91 |
1 files changed, 0 insertions, 91 deletions
diff --git a/tests/rustdoc/hide-complex-unevaluated-const-arguments.rs b/tests/rustdoc/hide-complex-unevaluated-const-arguments.rs deleted file mode 100644 index e94c1ea5c61..00000000000 --- a/tests/rustdoc/hide-complex-unevaluated-const-arguments.rs +++ /dev/null @@ -1,91 +0,0 @@ -// Test that certain unevaluated constant expression arguments that are -// deemed too verbose or complex and that may leak private or -// `doc(hidden)` struct fields are not displayed in the documentation. -// -// Read the documentation of `rustdoc::clean::utils::print_const_expr` -// for further details. -#![feature(const_trait_impl, generic_const_exprs, adt_const_params, generic_const_items)] -#![allow(incomplete_features)] - -use std::marker::ConstParamTy; - -//@ has hide_complex_unevaluated_const_arguments/trait.Stage.html -pub trait Stage { - // A helper constant that prevents const expressions containing it - // from getting fully evaluated since it doesn't have a body and - // thus is non-reducible. This allows us to specifically test the - // pretty-printing of *unevaluated* consts. - const ABSTRACT: usize; - - // Currently considered "overly complex" by the `generic_const_exprs` - // feature. If / once this expression kind gets supported, this - // unevaluated const expression could leak the private struct field. - // - // FIXME: Once the line below compiles, make this a test that - // ensures that the private field is not printed. - // - //const ARRAY0: [u8; Struct { private: () } + Self::ABSTRACT]; - - // This assoc. const could leak the private assoc. function `Struct::new`. - // Ensure that this does not happen. - // - //@ has - '//*[@id="associatedconstant.ARRAY1"]' \ - // 'const ARRAY1: [u8; { _ }]' - const ARRAY1: [u8; Struct::new(/* ... */).do_something(Self::ABSTRACT * 1_000)] - where [(); Struct::new(/* ... */).do_something(Self::ABSTRACT * 1_000)]:; - - //@ has - '//*[@id="associatedconstant.VERBOSE"]' \ - // 'const VERBOSE: [u16; { _ }]' - const VERBOSE: [u16; compute("thing", 9 + 9) * Self::ABSTRACT] - where [(); compute("thing", 9 + 9) * Self::ABSTRACT]:; - - // Check that we do not leak the private struct field contained within - // the path. The output could definitely be improved upon - // (e.g. printing sth. akin to `<Self as Helper<{ _ }>>::OUT`) but - // right now “safe is safe”. - // - //@ has - '//*[@id="associatedconstant.PATH"]' \ - // 'const PATH: usize = _' - const PATH: usize = <Self as Helper<{ Struct { private: () } }>>::OUT; -} - -const fn compute(input: &str, extra: usize) -> usize { - input.len() + extra -} - -pub trait Helper<const S: Struct> { - const OUT: usize; -} - -impl<const S: Struct, St: Stage + ?Sized> Helper<S> for St { - const OUT: usize = St::ABSTRACT; -} - -// Currently in rustdoc, const arguments are not evaluated in this position -// and therefore they fall under the realm of `print_const_expr`. -// If rustdoc gets patched to evaluate const arguments, it is fine to replace -// this test as long as one can ensure that private fields are not leaked! -// -//@ has hide_complex_unevaluated_const_arguments/trait.Sub.html \ -// '//pre[@class="rust item-decl"]' \ -// 'pub trait Sub: Sup<{ _ }, { _ }> { }' -pub trait Sub: Sup<{ 90 * 20 * 4 }, { Struct { private: () } }> {} - -pub trait Sup<const N: usize, const S: Struct> {} - -#[derive(ConstParamTy, PartialEq, Eq)] -pub struct Struct { private: () } - -impl Struct { - const fn new() -> Self { Self { private: () } } - const fn do_something(self, x: usize) -> usize { - x - } -} -/* FIXME(const-trait): readd this -impl const std::ops::Add<usize> for Struct { - type Output = usize; - - fn add(self, _: usize) -> usize { 0 } -} -*/ |
