Skip to content

Commit

Permalink
Docs for extension proc-macro
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Feb 19, 2024
1 parent 43d3470 commit aef682a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions compiler/rustc_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Check failure on line 48 in compiler/rustc_macros/src/lib.rs

View workflow job for this annotation

GitHub Actions / PR - x86_64-gnu-llvm-16

cannot find attribute `extension` in this scope
/// impl i32 { fn hello() {} }

Check failure on line 49 in compiler/rustc_macros/src/lib.rs

View workflow job for this annotation

GitHub Actions / PR - x86_64-gnu-llvm-16

cannot define inherent `impl` for primitive types
/// ```
///
/// 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)
Expand Down

0 comments on commit aef682a

Please sign in to comment.