From 3a46f410cc316626019ccef0a1c7546b37a53717 Mon Sep 17 00:00:00 2001 From: The0x539 Date: Sat, 23 Mar 2024 14:50:16 -0500 Subject: [PATCH] macros: Add documentation to blanket_ref --- macros/src/lib.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/macros/src/lib.rs b/macros/src/lib.rs index f8218c2b2005..ad3784d6140e 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -25,6 +25,25 @@ pub fn define_node(input: proc_macro::TokenStream) -> proc_macro::TokenStream { stream.into() } +/// Given a trait definition such as: +/// ``` +/// trait Node { +/// type ParseError; +/// const NODE_TYPE: NodeType; +/// fn source_range(&self) -> SourceRange; +/// } +/// ``` +/// Generate an implementation of the form: +/// ``` +/// impl Node for &T { +/// type ParseError = T::ParseError; +/// const NODE_TYPE: NodeType = T::NODE_TYPE; +/// fn source_range(&self) -> SourceRange { +/// T::source_range(self) +/// } +/// } +/// ``` +/// A similar `impl` will be generated for `&mut T`. #[proc_macro_attribute] pub fn blanket_ref( _attr: proc_macro::TokenStream, @@ -37,6 +56,7 @@ pub fn blanket_ref( output.into() } +/// Like [`macro@blanket_ref`], but only generates an `impl` for `&mut T`. #[proc_macro_attribute] pub fn blanket_mut( _attr: proc_macro::TokenStream,