Skip to content

Commit 94e459f

Browse files
authored
Rollup merge of #121304 - compiler-errors:ext, r=nnethercote
Add docs for extension proc-macro r? nnethercote
2 parents 4840785 + 62e7414 commit 94e459f

File tree

1 file changed

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

1 file changed

+14
-0
lines changed

compiler/rustc_macros/src/lib.rs

+14
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ 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+
/// use rustc_macros::extension;
49+
/// #[extension(pub trait Foo)]
50+
/// impl i32 { fn hello() {} }
51+
/// ```
52+
///
53+
/// expands to:
54+
/// ```
55+
/// pub trait Foo { fn hello(); }
56+
/// impl Foo for i32 { fn hello() {} }
57+
/// ```
4458
#[proc_macro_attribute]
4559
pub fn extension(attr: TokenStream, input: TokenStream) -> TokenStream {
4660
extension::extension(attr, input)

0 commit comments

Comments
 (0)