/src/test/rustdoc/proc-macro.rs

https://gitlab.com/rust-lang/rust · Rust · 72 lines · 21 code · 11 blank · 40 comment · 0 complexity · 73b41fe664199f02873da43b6b147cdf MD5 · raw file

  1. // force-host
  2. // no-prefer-dynamic
  3. // compile-flags: --crate-type proc-macro --document-private-items
  4. #![crate_type="proc-macro"]
  5. #![crate_name="some_macros"]
  6. // @has some_macros/index.html
  7. // @has - '//a/[@href="attr.some_proc_attr.html"]' 'some_proc_attr'
  8. //! include a link to [some_proc_macro!] to make sure it works.
  9. extern crate proc_macro;
  10. use proc_macro::TokenStream;
  11. // @has some_macros/index.html
  12. // @has - '//h2' 'Macros'
  13. // @has - '//h2' 'Attribute Macros'
  14. // @has - '//h2' 'Derive Macros'
  15. // @!has - '//h2' 'Functions'
  16. // @has some_macros/all.html
  17. // @has - '//a[@href="macro.some_proc_macro.html"]' 'some_proc_macro'
  18. // @has - '//a[@href="attr.some_proc_attr.html"]' 'some_proc_attr'
  19. // @has - '//a[@href="derive.SomeDerive.html"]' 'SomeDerive'
  20. // @!has - '//a/@href' 'fn.some_proc_macro.html'
  21. // @!has - '//a/@href' 'fn.some_proc_attr.html'
  22. // @!has - '//a/@href' 'fn.some_derive.html'
  23. // @has some_macros/index.html '//a/@href' 'macro.some_proc_macro.html'
  24. // @!has - '//a/@href' 'fn.some_proc_macro.html'
  25. // @has some_macros/macro.some_proc_macro.html
  26. // @!has some_macros/fn.some_proc_macro.html
  27. /// a proc-macro that swallows its input and does nothing.
  28. #[proc_macro]
  29. pub fn some_proc_macro(_input: TokenStream) -> TokenStream {
  30. TokenStream::new()
  31. }
  32. // @has some_macros/index.html '//a/@href' 'attr.some_proc_attr.html'
  33. // @!has - '//a/@href' 'fn.some_proc_attr.html'
  34. // @has some_macros/attr.some_proc_attr.html
  35. // @!has some_macros/fn.some_proc_attr.html
  36. /// a proc-macro attribute that passes its item through verbatim.
  37. #[proc_macro_attribute]
  38. pub fn some_proc_attr(_attr: TokenStream, item: TokenStream) -> TokenStream {
  39. item
  40. }
  41. // @has some_macros/index.html '//a/@href' 'derive.SomeDerive.html'
  42. // @!has - '//a/@href' 'fn.some_derive.html'
  43. // @has some_macros/derive.SomeDerive.html
  44. // @!has some_macros/fn.some_derive.html
  45. /// a derive attribute that adds nothing to its input.
  46. #[proc_macro_derive(SomeDerive)]
  47. pub fn some_derive(_item: TokenStream) -> TokenStream {
  48. TokenStream::new()
  49. }
  50. // @has some_macros/foo/index.html
  51. mod foo {
  52. // @has - '//code' 'pub use some_proc_macro;'
  53. // @has - '//a/@href' '../macro.some_proc_macro.html'
  54. pub use some_proc_macro;
  55. // @has - '//code' 'pub use some_proc_attr;'
  56. // @has - '//a/@href' '../attr.some_proc_attr.html'
  57. pub use some_proc_attr;
  58. // @has - '//code' 'pub use some_derive;'
  59. // @has - '//a/@href' '../derive.SomeDerive.html'
  60. pub use some_derive;
  61. }