From aef682a89853b83c20f086fdd5a6fba2af1ebfdd Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 19 Feb 2024 16:07:39 +0000 Subject: [PATCH] Docs for extension proc-macro --- compiler/rustc_macros/src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/compiler/rustc_macros/src/lib.rs b/compiler/rustc_macros/src/lib.rs index 619f93c8a533a..e3669375c0e90 100644 --- a/compiler/rustc_macros/src/lib.rs +++ b/compiler/rustc_macros/src/lib.rs @@ -41,6 +41,19 @@ pub fn symbols(input: TokenStream) -> TokenStream { symbols::symbols(input.into()).into() } +/// Derive an extension trait for a given impl block. The trait name +/// goes into the parenthesized args of the macro, for greppability. +/// For example: +/// ``` +/// #[extension(pub trait Foo)] +/// impl i32 { fn hello() {} } +/// ``` +/// +/// expands to: +/// ``` +/// pub trait Foo { fn hello(); } +/// impl Foo for i32 { fn hello() {} } +/// ``` #[proc_macro_attribute] pub fn extension(attr: TokenStream, input: TokenStream) -> TokenStream { extension::extension(attr, input)