/src/test/rustdoc/intra-doc/generic-params.rs

https://gitlab.com/rust-lang/rust · Rust · 62 lines · 2 code · 9 blank · 51 comment · 0 complexity · f4e0b3b1996b4faaf567aa88a66a4a06 MD5 · raw file

  1. // ignore-tidy-linelength
  2. #![crate_name = "foo"]
  3. //! Here's a link to [`Vec<T>`] and one to [`Box<Vec<Option<T>>>`].
  4. //! Here's a link to [`Iterator<Box<T>>::Item`].
  5. //!
  6. // @has foo/index.html '//a[@href="{{channel}}/alloc/vec/struct.Vec.html"]' 'Vec<T>'
  7. // @has foo/index.html '//a[@href="{{channel}}/alloc/boxed/struct.Box.html"]' 'Box<Vec<Option<T>>>'
  8. // @has foo/index.html '//a[@href="{{channel}}/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item"]' 'Iterator<Box<T>>::Item'
  9. //! And what about a link to [just `Option`](Option) and, [with the generic, `Option<T>`](Option<T>)?
  10. //!
  11. // @has foo/index.html '//a[@href="{{channel}}/core/option/enum.Option.html"]' 'just Option'
  12. // @has foo/index.html '//a[@href="{{channel}}/core/option/enum.Option.html"]' 'with the generic, Option<T>'
  13. //! We should also try linking to [`Result<T, E>`]; it has *two* generics!
  14. //! And [`Result<T, !>`] and [`Result<!, E>`].
  15. //!
  16. // @has foo/index.html '//a[@href="{{channel}}/core/result/enum.Result.html"]' 'Result<T, E>'
  17. // @has foo/index.html '//a[@href="{{channel}}/core/result/enum.Result.html"]' 'Result<T, !>'
  18. // @has foo/index.html '//a[@href="{{channel}}/core/result/enum.Result.html"]' 'Result<!, E>'
  19. //! Now let's test a trickier case: [`Vec::<T>::new`], or you could write it
  20. //! [with parentheses as `Vec::<T>::new()`][Vec::<T>::new()].
  21. //! And what about something even harder? That would be [`Vec::<Box<T>>::new()`].
  22. //!
  23. // @has foo/index.html '//a[@href="{{channel}}/alloc/vec/struct.Vec.html#method.new"]' 'Vec::<T>::new'
  24. // @has foo/index.html '//a[@href="{{channel}}/alloc/vec/struct.Vec.html#method.new"]' 'with parentheses as Vec::<T>::new()'
  25. // @has foo/index.html '//a[@href="{{channel}}/alloc/vec/struct.Vec.html#method.new"]' 'Vec::<Box<T>>::new()'
  26. //! This is also pretty tricky: [`TypeId::of::<String>()`].
  27. //! And this too: [`Vec::<std::error::Error>::len`].
  28. //!
  29. // @has foo/index.html '//a[@href="{{channel}}/core/any/struct.TypeId.html#method.of"]' 'TypeId::of::<String>()'
  30. // @has foo/index.html '//a[@href="{{channel}}/alloc/vec/struct.Vec.html#method.len"]' 'Vec::<std::error::Error>::len'
  31. //! We unofficially and implicitly support things that aren't valid in the actual Rust syntax, like
  32. //! [`Box::<T>new()`]. We may not support them in the future!
  33. //!
  34. // @has foo/index.html '//a[@href="{{channel}}/alloc/boxed/struct.Box.html#method.new"]' 'Box::<T>new()'
  35. //! These will be resolved as regular links:
  36. //! - [`this is <invalid syntax> first`](https://www.rust-lang.org)
  37. //! - [`this is <invalid syntax> twice`]
  38. //! - [`<invalid syntax> thrice`](https://www.rust-lang.org)
  39. //! - [`<invalid syntax> four times`][rlo]
  40. //! - [a < b][rlo]
  41. //! - [c > d]
  42. //!
  43. //! [`this is <invalid syntax> twice`]: https://www.rust-lang.org
  44. //! [rlo]: https://www.rust-lang.org
  45. //! [c > d]: https://www.rust-lang.org
  46. //!
  47. // @has foo/index.html '//a[@href="https://www.rust-lang.org"]' 'this is <invalid syntax> first'
  48. // @has foo/index.html '//a[@href="https://www.rust-lang.org"]' 'this is <invalid syntax> twice'
  49. // @has foo/index.html '//a[@href="https://www.rust-lang.org"]' '<invalid syntax> thrice'
  50. // @has foo/index.html '//a[@href="https://www.rust-lang.org"]' '<invalid syntax> four times'
  51. // @has foo/index.html '//a[@href="https://www.rust-lang.org"]' 'a < b'
  52. // @has foo/index.html '//a[@href="https://www.rust-lang.org"]' 'c > d'
  53. use std::any::TypeId;