/src/test/rustdoc/generic-associated-types/gats.rs

https://gitlab.com/rust-lang/rust · Rust · 34 lines · 17 code · 7 blank · 10 comment · 2 complexity · ef44863984d3859aaa3e29b0700ba388 MD5 · raw file

  1. #![crate_name = "foo"]
  2. #![feature(generic_associated_types)]
  3. // @has foo/trait.LendingIterator.html
  4. pub trait LendingIterator {
  5. // @has - '//*[@id="associatedtype.Item"]//h4[@class="code-header"]' "type Item<'a> where Self: 'a"
  6. type Item<'a> where Self: 'a;
  7. // @has - '//*[@id="tymethod.next"]//h4[@class="code-header"]' \
  8. // "fn next<'a>(&'a self) -> Self::Item<'a>"
  9. // @has - '//*[@id="tymethod.next"]//h4[@class="code-header"]//a[@href="trait.LendingIterator.html#associatedtype.Item"]' \
  10. // "Item"
  11. fn next<'a>(&'a self) -> Self::Item<'a>;
  12. }
  13. // @has foo/trait.LendingIterator.html
  14. // @has - '//*[@id="associatedtype.Item-1"]//h4[@class="code-header"]' "type Item<'a> = ()"
  15. impl LendingIterator for () {
  16. type Item<'a> = ();
  17. fn next<'a>(&self) -> () {}
  18. }
  19. pub struct Infinite<T>(T);
  20. // @has foo/trait.LendingIterator.html
  21. // @has - '//*[@id="associatedtype.Item-2"]//h4[@class="code-header"]' "type Item<'a> where Self: 'a = &'a T"
  22. impl<T> LendingIterator for Infinite<T> {
  23. type Item<'a> where Self: 'a = &'a T;
  24. fn next<'a>(&'a self) -> Self::Item<'a> {
  25. &self.0
  26. }
  27. }