From a4b7ed7a42c716ab9f05e351f003d589124fd55d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:18:58 +0200 Subject: Adding upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- tests/rustdoc/const-generics/add-impl.rs | 17 +++ .../const-generics/auxiliary/extern_crate.rs | 16 +++ .../const-generics/const-generic-defaults.rs | 5 + .../rustdoc/const-generics/const-generic-slice.rs | 11 ++ .../rustdoc/const-generics/const-generics-docs.rs | 128 +++++++++++++++++++++ tests/rustdoc/const-generics/const-impl.rs | 37 ++++++ .../rustdoc/const-generics/generic_const_exprs.rs | 7 ++ .../lazy_normalization_consts/const-equate-pred.rs | 18 +++ tests/rustdoc/const-generics/type-alias.rs | 4 + 9 files changed, 243 insertions(+) create mode 100644 tests/rustdoc/const-generics/add-impl.rs create mode 100644 tests/rustdoc/const-generics/auxiliary/extern_crate.rs create mode 100644 tests/rustdoc/const-generics/const-generic-defaults.rs create mode 100644 tests/rustdoc/const-generics/const-generic-slice.rs create mode 100644 tests/rustdoc/const-generics/const-generics-docs.rs create mode 100644 tests/rustdoc/const-generics/const-impl.rs create mode 100644 tests/rustdoc/const-generics/generic_const_exprs.rs create mode 100644 tests/rustdoc/const-generics/lazy_normalization_consts/const-equate-pred.rs create mode 100644 tests/rustdoc/const-generics/type-alias.rs (limited to 'tests/rustdoc/const-generics') diff --git a/tests/rustdoc/const-generics/add-impl.rs b/tests/rustdoc/const-generics/add-impl.rs new file mode 100644 index 000000000..b5226ad3f --- /dev/null +++ b/tests/rustdoc/const-generics/add-impl.rs @@ -0,0 +1,17 @@ +#![crate_name = "foo"] + +use std::ops::Add; + +// @has foo/struct.Simd.html '//div[@class="item-decl"]/pre[@class="rust"]' 'pub struct Simd' +pub struct Simd { + inner: T, +} + +// @has foo/struct.Simd.html '//div[@id="trait-implementations-list"]//h3[@class="code-header"]' 'impl Add> for Simd' +impl Add for Simd { + type Output = Self; + + fn add(self, rhs: Self) -> Self::Output { + Self { inner: 0 } + } +} diff --git a/tests/rustdoc/const-generics/auxiliary/extern_crate.rs b/tests/rustdoc/const-generics/auxiliary/extern_crate.rs new file mode 100644 index 000000000..55b632a48 --- /dev/null +++ b/tests/rustdoc/const-generics/auxiliary/extern_crate.rs @@ -0,0 +1,16 @@ +// edition:2018 +pub fn extern_fn() -> impl Iterator { + [[0; N]; N].iter().copied() +} + +pub struct ExternTy { + pub inner: [u8; N], +} + +pub type TyAlias = ExternTy; + +pub trait WTrait { + fn hey() -> usize { + N + M + P + } +} diff --git a/tests/rustdoc/const-generics/const-generic-defaults.rs b/tests/rustdoc/const-generics/const-generic-defaults.rs new file mode 100644 index 000000000..acc3b853e --- /dev/null +++ b/tests/rustdoc/const-generics/const-generic-defaults.rs @@ -0,0 +1,5 @@ +#![crate_name = "foo"] + +// @has foo/struct.Foo.html '//div[@class="item-decl"]/pre[@class="rust"]' \ +// 'pub struct Foo(_);' +pub struct Foo(T); diff --git a/tests/rustdoc/const-generics/const-generic-slice.rs b/tests/rustdoc/const-generics/const-generic-slice.rs new file mode 100644 index 000000000..4279de91f --- /dev/null +++ b/tests/rustdoc/const-generics/const-generic-slice.rs @@ -0,0 +1,11 @@ +#![crate_name = "foo"] + +pub trait Array { + type Item; +} + +// @has foo/trait.Array.html +// @has - '//*[@class="impl has-srclink"]' 'impl Array for [T; N]' +impl Array for [T; N] { + type Item = T; +} diff --git a/tests/rustdoc/const-generics/const-generics-docs.rs b/tests/rustdoc/const-generics/const-generics-docs.rs new file mode 100644 index 000000000..543332d2c --- /dev/null +++ b/tests/rustdoc/const-generics/const-generics-docs.rs @@ -0,0 +1,128 @@ +// edition:2018 +// aux-build: extern_crate.rs +#![crate_name = "foo"] + +extern crate extern_crate; +// @has foo/fn.extern_fn.html '//div[@class="item-decl"]/pre[@class="rust"]' \ +// 'pub fn extern_fn() -> impl Iterator' +pub use extern_crate::extern_fn; +// @has foo/struct.ExternTy.html '//div[@class="item-decl"]/pre[@class="rust"]' \ +// 'pub struct ExternTy {' +pub use extern_crate::ExternTy; +// @has foo/type.TyAlias.html '//div[@class="item-decl"]/pre[@class="rust"]' \ +// 'type TyAlias = ExternTy;' +pub use extern_crate::TyAlias; +// @has foo/trait.WTrait.html '//div[@class="item-decl"]/pre[@class="rust"]' \ +// 'pub trait WTrait' +// @has - '//div[@class="item-decl"]/pre[@class="rust"]' 'fn hey() -> usize' +pub use extern_crate::WTrait; + +// @has foo/trait.Trait.html '//div[@class="item-decl"]/pre[@class="rust"]' \ +// 'pub trait Trait' +// @has - '//*[@id="impl-Trait%3C1%3E-for-u8"]//h3[@class="code-header"]' 'impl Trait<1> for u8' +// @has - '//*[@id="impl-Trait%3C2%3E-for-u8"]//h3[@class="code-header"]' 'impl Trait<2> for u8' +// @has - '//*[@id="impl-Trait%3C{1%20+%202}%3E-for-u8"]//h3[@class="code-header"]' 'impl Trait<{1 + 2}> for u8' +// @has - '//*[@id="impl-Trait%3CN%3E-for-%5Bu8%3B%20N%5D"]//h3[@class="code-header"]' \ +// 'impl Trait for [u8; N]' +pub trait Trait {} +impl Trait<1> for u8 {} +impl Trait<2> for u8 {} +impl Trait<{1 + 2}> for u8 {} +impl Trait for [u8; N] {} + +// @has foo/struct.Foo.html '//div[@class="item-decl"]/pre[@class="rust"]' \ +// 'pub struct Foowhere u8: Trait' +pub struct Foo where u8: Trait; +// @has foo/struct.Bar.html '//div[@class="item-decl"]/pre[@class="rust"]' 'pub struct Bar(_)' +pub struct Bar([T; N]); + +// @has foo/struct.Foo.html '//*[@id="impl-Foo%3CM%3E"]/h3[@class="code-header"]' 'impl Foowhere u8: Trait' +impl Foo where u8: Trait { + // @has - '//*[@id="associatedconstant.FOO_ASSOC"]' 'pub const FOO_ASSOC: usize' + pub const FOO_ASSOC: usize = M + 13; + + // @has - '//*[@id="method.hey"]' 'pub fn hey(&self) -> Bar' + pub fn hey(&self) -> Bar { + Bar([0; N]) + } +} + +// @has foo/struct.Bar.html '//*[@id="impl-Bar%3Cu8%2C%20M%3E"]/h3[@class="code-header"]' 'impl Bar' +impl Bar { + // @has - '//*[@id="method.hey"]' \ + // 'pub fn hey(&self) -> Foowhere u8: Trait' + pub fn hey(&self) -> Foo where u8: Trait { + Foo + } +} + +// @has foo/fn.test.html '//div[@class="item-decl"]/pre[@class="rust"]' \ +// 'pub fn test() -> impl Traitwhere u8: Trait' +pub fn test() -> impl Trait where u8: Trait { + 2u8 +} + +// @has foo/fn.a_sink.html '//div[@class="item-decl"]/pre[@class="rust"]' \ +// 'pub async fn a_sink(v: [u8; N]) -> impl Trait' +pub async fn a_sink(v: [u8; N]) -> impl Trait { + v +} + +// @has foo/fn.b_sink.html '//div[@class="item-decl"]/pre[@class="rust"]' \ +// 'pub async fn b_sink(_: impl Trait)' +pub async fn b_sink(_: impl Trait) {} + +// @has foo/fn.concrete.html '//div[@class="item-decl"]/pre[@class="rust"]' \ +// 'pub fn concrete() -> [u8; 22]' +pub fn concrete() -> [u8; 3 + std::mem::size_of::() << 1] { + Default::default() +} + +// @has foo/type.Faz.html '//div[@class="item-decl"]/pre[@class="rust"]' \ +// 'type Faz = [u8; N];' +pub type Faz = [u8; N]; +// @has foo/type.Fiz.html '//div[@class="item-decl"]/pre[@class="rust"]' \ +// 'type Fiz = [[u8; N]; 48];' +pub type Fiz = [[u8; N]; 3 << 4]; + +macro_rules! define_me { + ($t:tt<$q:tt>) => { + pub struct $t([u8; $q]); + } +} + +// @has foo/struct.Foz.html '//div[@class="item-decl"]/pre[@class="rust"]' \ +// 'pub struct Foz(_);' +define_me!(Foz); + +trait Q { + const ASSOC: usize; +} + +impl Q for [u8; N] { + const ASSOC: usize = N; +} + +// @has foo/fn.q_user.html '//div[@class="item-decl"]/pre[@class="rust"]' \ +// 'pub fn q_user() -> [u8; 13]' +pub fn q_user() -> [u8; <[u8; 13] as Q>::ASSOC] { + [0; <[u8; 13] as Q>::ASSOC] +} + +// @has foo/union.Union.html '//div[@class="item-decl"]/pre[@class="rust"]' \ +// 'pub union Union' +pub union Union { + // @has - //pre "pub arr: [u8; N]" + pub arr: [u8; N], + // @has - //pre "pub another_arr: [(); N]" + pub another_arr: [(); N], +} + +// @has foo/enum.Enum.html '//div[@class="item-decl"]/pre[@class="rust"]' \ +// 'pub enum Enum' +pub enum Enum { + // @has - //pre "Variant([u8; N])" + Variant([u8; N]), + // @has - //pre "EmptyVariant" + EmptyVariant, +} diff --git a/tests/rustdoc/const-generics/const-impl.rs b/tests/rustdoc/const-generics/const-impl.rs new file mode 100644 index 000000000..726fb8f0c --- /dev/null +++ b/tests/rustdoc/const-generics/const-impl.rs @@ -0,0 +1,37 @@ +#![allow(incomplete_features)] +#![feature(adt_const_params)] +#![crate_name = "foo"] + +#[derive(PartialEq, Eq)] +pub enum Order { + Sorted, + Unsorted, +} + +// @has foo/struct.VSet.html '//div[@class="item-decl"]/pre[@class="rust"]' 'pub struct VSet' +// @has foo/struct.VSet.html '//*[@id="impl-Send-for-VSet%3CT%2C%20ORDER%3E"]/h3[@class="code-header"]' 'impl Send for VSet' +// @has foo/struct.VSet.html '//*[@id="impl-Sync-for-VSet%3CT%2C%20ORDER%3E"]/h3[@class="code-header"]' 'impl Sync for VSet' +pub struct VSet { + inner: Vec, +} + +// @has foo/struct.VSet.html '//*[@id="impl-VSet%3CT%2C%20{%20Order%3A%3ASorted%20}%3E"]/h3[@class="code-header"]' 'impl VSet' +impl VSet { + pub fn new() -> Self { + Self { inner: Vec::new() } + } +} + +// @has foo/struct.VSet.html '//*[@id="impl-VSet%3CT%2C%20{%20Order%3A%3AUnsorted%20}%3E"]/h3[@class="code-header"]' 'impl VSet' +impl VSet { + pub fn new() -> Self { + Self { inner: Vec::new() } + } +} + +pub struct Escape; + +// @has foo/struct.Escape.html '//*[@id="impl-Escape%3Cr#%22%3Cscript%3Ealert(%22Escape%22)%3B%3C/script%3E%22#%3E"]/h3[@class="code-header"]' 'impl Escapealert("Escape");"#>' +impl Escapealert("Escape");"#> { + pub fn f() {} +} diff --git a/tests/rustdoc/const-generics/generic_const_exprs.rs b/tests/rustdoc/const-generics/generic_const_exprs.rs new file mode 100644 index 000000000..c53cf6dcd --- /dev/null +++ b/tests/rustdoc/const-generics/generic_const_exprs.rs @@ -0,0 +1,7 @@ +#![crate_name = "foo"] +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] +// make sure that `ConstEvaluatable` predicates dont cause rustdoc to ICE #77647 +// @has foo/struct.Ice.html '//div[@class="item-decl"]/pre[@class="rust"]' \ +// 'pub struct Ice;' +pub struct Ice where [(); N + 1]:; diff --git a/tests/rustdoc/const-generics/lazy_normalization_consts/const-equate-pred.rs b/tests/rustdoc/const-generics/lazy_normalization_consts/const-equate-pred.rs new file mode 100644 index 000000000..310e89a35 --- /dev/null +++ b/tests/rustdoc/const-generics/lazy_normalization_consts/const-equate-pred.rs @@ -0,0 +1,18 @@ +#![crate_name = "foo"] +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +// Checking if `Send` is implemented for `Hasher` requires us to evaluate a `ConstEquate` predicate, +// which previously caused an ICE. + +pub struct Hasher { + cv_stack: T, +} + +unsafe impl Send for Hasher {} + +// @has foo/struct.Foo.html +// @has - '//h3[@class="code-header"]' 'impl Send for Foo' +pub struct Foo { + hasher: Hasher<[u8; 3]>, +} diff --git a/tests/rustdoc/const-generics/type-alias.rs b/tests/rustdoc/const-generics/type-alias.rs new file mode 100644 index 000000000..72473a112 --- /dev/null +++ b/tests/rustdoc/const-generics/type-alias.rs @@ -0,0 +1,4 @@ +#![crate_name = "foo"] + +// @has foo/type.CellIndex.html '//div[@class="item-decl"]/pre[@class="rust"]' 'type CellIndex = [i64; D];' +pub type CellIndex = [i64; D]; -- cgit v1.2.3