]> git.lizzy.rs Git - rust.git/blob - tests/rustdoc/deref-recursive.rs
Rollup merge of #107662 - cjgillot:copy-projection, r=oli-obk
[rust.git] / tests / rustdoc / deref-recursive.rs
1 // #26207: Show all methods reachable via Deref impls, recursing through multiple dereferencing
2 // levels if needed.
3 // For `Deref` on foreign types, look at `deref-recursive-pathbuf.rs`.
4
5 // @has 'foo/struct.Foo.html'
6 // @has '-' '//*[@id="deref-methods-Bar"]' 'Methods from Deref<Target = Bar>'
7 // @has '-' '//*[@class="impl-items"]//*[@id="method.bar"]' 'pub fn bar(&self)'
8 // @has '-' '//*[@id="deref-methods-Baz"]' 'Methods from Deref<Target = Baz>'
9 // @has '-' '//*[@class="impl-items"]//*[@id="method.baz"]' 'pub fn baz(&self)'
10 // @has '-' '//div[@class="sidebar-elems"]//h3/a[@href="#deref-methods-Bar"]' 'Methods from Deref<Target=Bar>'
11 // @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.bar"]' 'bar'
12 // @has '-' '//div[@class="sidebar-elems"]//h3/a[@href="#deref-methods-Baz"]' 'Methods from Deref<Target=Baz>'
13 // @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.baz"]' 'baz'
14
15 #![crate_name = "foo"]
16
17 use std::ops::Deref;
18
19 pub struct Foo(Bar);
20 pub struct Bar(Baz);
21 pub struct Baz;
22
23 impl Deref for Foo {
24     type Target = Bar;
25     fn deref(&self) -> &Bar { &self.0 }
26 }
27
28 impl Deref for Bar {
29     type Target = Baz;
30     fn deref(&self) -> &Baz { &self.0 }
31 }
32
33 impl Bar {
34     /// This appears under `Foo` methods
35     pub fn bar(&self) {}
36 }
37
38 impl Baz {
39     /// This should also appear in `Foo` methods when recursing
40     pub fn baz(&self) {}
41 }