From 10c77b1cd0027926a966620c988a3af8643314f2 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 28 Apr 2023 12:54:26 -0700 Subject: rustdoc: move deref tests into a directory --- tests/rustdoc/deref-const-fn.rs | 38 ------- tests/rustdoc/deref-mut-methods.rs | 29 ----- tests/rustdoc/deref-recursive-pathbuf.rs | 25 ----- tests/rustdoc/deref-recursive.rs | 41 ------- tests/rustdoc/deref-slice-core.rs | 22 ---- tests/rustdoc/deref-to-primitive.rs | 15 --- tests/rustdoc/deref-typedef.rs | 46 -------- tests/rustdoc/deref/deref-const-fn.rs | 38 +++++++ tests/rustdoc/deref/deref-mut-methods.rs | 29 +++++ tests/rustdoc/deref/deref-recursive-pathbuf.rs | 25 +++++ tests/rustdoc/deref/deref-recursive.rs | 41 +++++++ tests/rustdoc/deref/deref-slice-core.rs | 22 ++++ tests/rustdoc/deref/deref-to-primitive.rs | 15 +++ tests/rustdoc/deref/deref-typedef.rs | 46 ++++++++ tests/rustdoc/deref/escape-deref-methods.rs | 35 ++++++ .../deref/issue-100679-sidebar-links-deref.rs | 30 ++++++ tests/rustdoc/deref/recursive-deref-sidebar.rs | 22 ++++ tests/rustdoc/deref/recursive-deref.rs | 120 +++++++++++++++++++++ tests/rustdoc/escape-deref-methods.rs | 35 ------ tests/rustdoc/issue-100679-sidebar-links-deref.rs | 30 ------ tests/rustdoc/recursive-deref-sidebar.rs | 22 ---- tests/rustdoc/recursive-deref.rs | 120 --------------------- 22 files changed, 423 insertions(+), 423 deletions(-) delete mode 100644 tests/rustdoc/deref-const-fn.rs delete mode 100644 tests/rustdoc/deref-mut-methods.rs delete mode 100644 tests/rustdoc/deref-recursive-pathbuf.rs delete mode 100644 tests/rustdoc/deref-recursive.rs delete mode 100644 tests/rustdoc/deref-slice-core.rs delete mode 100644 tests/rustdoc/deref-to-primitive.rs delete mode 100644 tests/rustdoc/deref-typedef.rs create mode 100644 tests/rustdoc/deref/deref-const-fn.rs create mode 100644 tests/rustdoc/deref/deref-mut-methods.rs create mode 100644 tests/rustdoc/deref/deref-recursive-pathbuf.rs create mode 100644 tests/rustdoc/deref/deref-recursive.rs create mode 100644 tests/rustdoc/deref/deref-slice-core.rs create mode 100644 tests/rustdoc/deref/deref-to-primitive.rs create mode 100644 tests/rustdoc/deref/deref-typedef.rs create mode 100644 tests/rustdoc/deref/escape-deref-methods.rs create mode 100644 tests/rustdoc/deref/issue-100679-sidebar-links-deref.rs create mode 100644 tests/rustdoc/deref/recursive-deref-sidebar.rs create mode 100644 tests/rustdoc/deref/recursive-deref.rs delete mode 100644 tests/rustdoc/escape-deref-methods.rs delete mode 100644 tests/rustdoc/issue-100679-sidebar-links-deref.rs delete mode 100644 tests/rustdoc/recursive-deref-sidebar.rs delete mode 100644 tests/rustdoc/recursive-deref.rs diff --git a/tests/rustdoc/deref-const-fn.rs b/tests/rustdoc/deref-const-fn.rs deleted file mode 100644 index 8ecca6d12d2..00000000000 --- a/tests/rustdoc/deref-const-fn.rs +++ /dev/null @@ -1,38 +0,0 @@ -// This test ensures that the const methods from Deref aren't shown as const. -// For more information, see https://github.com/rust-lang/rust/issues/90855. - -#![crate_name = "foo"] - -#![feature(staged_api)] - -#![stable(feature = "rust1", since = "1.0.0")] - -// @has 'foo/struct.Bar.html' -#[stable(feature = "rust1", since = "1.0.0")] -pub struct Bar; - -impl Bar { - // @has - '//*[@id="method.len"]' 'pub const fn len(&self) -> usize' - // @has - '//*[@id="method.len"]//span[@class="since"]' 'const: 1.0.0' - #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_stable(feature = "rust1", since = "1.0.0")] - pub const fn len(&self) -> usize { 0 } -} - -#[stable(feature = "rust1", since = "1.0.0")] -pub struct Foo { - value: Bar, -} - -// @has 'foo/struct.Foo.html' -// @has - '//*[@id="method.len"]' 'pub fn len(&self) -> usize' -// @!has - '//*[@id="method.len"]//span[@class="since"]' '1.0.0' -// @!has - '//*[@id="method.len"]//span[@class="since"]' '(const: 1.0.0)' -#[stable(feature = "rust1", since = "1.0.0")] -impl std::ops::Deref for Foo { - type Target = Bar; - - fn deref(&self) -> &Self::Target { - &self.value - } -} diff --git a/tests/rustdoc/deref-mut-methods.rs b/tests/rustdoc/deref-mut-methods.rs deleted file mode 100644 index fdf8434224f..00000000000 --- a/tests/rustdoc/deref-mut-methods.rs +++ /dev/null @@ -1,29 +0,0 @@ -#![crate_name = "foo"] - -use std::ops; - -pub struct Foo; - -impl Foo { - pub fn foo(&mut self) {} -} - -// @has foo/struct.Bar.html -// @has - '//*[@class="sidebar-elems"]//*[@class="block"]//a[@href="#method.foo"]' 'foo' -pub struct Bar { - foo: Foo, -} - -impl ops::Deref for Bar { - type Target = Foo; - - fn deref(&self) -> &Foo { - &self.foo - } -} - -impl ops::DerefMut for Bar { - fn deref_mut(&mut self) -> &mut Foo { - &mut self.foo - } -} diff --git a/tests/rustdoc/deref-recursive-pathbuf.rs b/tests/rustdoc/deref-recursive-pathbuf.rs deleted file mode 100644 index be2b42b5ac6..00000000000 --- a/tests/rustdoc/deref-recursive-pathbuf.rs +++ /dev/null @@ -1,25 +0,0 @@ -// #26207: Show all methods reachable via Deref impls, recursing through multiple dereferencing -// levels and across multiple crates. -// For `Deref` on non-foreign types, look at `deref-recursive.rs`. - -// @has 'foo/struct.Foo.html' -// @has '-' '//*[@id="deref-methods-PathBuf"]' 'Methods from Deref' -// @has '-' '//*[@class="impl-items"]//*[@id="method.as_path"]' 'pub fn as_path(&self)' -// @has '-' '//*[@id="deref-methods-Path"]' 'Methods from Deref' -// @has '-' '//*[@class="impl-items"]//*[@id="method.exists"]' 'pub fn exists(&self)' -// @has '-' '//div[@class="sidebar-elems"]//h3/a[@href="#deref-methods-PathBuf"]' 'Methods from Deref' -// @has '-' '//*[@class="sidebar-elems"]//*[@class="block"]//a[@href="#method.as_path"]' 'as_path' -// @has '-' '//div[@class="sidebar-elems"]//h3/a[@href="#deref-methods-Path"]' 'Methods from Deref' -// @has '-' '//*[@class="sidebar-elems"]//*[@class="block"]//a[@href="#method.exists"]' 'exists' - -#![crate_name = "foo"] - -use std::ops::Deref; -use std::path::PathBuf; - -pub struct Foo(PathBuf); - -impl Deref for Foo { - type Target = PathBuf; - fn deref(&self) -> &PathBuf { &self.0 } -} diff --git a/tests/rustdoc/deref-recursive.rs b/tests/rustdoc/deref-recursive.rs deleted file mode 100644 index 0436f2f86f5..00000000000 --- a/tests/rustdoc/deref-recursive.rs +++ /dev/null @@ -1,41 +0,0 @@ -// #26207: Show all methods reachable via Deref impls, recursing through multiple dereferencing -// levels if needed. -// For `Deref` on foreign types, look at `deref-recursive-pathbuf.rs`. - -// @has 'foo/struct.Foo.html' -// @has '-' '//*[@id="deref-methods-Bar"]' 'Methods from Deref' -// @has '-' '//*[@class="impl-items"]//*[@id="method.bar"]' 'pub fn bar(&self)' -// @has '-' '//*[@id="deref-methods-Baz"]' 'Methods from Deref' -// @has '-' '//*[@class="impl-items"]//*[@id="method.baz"]' 'pub fn baz(&self)' -// @has '-' '//div[@class="sidebar-elems"]//h3/a[@href="#deref-methods-Bar"]' 'Methods from Deref' -// @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.bar"]' 'bar' -// @has '-' '//div[@class="sidebar-elems"]//h3/a[@href="#deref-methods-Baz"]' 'Methods from Deref' -// @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.baz"]' 'baz' - -#![crate_name = "foo"] - -use std::ops::Deref; - -pub struct Foo(Bar); -pub struct Bar(Baz); -pub struct Baz; - -impl Deref for Foo { - type Target = Bar; - fn deref(&self) -> &Bar { &self.0 } -} - -impl Deref for Bar { - type Target = Baz; - fn deref(&self) -> &Baz { &self.0 } -} - -impl Bar { - /// This appears under `Foo` methods - pub fn bar(&self) {} -} - -impl Baz { - /// This should also appear in `Foo` methods when recursing - pub fn baz(&self) {} -} diff --git a/tests/rustdoc/deref-slice-core.rs b/tests/rustdoc/deref-slice-core.rs deleted file mode 100644 index cccf273a820..00000000000 --- a/tests/rustdoc/deref-slice-core.rs +++ /dev/null @@ -1,22 +0,0 @@ -// https://github.com/rust-lang/rust/issues/95325 -// -// Show methods reachable from Deref of primitive. -#![no_std] - -use core::ops::Deref; - -// @has 'deref_slice_core/struct.MyArray.html' -// @has '-' '//*[@id="deref-methods-%5BT%5D"]' 'Methods from Deref' -// @has '-' '//*[@class="impl-items"]//*[@id="method.len"]' 'pub fn len(&self)' - -pub struct MyArray { - array: [T; 10], -} - -impl Deref for MyArray { - type Target = [T]; - - fn deref(&self) -> &Self::Target { - &self.array - } -} diff --git a/tests/rustdoc/deref-to-primitive.rs b/tests/rustdoc/deref-to-primitive.rs deleted file mode 100644 index 527de780d48..00000000000 --- a/tests/rustdoc/deref-to-primitive.rs +++ /dev/null @@ -1,15 +0,0 @@ -#![crate_name = "foo"] - -// @has 'foo/struct.Foo.html' -// @has - '//*[@id="deref-methods-i32"]' 'Methods from Deref' -// @has - '//*[@id="deref-methods-i32-1"]//*[@id="associatedconstant.BITS"]/h4' \ -// 'pub const BITS: u32 = 32u32' -pub struct Foo(i32); - -impl std::ops::Deref for Foo { - type Target = i32; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} diff --git a/tests/rustdoc/deref-typedef.rs b/tests/rustdoc/deref-typedef.rs deleted file mode 100644 index 32424d13eb8..00000000000 --- a/tests/rustdoc/deref-typedef.rs +++ /dev/null @@ -1,46 +0,0 @@ -#![crate_name = "foo"] - -// @has 'foo/struct.Bar.html' -// @has '-' '//*[@id="deref-methods-FooJ"]' 'Methods from Deref' -// @has '-' '//*[@class="impl-items"]//*[@id="method.foo_a"]' 'pub fn foo_a(&self)' -// @has '-' '//*[@class="impl-items"]//*[@id="method.foo_b"]' 'pub fn foo_b(&self)' -// @has '-' '//*[@class="impl-items"]//*[@id="method.foo_c"]' 'pub fn foo_c(&self)' -// @has '-' '//*[@class="impl-items"]//*[@id="method.foo_j"]' 'pub fn foo_j(&self)' -// @has '-' '//div[@class="sidebar-elems"]//h3/a[@href="#deref-methods-FooJ"]' 'Methods from Deref' -// @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.foo_a"]' 'foo_a' -// @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.foo_b"]' 'foo_b' -// @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.foo_c"]' 'foo_c' -// @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.foo_j"]' 'foo_j' - -pub struct FooA; -pub type FooB = FooA; -pub type FooC = FooB; -pub type FooD = FooC; -pub type FooE = FooD; -pub type FooF = FooE; -pub type FooG = FooF; -pub type FooH = FooG; -pub type FooI = FooH; -pub type FooJ = FooI; - -impl FooA { - pub fn foo_a(&self) {} -} - -impl FooB { - pub fn foo_b(&self) {} -} - -impl FooC { - pub fn foo_c(&self) {} -} - -impl FooJ { - pub fn foo_j(&self) {} -} - -pub struct Bar; -impl std::ops::Deref for Bar { - type Target = FooJ; - fn deref(&self) -> &Self::Target { unimplemented!() } -} diff --git a/tests/rustdoc/deref/deref-const-fn.rs b/tests/rustdoc/deref/deref-const-fn.rs new file mode 100644 index 00000000000..8ecca6d12d2 --- /dev/null +++ b/tests/rustdoc/deref/deref-const-fn.rs @@ -0,0 +1,38 @@ +// This test ensures that the const methods from Deref aren't shown as const. +// For more information, see https://github.com/rust-lang/rust/issues/90855. + +#![crate_name = "foo"] + +#![feature(staged_api)] + +#![stable(feature = "rust1", since = "1.0.0")] + +// @has 'foo/struct.Bar.html' +#[stable(feature = "rust1", since = "1.0.0")] +pub struct Bar; + +impl Bar { + // @has - '//*[@id="method.len"]' 'pub const fn len(&self) -> usize' + // @has - '//*[@id="method.len"]//span[@class="since"]' 'const: 1.0.0' + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "rust1", since = "1.0.0")] + pub const fn len(&self) -> usize { 0 } +} + +#[stable(feature = "rust1", since = "1.0.0")] +pub struct Foo { + value: Bar, +} + +// @has 'foo/struct.Foo.html' +// @has - '//*[@id="method.len"]' 'pub fn len(&self) -> usize' +// @!has - '//*[@id="method.len"]//span[@class="since"]' '1.0.0' +// @!has - '//*[@id="method.len"]//span[@class="since"]' '(const: 1.0.0)' +#[stable(feature = "rust1", since = "1.0.0")] +impl std::ops::Deref for Foo { + type Target = Bar; + + fn deref(&self) -> &Self::Target { + &self.value + } +} diff --git a/tests/rustdoc/deref/deref-mut-methods.rs b/tests/rustdoc/deref/deref-mut-methods.rs new file mode 100644 index 00000000000..fdf8434224f --- /dev/null +++ b/tests/rustdoc/deref/deref-mut-methods.rs @@ -0,0 +1,29 @@ +#![crate_name = "foo"] + +use std::ops; + +pub struct Foo; + +impl Foo { + pub fn foo(&mut self) {} +} + +// @has foo/struct.Bar.html +// @has - '//*[@class="sidebar-elems"]//*[@class="block"]//a[@href="#method.foo"]' 'foo' +pub struct Bar { + foo: Foo, +} + +impl ops::Deref for Bar { + type Target = Foo; + + fn deref(&self) -> &Foo { + &self.foo + } +} + +impl ops::DerefMut for Bar { + fn deref_mut(&mut self) -> &mut Foo { + &mut self.foo + } +} diff --git a/tests/rustdoc/deref/deref-recursive-pathbuf.rs b/tests/rustdoc/deref/deref-recursive-pathbuf.rs new file mode 100644 index 00000000000..be2b42b5ac6 --- /dev/null +++ b/tests/rustdoc/deref/deref-recursive-pathbuf.rs @@ -0,0 +1,25 @@ +// #26207: Show all methods reachable via Deref impls, recursing through multiple dereferencing +// levels and across multiple crates. +// For `Deref` on non-foreign types, look at `deref-recursive.rs`. + +// @has 'foo/struct.Foo.html' +// @has '-' '//*[@id="deref-methods-PathBuf"]' 'Methods from Deref' +// @has '-' '//*[@class="impl-items"]//*[@id="method.as_path"]' 'pub fn as_path(&self)' +// @has '-' '//*[@id="deref-methods-Path"]' 'Methods from Deref' +// @has '-' '//*[@class="impl-items"]//*[@id="method.exists"]' 'pub fn exists(&self)' +// @has '-' '//div[@class="sidebar-elems"]//h3/a[@href="#deref-methods-PathBuf"]' 'Methods from Deref' +// @has '-' '//*[@class="sidebar-elems"]//*[@class="block"]//a[@href="#method.as_path"]' 'as_path' +// @has '-' '//div[@class="sidebar-elems"]//h3/a[@href="#deref-methods-Path"]' 'Methods from Deref' +// @has '-' '//*[@class="sidebar-elems"]//*[@class="block"]//a[@href="#method.exists"]' 'exists' + +#![crate_name = "foo"] + +use std::ops::Deref; +use std::path::PathBuf; + +pub struct Foo(PathBuf); + +impl Deref for Foo { + type Target = PathBuf; + fn deref(&self) -> &PathBuf { &self.0 } +} diff --git a/tests/rustdoc/deref/deref-recursive.rs b/tests/rustdoc/deref/deref-recursive.rs new file mode 100644 index 00000000000..0436f2f86f5 --- /dev/null +++ b/tests/rustdoc/deref/deref-recursive.rs @@ -0,0 +1,41 @@ +// #26207: Show all methods reachable via Deref impls, recursing through multiple dereferencing +// levels if needed. +// For `Deref` on foreign types, look at `deref-recursive-pathbuf.rs`. + +// @has 'foo/struct.Foo.html' +// @has '-' '//*[@id="deref-methods-Bar"]' 'Methods from Deref' +// @has '-' '//*[@class="impl-items"]//*[@id="method.bar"]' 'pub fn bar(&self)' +// @has '-' '//*[@id="deref-methods-Baz"]' 'Methods from Deref' +// @has '-' '//*[@class="impl-items"]//*[@id="method.baz"]' 'pub fn baz(&self)' +// @has '-' '//div[@class="sidebar-elems"]//h3/a[@href="#deref-methods-Bar"]' 'Methods from Deref' +// @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.bar"]' 'bar' +// @has '-' '//div[@class="sidebar-elems"]//h3/a[@href="#deref-methods-Baz"]' 'Methods from Deref' +// @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.baz"]' 'baz' + +#![crate_name = "foo"] + +use std::ops::Deref; + +pub struct Foo(Bar); +pub struct Bar(Baz); +pub struct Baz; + +impl Deref for Foo { + type Target = Bar; + fn deref(&self) -> &Bar { &self.0 } +} + +impl Deref for Bar { + type Target = Baz; + fn deref(&self) -> &Baz { &self.0 } +} + +impl Bar { + /// This appears under `Foo` methods + pub fn bar(&self) {} +} + +impl Baz { + /// This should also appear in `Foo` methods when recursing + pub fn baz(&self) {} +} diff --git a/tests/rustdoc/deref/deref-slice-core.rs b/tests/rustdoc/deref/deref-slice-core.rs new file mode 100644 index 00000000000..cccf273a820 --- /dev/null +++ b/tests/rustdoc/deref/deref-slice-core.rs @@ -0,0 +1,22 @@ +// https://github.com/rust-lang/rust/issues/95325 +// +// Show methods reachable from Deref of primitive. +#![no_std] + +use core::ops::Deref; + +// @has 'deref_slice_core/struct.MyArray.html' +// @has '-' '//*[@id="deref-methods-%5BT%5D"]' 'Methods from Deref' +// @has '-' '//*[@class="impl-items"]//*[@id="method.len"]' 'pub fn len(&self)' + +pub struct MyArray { + array: [T; 10], +} + +impl Deref for MyArray { + type Target = [T]; + + fn deref(&self) -> &Self::Target { + &self.array + } +} diff --git a/tests/rustdoc/deref/deref-to-primitive.rs b/tests/rustdoc/deref/deref-to-primitive.rs new file mode 100644 index 00000000000..527de780d48 --- /dev/null +++ b/tests/rustdoc/deref/deref-to-primitive.rs @@ -0,0 +1,15 @@ +#![crate_name = "foo"] + +// @has 'foo/struct.Foo.html' +// @has - '//*[@id="deref-methods-i32"]' 'Methods from Deref' +// @has - '//*[@id="deref-methods-i32-1"]//*[@id="associatedconstant.BITS"]/h4' \ +// 'pub const BITS: u32 = 32u32' +pub struct Foo(i32); + +impl std::ops::Deref for Foo { + type Target = i32; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} diff --git a/tests/rustdoc/deref/deref-typedef.rs b/tests/rustdoc/deref/deref-typedef.rs new file mode 100644 index 00000000000..32424d13eb8 --- /dev/null +++ b/tests/rustdoc/deref/deref-typedef.rs @@ -0,0 +1,46 @@ +#![crate_name = "foo"] + +// @has 'foo/struct.Bar.html' +// @has '-' '//*[@id="deref-methods-FooJ"]' 'Methods from Deref' +// @has '-' '//*[@class="impl-items"]//*[@id="method.foo_a"]' 'pub fn foo_a(&self)' +// @has '-' '//*[@class="impl-items"]//*[@id="method.foo_b"]' 'pub fn foo_b(&self)' +// @has '-' '//*[@class="impl-items"]//*[@id="method.foo_c"]' 'pub fn foo_c(&self)' +// @has '-' '//*[@class="impl-items"]//*[@id="method.foo_j"]' 'pub fn foo_j(&self)' +// @has '-' '//div[@class="sidebar-elems"]//h3/a[@href="#deref-methods-FooJ"]' 'Methods from Deref' +// @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.foo_a"]' 'foo_a' +// @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.foo_b"]' 'foo_b' +// @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.foo_c"]' 'foo_c' +// @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.foo_j"]' 'foo_j' + +pub struct FooA; +pub type FooB = FooA; +pub type FooC = FooB; +pub type FooD = FooC; +pub type FooE = FooD; +pub type FooF = FooE; +pub type FooG = FooF; +pub type FooH = FooG; +pub type FooI = FooH; +pub type FooJ = FooI; + +impl FooA { + pub fn foo_a(&self) {} +} + +impl FooB { + pub fn foo_b(&self) {} +} + +impl FooC { + pub fn foo_c(&self) {} +} + +impl FooJ { + pub fn foo_j(&self) {} +} + +pub struct Bar; +impl std::ops::Deref for Bar { + type Target = FooJ; + fn deref(&self) -> &Self::Target { unimplemented!() } +} diff --git a/tests/rustdoc/deref/escape-deref-methods.rs b/tests/rustdoc/deref/escape-deref-methods.rs new file mode 100644 index 00000000000..66919d73eeb --- /dev/null +++ b/tests/rustdoc/deref/escape-deref-methods.rs @@ -0,0 +1,35 @@ +#![crate_name = "foo"] + +use std::ops::{Deref, DerefMut}; + +#[derive(Debug, Clone)] +pub struct Title { + name: String, +} + +#[derive(Debug, Clone)] +pub struct TitleList { + pub members: Vec, +} + +impl TitleList { + pub fn new() -> Self { + TitleList { members: Vec::new() } + } +} + +impl Deref for TitleList { + type Target = Vec<Title>; + + fn deref(&self) -> &Self::Target { + &self.members + } +} + +// @has foo/struct.TitleList.html +// @has - '//div[@class="sidebar-elems"]//h3' 'Methods from Deref<Target=Vec<Title>>' +impl DerefMut for TitleList { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.members + } +} diff --git a/tests/rustdoc/deref/issue-100679-sidebar-links-deref.rs b/tests/rustdoc/deref/issue-100679-sidebar-links-deref.rs new file mode 100644 index 00000000000..f09d2320609 --- /dev/null +++ b/tests/rustdoc/deref/issue-100679-sidebar-links-deref.rs @@ -0,0 +1,30 @@ +#![crate_name="foo"] + +pub struct Vec; + +pub struct Slice; + +impl std::ops::Deref for Vec { + type Target = Slice; + fn deref(&self) -> &Slice { + &Slice + } +} + +// @has foo/struct.Vec.html '//*[@class="sidebar-elems"]//section//li/a[@href="#method.is_empty"]' \ +// "is_empty" +impl Vec { + pub fn is_empty(&self) -> bool { + true + } +} + +// @has foo/struct.Vec.html '//*[@class="sidebar-elems"]//section//li/a[@href="#method.is_empty-1"]' \ +// "is_empty" +// @has foo/struct.Slice.html '//*[@class="sidebar-elems"]//section//li/a[@href="#method.is_empty"]' \ +// "is_empty" +impl Slice { + pub fn is_empty(&self) -> bool { + true + } +} diff --git a/tests/rustdoc/deref/recursive-deref-sidebar.rs b/tests/rustdoc/deref/recursive-deref-sidebar.rs new file mode 100644 index 00000000000..619f40eff89 --- /dev/null +++ b/tests/rustdoc/deref/recursive-deref-sidebar.rs @@ -0,0 +1,22 @@ +use std::ops::Deref; + +pub struct A {} +impl A { pub fn foo_a(&self) {} } + +pub struct B {} +impl B { pub fn foo_b(&self) {} } + +pub struct C {} +impl C { pub fn foo_c(&self) {} } + +// @has recursive_deref_sidebar/struct.A.html '//*[@class="sidebar-elems"]//section' 'foo_b' +impl Deref for A { + type Target = B; + fn deref(&self) -> &B { todo!() } +} + +// @has recursive_deref_sidebar/struct.A.html '//*[@class="sidebar-elems"]//section' 'foo_c' +impl Deref for B { + type Target = C; + fn deref(&self) -> &C { todo!() } +} diff --git a/tests/rustdoc/deref/recursive-deref.rs b/tests/rustdoc/deref/recursive-deref.rs new file mode 100644 index 00000000000..aa38485c445 --- /dev/null +++ b/tests/rustdoc/deref/recursive-deref.rs @@ -0,0 +1,120 @@ +use std::ops::Deref; + +// Cyclic deref with the parent (which is not the top parent). +pub struct A; +pub struct B; +pub struct C; + +impl C { + pub fn c(&self) {} +} + +// @has recursive_deref/struct.A.html '//h3[@class="code-header"]' 'impl Deref for A' +// @has '-' '//*[@class="impl-items"]//*[@id="method.c"]' 'pub fn c(&self)' +impl Deref for A { + type Target = B; + + fn deref(&self) -> &Self::Target { + panic!() + } +} + +// @has recursive_deref/struct.B.html '//h3[@class="code-header"]' 'impl Deref for B' +// @has '-' '//*[@class="impl-items"]//*[@id="method.c"]' 'pub fn c(&self)' +impl Deref for B { + type Target = C; + + fn deref(&self) -> &Self::Target { + panic!() + } +} + +// @has recursive_deref/struct.C.html '//h3[@class="code-header"]' 'impl Deref for C' +impl Deref for C { + type Target = B; + + fn deref(&self) -> &Self::Target { + panic!() + } +} + +// Cyclic deref with the grand-parent (which is not the top parent). +pub struct D; +pub struct E; +pub struct F; +pub struct G; + +impl G { + // There is no "self" parameter so it shouldn't be listed! + pub fn g() {} +} + +// @has recursive_deref/struct.D.html '//h3[@class="code-header"]' 'impl Deref for D' +// We also check that `G::g` method isn't rendered because there is no `self` argument. +// @!has '-' '//*[@id="deref-methods-G"]' '' +impl Deref for D { + type Target = E; + + fn deref(&self) -> &Self::Target { + panic!() + } +} + +// @has recursive_deref/struct.E.html '//h3[@class="code-header"]' 'impl Deref for E' +// We also check that `G::g` method isn't rendered because there is no `self` argument. +// @!has '-' '//*[@id="deref-methods-G"]' '' +impl Deref for E { + type Target = F; + + fn deref(&self) -> &Self::Target { + panic!() + } +} + +// @has recursive_deref/struct.F.html '//h3[@class="code-header"]' 'impl Deref for F' +// We also check that `G::g` method isn't rendered because there is no `self` argument. +// @!has '-' '//*[@id="deref-methods-G"]' '' +impl Deref for F { + type Target = G; + + fn deref(&self) -> &Self::Target { + panic!() + } +} + +// @has recursive_deref/struct.G.html '//h3[@class="code-header"]' 'impl Deref for G' +impl Deref for G { + type Target = E; + + fn deref(&self) -> &Self::Target { + panic!() + } +} + +// Cyclic deref with top parent. +pub struct H; +pub struct I; + +impl I { + // There is no "self" parameter so it shouldn't be listed! + pub fn i() {} +} + +// @has recursive_deref/struct.H.html '//h3[@class="code-header"]' 'impl Deref for H' +// @!has '-' '//*[@id="deref-methods-I"]' '' +impl Deref for H { + type Target = I; + + fn deref(&self) -> &Self::Target { + panic!() + } +} + +// @has recursive_deref/struct.I.html '//h3[@class="code-header"]' 'impl Deref for I' +impl Deref for I { + type Target = H; + + fn deref(&self) -> &Self::Target { + panic!() + } +} diff --git a/tests/rustdoc/escape-deref-methods.rs b/tests/rustdoc/escape-deref-methods.rs deleted file mode 100644 index 66919d73eeb..00000000000 --- a/tests/rustdoc/escape-deref-methods.rs +++ /dev/null @@ -1,35 +0,0 @@ -#![crate_name = "foo"] - -use std::ops::{Deref, DerefMut}; - -#[derive(Debug, Clone)] -pub struct Title { - name: String, -} - -#[derive(Debug, Clone)] -pub struct TitleList { - pub members: Vec<Title>, -} - -impl TitleList { - pub fn new() -> Self { - TitleList { members: Vec::new() } - } -} - -impl Deref for TitleList { - type Target = Vec<Title>; - - fn deref(&self) -> &Self::Target { - &self.members - } -} - -// @has foo/struct.TitleList.html -// @has - '//div[@class="sidebar-elems"]//h3' 'Methods from Deref<Target=Vec<Title>>' -impl DerefMut for TitleList { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.members - } -} diff --git a/tests/rustdoc/issue-100679-sidebar-links-deref.rs b/tests/rustdoc/issue-100679-sidebar-links-deref.rs deleted file mode 100644 index f09d2320609..00000000000 --- a/tests/rustdoc/issue-100679-sidebar-links-deref.rs +++ /dev/null @@ -1,30 +0,0 @@ -#![crate_name="foo"] - -pub struct Vec; - -pub struct Slice; - -impl std::ops::Deref for Vec { - type Target = Slice; - fn deref(&self) -> &Slice { - &Slice - } -} - -// @has foo/struct.Vec.html '//*[@class="sidebar-elems"]//section//li/a[@href="#method.is_empty"]' \ -// "is_empty" -impl Vec { - pub fn is_empty(&self) -> bool { - true - } -} - -// @has foo/struct.Vec.html '//*[@class="sidebar-elems"]//section//li/a[@href="#method.is_empty-1"]' \ -// "is_empty" -// @has foo/struct.Slice.html '//*[@class="sidebar-elems"]//section//li/a[@href="#method.is_empty"]' \ -// "is_empty" -impl Slice { - pub fn is_empty(&self) -> bool { - true - } -} diff --git a/tests/rustdoc/recursive-deref-sidebar.rs b/tests/rustdoc/recursive-deref-sidebar.rs deleted file mode 100644 index 619f40eff89..00000000000 --- a/tests/rustdoc/recursive-deref-sidebar.rs +++ /dev/null @@ -1,22 +0,0 @@ -use std::ops::Deref; - -pub struct A {} -impl A { pub fn foo_a(&self) {} } - -pub struct B {} -impl B { pub fn foo_b(&self) {} } - -pub struct C {} -impl C { pub fn foo_c(&self) {} } - -// @has recursive_deref_sidebar/struct.A.html '//*[@class="sidebar-elems"]//section' 'foo_b' -impl Deref for A { - type Target = B; - fn deref(&self) -> &B { todo!() } -} - -// @has recursive_deref_sidebar/struct.A.html '//*[@class="sidebar-elems"]//section' 'foo_c' -impl Deref for B { - type Target = C; - fn deref(&self) -> &C { todo!() } -} diff --git a/tests/rustdoc/recursive-deref.rs b/tests/rustdoc/recursive-deref.rs deleted file mode 100644 index aa38485c445..00000000000 --- a/tests/rustdoc/recursive-deref.rs +++ /dev/null @@ -1,120 +0,0 @@ -use std::ops::Deref; - -// Cyclic deref with the parent (which is not the top parent). -pub struct A; -pub struct B; -pub struct C; - -impl C { - pub fn c(&self) {} -} - -// @has recursive_deref/struct.A.html '//h3[@class="code-header"]' 'impl Deref for A' -// @has '-' '//*[@class="impl-items"]//*[@id="method.c"]' 'pub fn c(&self)' -impl Deref for A { - type Target = B; - - fn deref(&self) -> &Self::Target { - panic!() - } -} - -// @has recursive_deref/struct.B.html '//h3[@class="code-header"]' 'impl Deref for B' -// @has '-' '//*[@class="impl-items"]//*[@id="method.c"]' 'pub fn c(&self)' -impl Deref for B { - type Target = C; - - fn deref(&self) -> &Self::Target { - panic!() - } -} - -// @has recursive_deref/struct.C.html '//h3[@class="code-header"]' 'impl Deref for C' -impl Deref for C { - type Target = B; - - fn deref(&self) -> &Self::Target { - panic!() - } -} - -// Cyclic deref with the grand-parent (which is not the top parent). -pub struct D; -pub struct E; -pub struct F; -pub struct G; - -impl G { - // There is no "self" parameter so it shouldn't be listed! - pub fn g() {} -} - -// @has recursive_deref/struct.D.html '//h3[@class="code-header"]' 'impl Deref for D' -// We also check that `G::g` method isn't rendered because there is no `self` argument. -// @!has '-' '//*[@id="deref-methods-G"]' '' -impl Deref for D { - type Target = E; - - fn deref(&self) -> &Self::Target { - panic!() - } -} - -// @has recursive_deref/struct.E.html '//h3[@class="code-header"]' 'impl Deref for E' -// We also check that `G::g` method isn't rendered because there is no `self` argument. -// @!has '-' '//*[@id="deref-methods-G"]' '' -impl Deref for E { - type Target = F; - - fn deref(&self) -> &Self::Target { - panic!() - } -} - -// @has recursive_deref/struct.F.html '//h3[@class="code-header"]' 'impl Deref for F' -// We also check that `G::g` method isn't rendered because there is no `self` argument. -// @!has '-' '//*[@id="deref-methods-G"]' '' -impl Deref for F { - type Target = G; - - fn deref(&self) -> &Self::Target { - panic!() - } -} - -// @has recursive_deref/struct.G.html '//h3[@class="code-header"]' 'impl Deref for G' -impl Deref for G { - type Target = E; - - fn deref(&self) -> &Self::Target { - panic!() - } -} - -// Cyclic deref with top parent. -pub struct H; -pub struct I; - -impl I { - // There is no "self" parameter so it shouldn't be listed! - pub fn i() {} -} - -// @has recursive_deref/struct.H.html '//h3[@class="code-header"]' 'impl Deref for H' -// @!has '-' '//*[@id="deref-methods-I"]' '' -impl Deref for H { - type Target = I; - - fn deref(&self) -> &Self::Target { - panic!() - } -} - -// @has recursive_deref/struct.I.html '//h3[@class="code-header"]' 'impl Deref for I' -impl Deref for I { - type Target = H; - - fn deref(&self) -> &Self::Target { - panic!() - } -} -- cgit 1.4.1-3-g733a5 From 2299ba1ca2afdf56000017c70572ed181e174c37 Mon Sep 17 00:00:00 2001 From: Michael Howell <michael@notriddle.com> Date: Fri, 28 Apr 2023 13:10:25 -0700 Subject: rustdoc: fix weird margins between Deref impl items In the old setup, if the dereffed-to item has multiple impl blocks, each one gets its own `div.impl-items` in the section, but there are no headers separating them. Since the last method in a `div.impl-items` has no bottom margin, and there are no margins between these divs, there is no margin between the last method of one impl and the first method of the following impl. This patch fixes it by simplifying the HTML. Each Deref block gets exactly one `div.impl-items`, no matter how many impl blocks it actually has. --- src/librustdoc/html/render/mod.rs | 18 ++++++---- tests/rustdoc/deref/deref-multiple-impl-blocks.rs | 43 +++++++++++++++++++++++ 2 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 tests/rustdoc/deref/deref-multiple-impl-blocks.rs diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index a5f08fdac11..d90d0aecb93 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1155,10 +1155,10 @@ fn render_assoc_items_inner( let (non_trait, traits): (Vec<_>, _) = v.iter().partition(|i| i.inner_impl().trait_.is_none()); if !non_trait.is_empty() { let mut tmp_buf = Buffer::html(); - let (render_mode, id) = match what { + let (render_mode, id, class_html) = match what { AssocItemRender::All => { write_impl_section_heading(&mut tmp_buf, "Implementations", "implementations"); - (RenderMode::Normal, "implementations-list".to_owned()) + (RenderMode::Normal, "implementations-list".to_owned(), "") } AssocItemRender::DerefFor { trait_, type_, deref_mut_ } => { let id = @@ -1175,7 +1175,11 @@ fn render_assoc_items_inner( ), &id, ); - (RenderMode::ForDeref { mut_: deref_mut_ }, cx.derive_id(id)) + ( + RenderMode::ForDeref { mut_: deref_mut_ }, + cx.derive_id(id), + r#" class="impl-items""#, + ) } }; let mut impls_buf = Buffer::html(); @@ -1199,7 +1203,7 @@ fn render_assoc_items_inner( } if !impls_buf.is_empty() { write!(w, "{}", tmp_buf.into_inner()).unwrap(); - write!(w, "<div id=\"{}\">", id).unwrap(); + write!(w, "<div id=\"{id}\"{class_html}>").unwrap(); write!(w, "{}", impls_buf.into_inner()).unwrap(); w.write_str("</div>").unwrap(); } @@ -1788,12 +1792,14 @@ fn render_impl( .into_string() ); } + if !default_impl_items.is_empty() || !impl_items.is_empty() { + w.write_str("<div class=\"impl-items\">"); + close_tags.insert_str(0, "</div>"); + } } if !default_impl_items.is_empty() || !impl_items.is_empty() { - w.write_str("<div class=\"impl-items\">"); w.push_buffer(default_impl_items); w.push_buffer(impl_items); - close_tags.insert_str(0, "</div>"); } w.write_str(&close_tags); } diff --git a/tests/rustdoc/deref/deref-multiple-impl-blocks.rs b/tests/rustdoc/deref/deref-multiple-impl-blocks.rs new file mode 100644 index 00000000000..fa3607c5fc1 --- /dev/null +++ b/tests/rustdoc/deref/deref-multiple-impl-blocks.rs @@ -0,0 +1,43 @@ +#![crate_name="foo"] + +use std::ops::{Deref, DerefMut}; + +// @has foo/struct.Vec.html +// @count - '//h2[@id="deref-methods-Slice"]' 1 +// @count - '//div[@id="deref-methods-Slice-1"]' 1 +// @count - '//div[@id="deref-methods-Slice-1"][@class="impl-items"]' 1 +// @count - '//div[@id="deref-methods-Slice-1"]/div[@class="impl-items"]' 0 +pub struct Vec; + +pub struct Slice; + +impl Deref for Vec { + type Target = Slice; + fn deref(&self) -> &Slice { + &Slice + } +} + +impl DerefMut for Vec { + fn deref_mut(&mut self) -> &mut Slice { + &mut Slice + } +} + +impl Slice { + pub fn sort_floats(&mut self) { + todo!(); + } +} + +impl Slice { + pub fn sort(&mut self) { + todo!(); + } +} + +impl Slice { + pub fn len(&self) { + todo!(); + } +} -- cgit 1.4.1-3-g733a5