forked from rust-lang/rust-analyzer
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Small example of using a proc-macro that we need to expand
for subsequent code to type check
- Loading branch information
Showing
4 changed files
with
48 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "storage-macros" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
proc-macro = true | ||
|
||
[dependencies] | ||
quote = "1" | ||
proc-macro2 = "1.0" | ||
syn = "2.0" | ||
|
||
[workspace] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use proc_macro::TokenStream; | ||
use quote::{quote,format_ident}; | ||
use syn::{parse_macro_input, DeriveInput}; | ||
|
||
#[proc_macro_derive(Hello)] | ||
pub fn hello_derive(input: TokenStream) -> TokenStream { | ||
let input = parse_macro_input!(input as DeriveInput); | ||
let name = input.ident; | ||
let fn_name = format_ident!("say_hello_{}", name); | ||
|
||
quote!{ | ||
//#[verifier::external_body] | ||
fn #fn_name() { | ||
println!("#name says hi"); | ||
} | ||
}.into() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
#![allow(non_snake_case)] | ||
#![allow(dead_code)] | ||
//use vstd::prelude::*; | ||
use storage_macros::Hello; | ||
|
||
verus! { | ||
pub broadcast group all_the_axioms { | ||
axiom_jay_lorch | ||
} | ||
|
||
//verus! { | ||
|
||
#[derive(Hello)] | ||
struct TestKey { | ||
val: u64, | ||
} | ||
|
||
fn main() { } | ||
//} | ||
|
||
fn main() { | ||
say_hello_TestKey(); | ||
} |