/src/test/rustdoc/deref-recursive.rs

https://gitlab.com/rust-lang/rust · Rust · 41 lines · 19 code · 8 blank · 14 comment · 2 complexity · 0105d18ede7291d2435e7d189e89c271 MD5 · raw file

  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. // @has 'foo/struct.Foo.html'
  5. // @has '-' '//*[@id="deref-methods-Bar"]' 'Methods from Deref<Target = Bar>'
  6. // @has '-' '//*[@class="impl-items"]//*[@id="method.bar"]' 'pub fn bar(&self)'
  7. // @has '-' '//*[@id="deref-methods-Baz"]' 'Methods from Deref<Target = Baz>'
  8. // @has '-' '//*[@class="impl-items"]//*[@id="method.baz"]' 'pub fn baz(&self)'
  9. // @has '-' '//*[@class="sidebar-title"]/a[@href="#deref-methods-Bar"]' 'Methods from Deref<Target=Bar>'
  10. // @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.bar"]' 'bar'
  11. // @has '-' '//*[@class="sidebar-title"]/a[@href="#deref-methods-Baz"]' 'Methods from Deref<Target=Baz>'
  12. // @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.baz"]' 'baz'
  13. #![crate_name = "foo"]
  14. use std::ops::Deref;
  15. pub struct Foo(Bar);
  16. pub struct Bar(Baz);
  17. pub struct Baz;
  18. impl Deref for Foo {
  19. type Target = Bar;
  20. fn deref(&self) -> &Bar { &self.0 }
  21. }
  22. impl Deref for Bar {
  23. type Target = Baz;
  24. fn deref(&self) -> &Baz { &self.0 }
  25. }
  26. impl Bar {
  27. /// This appears under `Foo` methods
  28. pub fn bar(&self) {}
  29. }
  30. impl Baz {
  31. /// This should also appear in `Foo` methods when recursing
  32. pub fn baz(&self) {}
  33. }