Skip to content

Commit aef682a

Browse files
Docs for extension proc-macro
1 parent 43d3470 commit aef682a

File tree

1 file changed

+13
-0
lines changed
  • compiler/rustc_macros/src

1 file changed

+13
-0
lines changed

compiler/rustc_macros/src/lib.rs

+13
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ pub fn symbols(input: TokenStream) -> TokenStream {
4141
symbols::symbols(input.into()).into()
4242
}
4343

44+
/// Derive an extension trait for a given impl block. The trait name
45+
/// goes into the parenthesized args of the macro, for greppability.
46+
/// For example:
47+
/// ```
48+
/// #[extension(pub trait Foo)]
49+
/// impl i32 { fn hello() {} }
50+
/// ```
51+
///
52+
/// expands to:
53+
/// ```
54+
/// pub trait Foo { fn hello(); }
55+
/// impl Foo for i32 { fn hello() {} }
56+
/// ```
4457
#[proc_macro_attribute]
4558
pub fn extension(attr: TokenStream, input: TokenStream) -> TokenStream {
4659
extension::extension(attr, input)

0 commit comments

Comments
 (0)