/src/test/rustdoc/universal-impl-trait.rs

https://gitlab.com/jianglu/rust · Rust · 65 lines · 26 code · 10 blank · 29 comment · 1 complexity · 4add684bca4a6492e5eee7903728a44b MD5 · raw file

  1. // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
  2. // file at the top-level directory of this distribution and at
  3. // http://rust-lang.org/COPYRIGHT.
  4. //
  5. // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
  6. // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
  7. // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
  8. // option. This file may not be copied, modified, or distributed
  9. // except according to those terms.
  10. #![crate_name = "foo"]
  11. use std::io::Read;
  12. use std::borrow::Borrow;
  13. // @has foo/fn.foo.html
  14. // @has - //pre 'foo('
  15. // @matches - '_x: impl <a class="trait" href="[^"]+/trait\.Clone\.html"'
  16. // @matches - '_z: .+impl.+trait\.Copy\.html.+, impl.+trait\.Clone\.html'
  17. pub fn foo(_x: impl Clone, _y: i32, _z: (impl Copy, impl Clone)) {
  18. }
  19. pub trait Trait {
  20. // @has foo/trait.Trait.html
  21. // @has - 'method</a>('
  22. // @matches - '_x: impl <a class="trait" href="[^"]+/trait\.Debug\.html"'
  23. fn method(&self, _x: impl std::fmt::Debug) {
  24. }
  25. }
  26. pub struct S<T>(T);
  27. impl<T> S<T> {
  28. // @has foo/struct.S.html
  29. // @has - 'bar</a>('
  30. // @matches - '_bar: impl <a class="trait" href="[^"]+/trait\.Copy\.html"'
  31. pub fn bar(_bar: impl Copy) {
  32. }
  33. // @has - 'baz</a>('
  34. // @matches - '_baz:.+struct\.S\.html.+impl .+trait\.Clone\.html'
  35. pub fn baz(_baz: S<impl Clone>) {
  36. }
  37. // @has - 'qux</a>('
  38. // @matches - 'trait\.Read\.html'
  39. pub fn qux(_qux: impl IntoIterator<Item = S<impl Read>>) {
  40. }
  41. }
  42. // @has - 'method</a>('
  43. // @matches - '_x: impl <a class="trait" href="[^"]+/trait\.Debug\.html"'
  44. impl<T> Trait for S<T> {}
  45. // @has foo/fn.much_universe.html
  46. // @matches - 'T:.+Borrow.+impl .+trait\.Trait\.html'
  47. // @matches - 'U:.+IntoIterator.+= impl.+Iterator\.html.+= impl.+Clone\.html'
  48. // @matches - '_: impl .+trait\.Read\.html.+ \+ .+trait\.Clone\.html'
  49. pub fn much_universe<
  50. T: Borrow<impl Trait>,
  51. U: IntoIterator<Item = impl Iterator<Item = impl Clone>>,
  52. >(
  53. _: impl Read + Clone,
  54. ) {
  55. }