| 1 |
//! [![github]](https://github.com/dtolnay/proc-macro-hack) [![crates-io]](https://crates.io/crates/proc-macro-hack) [![docs-rs]](https://docs.rs/proc-macro-hack) |
| 2 |
//! |
| 3 |
//! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github |
| 4 |
//! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust |
| 5 |
//! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logoColor=white&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K |
| 6 |
//! |
| 7 |
//! <br> |
| 8 |
//! |
| 9 |
//! <table><tr><td><hr> |
| 10 |
//! <b>Note:</b> <i>As of Rust 1.45 this crate is superseded by native support |
| 11 |
//! for #[proc_macro] in expression position. Only consider using this crate if |
| 12 |
//! you care about supporting compilers between 1.31 and 1.45.</i> |
| 13 |
//! <hr></td></tr></table> |
| 14 |
//! |
| 15 |
//! Since Rust 1.30, the language supports user-defined function-like procedural |
| 16 |
//! macros. However these can only be invoked in item position, not in |
| 17 |
//! statements or expressions. |
| 18 |
//! |
| 19 |
//! This crate implements an alternative type of procedural macro that can be |
| 20 |
//! invoked in statement or expression position. |
| 21 |
//! |
| 22 |
//! # Defining procedural macros |
| 23 |
//! |
| 24 |
//! Two crates are required to define a procedural macro. |
| 25 |
//! |
| 26 |
//! ## The implementation crate |
| 27 |
//! |
| 28 |
//! This crate must contain nothing but procedural macros. Private helper |
| 29 |
//! functions and private modules are fine but nothing can be public. |
| 30 |
//! |
| 31 |
//! [» example of an implementation crate][demo-hack-impl] |
| 32 |
//! |
| 33 |
//! Just like you would use a #\[proc_macro\] attribute to define a natively |
| 34 |
//! supported procedural macro, use proc-macro-hack's #\[proc_macro_hack\] |
| 35 |
//! attribute to define a procedural macro that works in expression position. |
| 36 |
//! The function signature is the same as for ordinary function-like procedural |
| 37 |
//! macros. |
| 38 |
//! |
| 39 |
//! ``` |
| 40 |
//! # extern crate proc_macro; |
| 41 |
//! # |
| 42 |
//! use proc_macro::TokenStream; |
| 43 |
//! use proc_macro_hack::proc_macro_hack; |
| 44 |
//! use quote::quote; |
| 45 |
//! use syn::{parse_macro_input, Expr}; |
| 46 |
//! |
| 47 |
//! # const IGNORE: &str = stringify! { |
| 48 |
//! #[proc_macro_hack] |
| 49 |
//! # }; |
| 50 |
//! pub fn add_one(input: TokenStream) -> TokenStream { |
| 51 |
//! let expr = parse_macro_input!(input as Expr); |
| 52 |
//! TokenStream::from(quote! { |
| 53 |
//! 1 + (#expr) |
| 54 |
//! }) |
| 55 |
//! } |
| 56 |
//! # |
| 57 |
//! # fn main() {} |
| 58 |
//! ``` |
| 59 |
//! |
| 60 |
//! ## The declaration crate |
| 61 |
//! |
| 62 |
//! This crate is allowed to contain other public things if you need, for |
| 63 |
//! example traits or functions or ordinary macros. |
| 64 |
//! |
| 65 |
//! [» example of a declaration crate][demo-hack] |
| 66 |
//! |
| 67 |
//! Within the declaration crate there needs to be a re-export of your |
| 68 |
//! procedural macro from the implementation crate. The re-export also carries a |
| 69 |
//! \#\[proc_macro_hack\] attribute. |
| 70 |
//! |
| •71 |
//! ```ignore |
| 72 |
//! use proc_macro_hack::proc_macro_hack; |
| 73 |
//! |
| 74 |
//! /// Add one to an expression. |
| 75 |
//! /// |
| 76 |
//! /// (Documentation goes here on the re-export, not in the other crate.) |
| 77 |
//! #[proc_macro_hack] |
| 78 |
//! pub use demo_hack_impl::add_one; |
| 79 |
//! # |
| 80 |
//! # fn main() {} |
| 81 |
//! ``` |
| 82 |
//! |
| 83 |
//! Both crates depend on `proc-macro-hack`: |
| 84 |
//! |
| 85 |
//! ```toml |
| 86 |
//! [dependencies] |
| 87 |
//! proc-macro-hack = "0.5" |
| 88 |
//! ``` |
| 89 |
//! |
| 90 |
//! Additionally, your implementation crate (but not your declaration crate) is |
| 91 |
//! a proc macro crate: |
| 92 |
//! |
| 93 |
//! ```toml |
| 94 |
//! [lib] |
| 95 |
//! proc-macro = true |
| 96 |
//! ``` |
| 97 |
//! |
| 98 |
//! # Using procedural macros |
| 99 |
//! |
| 100 |
//! Users of your crate depend on your declaration crate (not your |
| 101 |
//! implementation crate), then use your procedural macros as usual. |
| 102 |
//! |
| 103 |
//! [» example of a downstream crate][example] |
| 104 |
//! |
| •105 |
//! ```ignore |
| 106 |
//! use demo_hack::add_one; |
| 107 |
//! |
| 108 |
//! fn main() { |
| 109 |
//! let two = 2; |
| 110 |
//! let nine = add_one!(two) + add_one!(2 + 3); |
| 111 |
//! println!("nine = {}", nine); |
| 112 |
//! } |
| 113 |
//! ``` |
| 114 |
//! |
| 115 |
//! [demo-hack-impl]: https://github.com/dtolnay/proc-macro-hack/tree/master/demo-hack-impl |
| 116 |
//! [demo-hack]: https://github.com/dtolnay/proc-macro-hack/tree/master/demo-hack |
| 117 |
//! [example]: https://github.com/dtolnay/proc-macro-hack/tree/master/example |
| 118 |
//! |
| 119 |
//! # Limitations |
| 120 |
//! |
| 121 |
//! - Only proc macros in expression position are supported. Proc macros in |
| 122 |
//! pattern position ([#20]) are not supported. |
| 123 |
//! |
| 124 |
//! - By default, nested invocations are not supported i.e. the code emitted by |
| 125 |
//! a proc-macro-hack macro invocation cannot contain recursive calls to the |
| 126 |
//! same proc-macro-hack macro nor calls to any other proc-macro-hack macros. |
| 127 |
//! Use [`proc-macro-nested`] if you require support for nested invocations. |
| 128 |
//! |
| 129 |
//! - By default, hygiene is structured such that the expanded code can't refer |
| 130 |
//! to local variables other than those passed by name somewhere in the macro |
| 131 |
//! input. If your macro must refer to *local* variables that don't get named |
| 132 |
//! in the macro input, use `#[proc_macro_hack(fake_call_site)]` on the |
| 133 |
//! re-export in your declaration crate. *Most macros won't need this.* |
| 134 |
//! |
| 135 |
//! - On compilers that are new enough to natively support proc macros in |
| 136 |
//! expression position, proc-macro-hack does not automatically use that |
| 137 |
//! support, since the hygiene can be subtly different between the two |
| 138 |
//! implementations. To opt in to compiling your macro to native |
| 139 |
//! `#[proc_macro]` on sufficiently new compilers, use |
| 140 |
//! `#[proc_macro_hack(only_hack_old_rustc)]` on the re-export in your |
| 141 |
//! declaration crate. |
| 142 |
//! |
| 143 |
//! [#10]: https://github.com/dtolnay/proc-macro-hack/issues/10 |
| 144 |
//! [#20]: https://github.com/dtolnay/proc-macro-hack/issues/20 |
| 145 |
//! [`proc-macro-nested`]: https://docs.rs/proc-macro-nested |
| 146 |
|
| 147 |
#![recursion_limit = "512"] |
| 148 |
#![allow(clippy::needless_doctest_main, clippy::toplevel_ref_arg)] |
| 149 |
|
| 150 |
extern crate proc_macrorust-analyzer cargo proc-macro-hack 0.5.19 proc_macro/; |
| 151 |
|
| 152 |
#[macro_use] |
| 153 |
mod quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/; |
| 154 |
|
| 155 |
mod errorrust-analyzer cargo proc-macro-hack 0.5.19 error/; |
| 156 |
mod iterrust-analyzer cargo proc-macro-hack 0.5.19 iter/; |
| 157 |
mod parserust-analyzer cargo proc-macro-hack 0.5.19 parse/; |
| 158 |
|
| 159 |
use craterust-analyzer cargo proc-macro-hack 0.5.19 crate/::errorrust-analyzer cargo proc-macro-hack 0.5.19 error/::{compile_errorrust-analyzer cargo proc-macro-hack 0.5.19 error/compile_error()., Errorrust-analyzer cargo proc-macro-hack 0.5.19 error/Error#}; |
| 160 |
use craterust-analyzer cargo proc-macro-hack 0.5.19 crate/::iterrust-analyzer cargo proc-macro-hack 0.5.19 iter/::Iterrust-analyzer cargo proc-macro-hack 0.5.19 iter/Iter#; |
| 161 |
use craterust-analyzer cargo proc-macro-hack 0.5.19 crate/::parserust-analyzer cargo proc-macro-hack 0.5.19 parse/::{ |
| 162 |
parse_define_argsrust-analyzer cargo proc-macro-hack 0.5.19 parse/parse_define_args()., parse_enum_hackrust-analyzer cargo proc-macro-hack 0.5.19 parse/parse_enum_hack()., parse_export_argsrust-analyzer cargo proc-macro-hack 0.5.19 parse/parse_export_args()., parse_fake_call_siterust-analyzer cargo proc-macro-hack 0.5.19 parse/parse_fake_call_site()., parse_inputrust-analyzer cargo proc-macro-hack 0.5.19 parse/parse_input()., |
| 163 |
}; |
| 164 |
use proc_macrorust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro crate/::{Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Ident#, Punctrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Punct#, Spacingrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Spacing#, Spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Span#, TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#, TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#}; |
| 165 |
use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#; |
| 166 |
|
| 167 |
type Visibilityrust-analyzer cargo proc-macro-hack 0.5.19 Visibility# = Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Ident#>; |
| 168 |
|
| 169 |
enum Inputrust-analyzer cargo proc-macro-hack 0.5.19 Input# { |
| 170 |
Exportrust-analyzer cargo proc-macro-hack 0.5.19 Input#Export#(Exportrust-analyzer cargo proc-macro-hack 0.5.19 Export#), |
| 171 |
Definerust-analyzer cargo proc-macro-hack 0.5.19 Input#Define#(Definerust-analyzer cargo proc-macro-hack 0.5.19 Define#), |
| 172 |
} |
| 173 |
|
| 174 |
// pub use demo_hack_impl::{m1, m2 as qrst}; |
| 175 |
struct Exportrust-analyzer cargo proc-macro-hack 0.5.19 Export# { |
| 176 |
attrsrust-analyzer cargo proc-macro-hack 0.5.19 Export#attrs.: TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#, |
| 177 |
visrust-analyzer cargo proc-macro-hack 0.5.19 Export#vis.: Visibilityrust-analyzer cargo proc-macro-hack 0.5.19 Visibility#, |
| 178 |
fromrust-analyzer cargo proc-macro-hack 0.5.19 Export#from.: Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Ident#, |
| 179 |
macrosrust-analyzer cargo proc-macro-hack 0.5.19 Export#macros.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Macrorust-analyzer cargo proc-macro-hack 0.5.19 Macro#>, |
| 180 |
} |
| 181 |
|
| 182 |
// pub fn m1(input: TokenStream) -> TokenStream { ... } |
| 183 |
struct Definerust-analyzer cargo proc-macro-hack 0.5.19 Define# { |
| 184 |
attrsrust-analyzer cargo proc-macro-hack 0.5.19 Define#attrs.: TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#, |
| 185 |
namerust-analyzer cargo proc-macro-hack 0.5.19 Define#name.: Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Ident#, |
| 186 |
bodyrust-analyzer cargo proc-macro-hack 0.5.19 Define#body.: TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#, |
| 187 |
} |
| 188 |
|
| 189 |
struct Macrorust-analyzer cargo proc-macro-hack 0.5.19 Macro# { |
| 190 |
namerust-analyzer cargo proc-macro-hack 0.5.19 Macro#name.: Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Ident#, |
| 191 |
export_asrust-analyzer cargo proc-macro-hack 0.5.19 Macro#export_as.: Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Ident#, |
| 192 |
} |
| 193 |
|
| 194 |
#[proc_macro_attribute] |
| 195 |
pub fn proc_macro_hackrust-analyzer cargo proc-macro-hack 0.5.19 proc_macro_hack:(args: TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#, input: TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#) -> TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream# { |
| 196 |
let ref mut args = iterrust-analyzer cargo proc-macro-hack 0.5.19 iter/::newrust-analyzer cargo proc-macro-hack 0.5.19 iter/new().(args); |
| 197 |
let ref mut input = iterrust-analyzer cargo proc-macro-hack 0.5.19 iter/::newrust-analyzer cargo proc-macro-hack 0.5.19 iter/new().(input); |
| 198 |
expand_proc_macro_hackrust-analyzer cargo proc-macro-hack 0.5.19 expand_proc_macro_hack().(args, input).unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or_else().(compile_errorrust-analyzer cargo proc-macro-hack 0.5.19 error/compile_error().) |
| 199 |
} |
| 200 |
|
| 201 |
fn expand_proc_macro_hackrust-analyzer cargo proc-macro-hack 0.5.19 expand_proc_macro_hack().(args: Iterrust-analyzer cargo proc-macro-hack 0.5.19 iter/Iter#, input: Iterrust-analyzer cargo proc-macro-hack 0.5.19 iter/Iter#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#, Errorrust-analyzer cargo proc-macro-hack 0.5.19 error/Error#> { |
| 202 |
match parse_inputrust-analyzer cargo proc-macro-hack 0.5.19 parse/parse_input().(input)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 203 |
Inputrust-analyzer cargo proc-macro-hack 0.5.19 Input#::Exportrust-analyzer cargo proc-macro-hack 0.5.19 Input#Export#(export) => { |
| 204 |
let args = parse_export_argsrust-analyzer cargo proc-macro-hack 0.5.19 parse/parse_export_args().(args)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 205 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(expand_exportrust-analyzer cargo proc-macro-hack 0.5.19 expand_export().(export, args)) |
| 206 |
} |
| 207 |
Inputrust-analyzer cargo proc-macro-hack 0.5.19 Input#::Definerust-analyzer cargo proc-macro-hack 0.5.19 Input#Define#(define) => { |
| 208 |
parse_define_argsrust-analyzer cargo proc-macro-hack 0.5.19 parse/parse_define_args().(args)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 209 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(expand_definerust-analyzer cargo proc-macro-hack 0.5.19 expand_define().(define)) |
| 210 |
} |
| 211 |
} |
| 212 |
} |
| 213 |
|
| 214 |
#[doc(hidden)] |
| 215 |
#[proc_macro_derive(ProcMacroHack)] |
| 216 |
pub fn enum_hackrust-analyzer cargo proc-macro-hack 0.5.19 ProcMacroHack:(input: TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#) -> TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream# { |
| 217 |
let ref mut input = iterrust-analyzer cargo proc-macro-hack 0.5.19 iter/::newrust-analyzer cargo proc-macro-hack 0.5.19 iter/new().(input); |
| 218 |
parse_enum_hackrust-analyzer cargo proc-macro-hack 0.5.19 parse/parse_enum_hack().(input).unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or_else().(compile_errorrust-analyzer cargo proc-macro-hack 0.5.19 error/compile_error().) |
| 219 |
} |
| 220 |
|
| 221 |
struct FakeCallSiterust-analyzer cargo proc-macro-hack 0.5.19 FakeCallSite# { |
| 222 |
deriverust-analyzer cargo proc-macro-hack 0.5.19 FakeCallSite#derive.: Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Ident#, |
| 223 |
restrust-analyzer cargo proc-macro-hack 0.5.19 FakeCallSite#rest.: TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#, |
| 224 |
} |
| 225 |
|
| 226 |
#[doc(hidden)] |
| 227 |
#[proc_macro_attribute] |
| 228 |
pub fn fake_call_siterust-analyzer cargo proc-macro-hack 0.5.19 fake_call_site:(args: TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#, input: TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#) -> TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream# { |
| 229 |
let ref mut args = iterrust-analyzer cargo proc-macro-hack 0.5.19 iter/::newrust-analyzer cargo proc-macro-hack 0.5.19 iter/new().(args); |
| 230 |
let ref mut input = iterrust-analyzer cargo proc-macro-hack 0.5.19 iter/::newrust-analyzer cargo proc-macro-hack 0.5.19 iter/new().(input); |
| 231 |
expand_fake_call_siterust-analyzer cargo proc-macro-hack 0.5.19 expand_fake_call_site().(args, input).unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or_else().(compile_errorrust-analyzer cargo proc-macro-hack 0.5.19 error/compile_error().) |
| 232 |
} |
| 233 |
|
| 234 |
fn expand_fake_call_siterust-analyzer cargo proc-macro-hack 0.5.19 expand_fake_call_site().(args: Iterrust-analyzer cargo proc-macro-hack 0.5.19 iter/Iter#, input: Iterrust-analyzer cargo proc-macro-hack 0.5.19 iter/Iter#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#, Errorrust-analyzer cargo proc-macro-hack 0.5.19 error/Error#> { |
| 235 |
let span = match args.nextrust-analyzer cargo proc-macro-hack 0.5.19 iter/impl#[IterImpl][Iterator]next().() { |
| 236 |
Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token) => token.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenTree]span().(), |
| 237 |
Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(input.collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()), |
| 238 |
}; |
| 239 |
|
| 240 |
let input = parse_fake_call_siterust-analyzer cargo proc-macro-hack 0.5.19 parse/parse_fake_call_site().(input)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 241 |
let mut derive = input.deriverust-analyzer cargo proc-macro-hack 0.5.19 FakeCallSite#derive.; |
| 242 |
derive.set_spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Ident]set_span().(span); |
| 243 |
let rest = input.restrust-analyzer cargo proc-macro-hack 0.5.19 FakeCallSite#rest.; |
| 244 |
|
| 245 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!! { |
| 246 |
#[derive(#derive)] |
| 247 |
#rest |
| 248 |
}) |
| 249 |
} |
| 250 |
|
| 251 |
struct ExportArgsrust-analyzer cargo proc-macro-hack 0.5.19 ExportArgs# { |
| 252 |
support_nestedrust-analyzer cargo proc-macro-hack 0.5.19 ExportArgs#support_nested.: bool, |
| 253 |
internal_macro_callsrust-analyzer cargo proc-macro-hack 0.5.19 ExportArgs#internal_macro_calls.: u16, |
| 254 |
fake_call_siterust-analyzer cargo proc-macro-hack 0.5.19 ExportArgs#fake_call_site.: bool, |
| 255 |
only_hack_old_rustcrust-analyzer cargo proc-macro-hack 0.5.19 ExportArgs#only_hack_old_rustc.: bool, |
| 256 |
} |
| 257 |
|
| 258 |
fn expand_exportrust-analyzer cargo proc-macro-hack 0.5.19 expand_export().(export: Exportrust-analyzer cargo proc-macro-hack 0.5.19 Export#, args: ExportArgsrust-analyzer cargo proc-macro-hack 0.5.19 ExportArgs#) -> TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream# { |
| 259 |
if args.only_hack_old_rustcrust-analyzer cargo proc-macro-hack 0.5.19 ExportArgs#only_hack_old_rustc. && cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(not(need_proc_macro_hack)) { |
| 260 |
return expand_export_nohackrust-analyzer cargo proc-macro-hack 0.5.19 expand_export_nohack().(export); |
| 261 |
} |
| 262 |
|
| 263 |
let dummy = dummy_name_for_exportrust-analyzer cargo proc-macro-hack 0.5.19 dummy_name_for_export().(&export); |
| 264 |
|
| 265 |
let attrs = export.attrsrust-analyzer cargo proc-macro-hack 0.5.19 Export#attrs.; |
| 266 |
let vis = export.visrust-analyzer cargo proc-macro-hack 0.5.19 Export#vis.; |
| 267 |
let macro_export = match vis { |
| 268 |
Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_) => quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!!(#[macro_export]), |
| 269 |
Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!!(), |
| 270 |
}; |
| 271 |
let crate_prefix = vis.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|_| quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!!($crate::)); |
| 272 |
let enum_variant = if args.support_nestedrust-analyzer cargo proc-macro-hack 0.5.19 ExportArgs#support_nested. { |
| 273 |
if args.internal_macro_callsrust-analyzer cargo proc-macro-hack 0.5.19 ExportArgs#internal_macro_calls. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().0 { |
| 274 |
Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Ident#::newrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Ident]new().("Nested", Spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Span#::call_siterust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Span]call_site().()) |
| 275 |
} else { |
| 276 |
let name = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Nested{}", args.internal_macro_callsrust-analyzer cargo proc-macro-hack 0.5.19 ExportArgs#internal_macro_calls.); |
| 277 |
Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Ident#::newrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Ident]new().(&name, Spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Span#::call_siterust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Span]call_site().()) |
| 278 |
} |
| 279 |
} else { |
| 280 |
Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Ident#::newrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Ident]new().("Value", Spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Span#::call_siterust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Span]call_site().()) |
| 281 |
}; |
| 282 |
|
| 283 |
let from = export.fromrust-analyzer cargo proc-macro-hack 0.5.19 Export#from.; |
| 284 |
let mut actual_names = TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#::newrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream]new().(); |
| 285 |
let mut export_dispatch = TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#::newrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream]new().(); |
| 286 |
let mut export_call_site = TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#::newrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream]new().(); |
| 287 |
let mut macro_rules = TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#::newrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream]new().(); |
| 288 |
for Macrorust-analyzer cargo proc-macro-hack 0.5.19 Macro# { namerust-analyzer cargo proc-macro-hack 0.5.19 Macro#name., export_asrust-analyzer cargo proc-macro-hack 0.5.19 Macro#export_as. } in &export.macrosrust-analyzer cargo proc-macro-hack 0.5.19 Export#macros. { |
| 289 |
let hacked = hacked_proc_macro_namerust-analyzer cargo proc-macro-hack 0.5.19 hacked_proc_macro_name().(&name); |
| 290 |
let dispatch = dispatch_macro_namerust-analyzer cargo proc-macro-hack 0.5.19 dispatch_macro_name().(&name); |
| 291 |
let call_site = call_site_macro_namerust-analyzer cargo proc-macro-hack 0.5.19 call_site_macro_name().(&name); |
| 292 |
|
| 293 |
if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().actual_names.is_emptyrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream]is_empty().() { |
| 294 |
actual_names.extendrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!!(,)); |
| 295 |
} |
| 296 |
actual_names.extendrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!!(#hacked)); |
| 297 |
|
| 298 |
if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().export_dispatch.is_emptyrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream]is_empty().() { |
| 299 |
export_dispatch.extendrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!!(,)); |
| 300 |
} |
| 301 |
export_dispatch.extendrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!!(dispatch as #dispatch)); |
| 302 |
|
| 303 |
if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().export_call_site.is_emptyrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream]is_empty().() { |
| 304 |
export_call_site.extendrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!!(,)); |
| 305 |
} |
| 306 |
export_call_site.extendrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!!(fake_call_site as #call_site)); |
| 307 |
|
| 308 |
let do_derive = if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().args.fake_call_siterust-analyzer cargo proc-macro-hack 0.5.19 ExportArgs#fake_call_site. { |
| 309 |
quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!! { |
| 310 |
#[derive(#crate_prefix #hacked)] |
| 311 |
} |
| 312 |
} else if crate_prefix.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 313 |
quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!! { |
| 314 |
use #crate_prefix #hacked; |
| 315 |
#[#crate_prefix #call_site ($($proc_macro)*)] |
| 316 |
#[derive(#hacked)] |
| 317 |
} |
| 318 |
} else { |
| 319 |
quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!! { |
| 320 |
#[#call_site ($($proc_macro)*)] |
| 321 |
#[derive(#hacked)] |
| 322 |
} |
| 323 |
}; |
| 324 |
|
| 325 |
let proc_macro_call = if args.support_nestedrust-analyzer cargo proc-macro-hack 0.5.19 ExportArgs#support_nested. { |
| 326 |
let extra_bangs = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#args.internal_macro_callsrust-analyzer cargo proc-macro-hack 0.5.19 ExportArgs#internal_macro_calls.) |
| 327 |
.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|_| TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#::Punctrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#Punct#(Punctrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Punct#::newrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Punct]new().('!', Spacingrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Spacing#::Alonerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Spacing#Alone#))) |
| 328 |
.collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#>(); |
| 329 |
quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!! { |
| 330 |
#crate_prefix #dispatch! { ($($proc_macro)*) #extra_bangs } |
| 331 |
} |
| 332 |
} else { |
| 333 |
quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!! { |
| 334 |
proc_macro_call!() |
| 335 |
} |
| 336 |
}; |
| 337 |
|
| 338 |
macro_rules.extendrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!! { |
| 339 |
#attrs |
| 340 |
#macro_export |
| 341 |
macro_rules! #export_as { |
| 342 |
($($proc_macro:tt)*) => {{ |
| 343 |
#do_derive |
| 344 |
#[allow(dead_code)] |
| 345 |
enum ProcMacroHack { |
| 346 |
#enum_variant = (stringify! { $($proc_macro)* }, 0).1, |
| 347 |
} |
| 348 |
#proc_macro_call |
| 349 |
}}; |
| 350 |
} |
| 351 |
}); |
| 352 |
} |
| 353 |
|
| 354 |
if export.macrosrust-analyzer cargo proc-macro-hack 0.5.19 Export#macros..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().1 { |
| 355 |
export_dispatch = quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!!({#export_dispatch}); |
| 356 |
export_call_site = quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!!({#export_call_site}); |
| 357 |
actual_names = quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!!({#actual_names}); |
| 358 |
} |
| 359 |
|
| 360 |
let export_dispatch = if args.support_nestedrust-analyzer cargo proc-macro-hack 0.5.19 ExportArgs#support_nested. { |
| 361 |
quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!! { |
| 362 |
#[doc(hidden)] |
| 363 |
#vis use proc_macro_nested::#export_dispatch; |
| 364 |
} |
| 365 |
} else { |
| 366 |
quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!!() |
| 367 |
}; |
| 368 |
|
| 369 |
let export_call_site = if args.fake_call_siterust-analyzer cargo proc-macro-hack 0.5.19 ExportArgs#fake_call_site. { |
| 370 |
quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!! { |
| 371 |
#[doc(hidden)] |
| 372 |
#vis use proc_macro_hack::#export_call_site; |
| 373 |
} |
| 374 |
} else { |
| 375 |
quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!!() |
| 376 |
}; |
| 377 |
|
| 378 |
let expanded = quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!! { |
| 379 |
#[doc(hidden)] |
| 380 |
#vis use #from::#actual_names; |
| 381 |
|
| 382 |
#export_dispatch |
| 383 |
#export_call_site |
| 384 |
|
| 385 |
#macro_rules |
| 386 |
}; |
| 387 |
|
| 388 |
wrap_in_enum_hackrust-analyzer cargo proc-macro-hack 0.5.19 wrap_in_enum_hack().(dummy, expanded) |
| 389 |
} |
| 390 |
|
| 391 |
fn expand_export_nohackrust-analyzer cargo proc-macro-hack 0.5.19 expand_export_nohack().(export: Exportrust-analyzer cargo proc-macro-hack 0.5.19 Export#) -> TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream# { |
| 392 |
let attrs = export.attrsrust-analyzer cargo proc-macro-hack 0.5.19 Export#attrs.; |
| 393 |
let vis = export.visrust-analyzer cargo proc-macro-hack 0.5.19 Export#vis.; |
| 394 |
let from = export.fromrust-analyzer cargo proc-macro-hack 0.5.19 Export#from.; |
| 395 |
let mut names = TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#::newrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream]new().(); |
| 396 |
|
| 397 |
for Macrorust-analyzer cargo proc-macro-hack 0.5.19 Macro# { namerust-analyzer cargo proc-macro-hack 0.5.19 Macro#name., export_asrust-analyzer cargo proc-macro-hack 0.5.19 Macro#export_as. } in &export.macrosrust-analyzer cargo proc-macro-hack 0.5.19 Export#macros. { |
| 398 |
let pub_name = pub_proc_macro_namerust-analyzer cargo proc-macro-hack 0.5.19 pub_proc_macro_name().(&name); |
| 399 |
if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().names.is_emptyrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream]is_empty().() { |
| 400 |
names.extendrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!!(,)); |
| 401 |
} |
| 402 |
names.extendrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!!(#pub_name as #export_as)); |
| 403 |
} |
| 404 |
|
| 405 |
if export.macrosrust-analyzer cargo proc-macro-hack 0.5.19 Export#macros..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().1 { |
| 406 |
names = quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!!({#names}); |
| 407 |
} |
| 408 |
|
| 409 |
quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!! { |
| 410 |
#attrs |
| 411 |
#vis use #from::#names; |
| 412 |
} |
| 413 |
} |
| 414 |
|
| 415 |
fn expand_definerust-analyzer cargo proc-macro-hack 0.5.19 expand_define().(define: Definerust-analyzer cargo proc-macro-hack 0.5.19 Define#) -> TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream# { |
| 416 |
let attrs = define.attrsrust-analyzer cargo proc-macro-hack 0.5.19 Define#attrs.; |
| 417 |
let name = define.namerust-analyzer cargo proc-macro-hack 0.5.19 Define#name.; |
| 418 |
let pub_name = pub_proc_macro_namerust-analyzer cargo proc-macro-hack 0.5.19 pub_proc_macro_name().(&name); |
| 419 |
let hacked = hacked_proc_macro_namerust-analyzer cargo proc-macro-hack 0.5.19 hacked_proc_macro_name().(&name); |
| 420 |
let body = define.bodyrust-analyzer cargo proc-macro-hack 0.5.19 Define#body.; |
| 421 |
|
| 422 |
quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!! { |
| 423 |
mod #pub_name { |
| 424 |
extern crate proc_macro; |
| 425 |
pub use self::proc_macro::*; |
| 426 |
} |
| 427 |
|
| 428 |
#attrs |
| 429 |
#[doc(hidden)] |
| 430 |
#[proc_macro_derive(#hacked)] |
| 431 |
pub fn #hacked(input: #pub_name::TokenStream) -> #pub_name::TokenStream { |
| 432 |
use std::iter::FromIterator; |
| 433 |
|
| 434 |
let mut iter = input.into_iter(); |
| 435 |
iter.next().unwrap(); // `enum` |
| 436 |
iter.next().unwrap(); // `ProcMacroHack` |
| 437 |
iter.next().unwrap(); // `#` |
| 438 |
iter.next().unwrap(); // `[allow(dead_code)]` |
| 439 |
|
| 440 |
let mut braces = match iter.next().unwrap() { |
| 441 |
#pub_name::TokenTree::Group(group) => group.stream().into_iter(), |
| 442 |
_ => unimplemented!(), |
| 443 |
}; |
| 444 |
let variant = braces.next().unwrap(); // `Value` or `Nested` |
| 445 |
let varname = variant.to_string(); |
| 446 |
let support_nested = varname.starts_with("Nested"); |
| 447 |
braces.next().unwrap(); // `=` |
| 448 |
|
| 449 |
let mut parens = match braces.next().unwrap() { |
| 450 |
#pub_name::TokenTree::Group(group) => group.stream().into_iter(), |
| 451 |
_ => unimplemented!(), |
| 452 |
}; |
| 453 |
parens.next().unwrap(); // `stringify` |
| 454 |
parens.next().unwrap(); // `!` |
| 455 |
|
| 456 |
let inner = match parens.next().unwrap() { |
| 457 |
#pub_name::TokenTree::Group(group) => group.stream(), |
| 458 |
_ => unimplemented!(), |
| 459 |
}; |
| 460 |
|
| 461 |
let output: #pub_name::TokenStream = #name(inner.clone()); |
| 462 |
|
| 463 |
fn count_bangs(input: #pub_name::TokenStream) -> usize { |
| 464 |
let mut count = 0; |
| 465 |
for token in input { |
| 466 |
match token { |
| 467 |
#pub_name::TokenTree::Punct(punct) => { |
| 468 |
if punct.as_char() == '!' { |
| 469 |
count += 1; |
| 470 |
} |
| 471 |
} |
| 472 |
#pub_name::TokenTree::Group(group) => { |
| 473 |
count += count_bangs(group.stream()); |
| 474 |
} |
| 475 |
_ => {} |
| 476 |
} |
| 477 |
} |
| 478 |
count |
| 479 |
} |
| 480 |
|
| 481 |
// macro_rules! proc_macro_call { |
| 482 |
// () => { #output } |
| 483 |
// } |
| 484 |
#pub_name::TokenStream::from_iter(vec![ |
| 485 |
#pub_name::TokenTree::Ident( |
| 486 |
#pub_name::Ident::new("macro_rules", #pub_name::Span::call_site()), |
| 487 |
), |
| 488 |
#pub_name::TokenTree::Punct( |
| 489 |
#pub_name::Punct::new('!', #pub_name::Spacing::Alone), |
| 490 |
), |
| 491 |
#pub_name::TokenTree::Ident( |
| 492 |
#pub_name::Ident::new( |
| 493 |
&if support_nested { |
| 494 |
let extra_bangs = if varname == "Nested" { |
| 495 |
0 |
| 496 |
} else { |
| 497 |
varname["Nested".len()..].parse().unwrap() |
| 498 |
}; |
| 499 |
format!("proc_macro_call_{}", extra_bangs + count_bangs(inner)) |
| 500 |
} else { |
| 501 |
String::from("proc_macro_call") |
| 502 |
}, |
| 503 |
#pub_name::Span::call_site(), |
| 504 |
), |
| 505 |
), |
| 506 |
#pub_name::TokenTree::Group( |
| 507 |
#pub_name::Group::new(#pub_name::Delimiter::Brace, #pub_name::TokenStream::from_iter(vec![ |
| 508 |
#pub_name::TokenTree::Group( |
| 509 |
#pub_name::Group::new(#pub_name::Delimiter::Parenthesis, #pub_name::TokenStream::new()), |
| 510 |
), |
| 511 |
#pub_name::TokenTree::Punct( |
| 512 |
#pub_name::Punct::new('=', #pub_name::Spacing::Joint), |
| 513 |
), |
| 514 |
#pub_name::TokenTree::Punct( |
| 515 |
#pub_name::Punct::new('>', #pub_name::Spacing::Alone), |
| 516 |
), |
| 517 |
#pub_name::TokenTree::Group( |
| 518 |
#pub_name::Group::new(#pub_name::Delimiter::Brace, output), |
| 519 |
), |
| 520 |
])), |
| 521 |
), |
| 522 |
]) |
| 523 |
} |
| 524 |
|
| 525 |
#attrs |
| 526 |
#[proc_macro] |
| 527 |
pub fn #pub_name(input: #pub_name::TokenStream) -> #pub_name::TokenStream { |
| 528 |
#name(input) |
| 529 |
} |
| 530 |
|
| 531 |
fn #name #body |
| 532 |
} |
| 533 |
} |
| 534 |
|
| 535 |
fn pub_proc_macro_namerust-analyzer cargo proc-macro-hack 0.5.19 pub_proc_macro_name().(conceptual: &Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Ident#) -> Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Ident# { |
| 536 |
Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Ident#::newrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Ident]new().( |
| 537 |
&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("proc_macro_hack_{}", conceptual), |
| 538 |
conceptual.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Ident]span().(), |
| 539 |
) |
| 540 |
} |
| 541 |
|
| 542 |
fn hacked_proc_macro_namerust-analyzer cargo proc-macro-hack 0.5.19 hacked_proc_macro_name().(conceptual: &Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Ident#) -> Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Ident# { |
| 543 |
Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Ident#::newrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Ident]new().( |
| 544 |
&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("_proc_macro_hack_{}", conceptual), |
| 545 |
conceptual.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Ident]span().(), |
| 546 |
) |
| 547 |
} |
| 548 |
|
| 549 |
fn dispatch_macro_namerust-analyzer cargo proc-macro-hack 0.5.19 dispatch_macro_name().(conceptual: &Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Ident#) -> Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Ident# { |
| 550 |
Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Ident#::newrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Ident]new().( |
| 551 |
&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("proc_macro_call_{}", conceptual), |
| 552 |
conceptual.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Ident]span().(), |
| 553 |
) |
| 554 |
} |
| 555 |
|
| 556 |
fn call_site_macro_namerust-analyzer cargo proc-macro-hack 0.5.19 call_site_macro_name().(conceptual: &Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Ident#) -> Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Ident# { |
| 557 |
Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Ident#::newrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Ident]new().( |
| 558 |
&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("proc_macro_fake_call_site_{}", conceptual), |
| 559 |
conceptual.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Ident]span().(), |
| 560 |
) |
| 561 |
} |
| 562 |
|
| 563 |
fn dummy_name_for_exportrust-analyzer cargo proc-macro-hack 0.5.19 dummy_name_for_export().(export: &Exportrust-analyzer cargo proc-macro-hack 0.5.19 Export#) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 564 |
let mut dummy = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 565 |
let from = unrawrust-analyzer cargo proc-macro-hack 0.5.19 unraw().(&export.fromrust-analyzer cargo proc-macro-hack 0.5.19 Export#from.).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 566 |
writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(dummy, "_{}{}", from.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().(), from).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 567 |
for m in &export.macrosrust-analyzer cargo proc-macro-hack 0.5.19 Export#macros. { |
| 568 |
let name = unrawrust-analyzer cargo proc-macro-hack 0.5.19 unraw().(&m.namerust-analyzer cargo proc-macro-hack 0.5.19 Macro#name.).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 569 |
writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(dummy, "_{}{}", name.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().(), name).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 570 |
} |
| 571 |
dummy |
| 572 |
} |
| 573 |
|
| 574 |
fn unrawrust-analyzer cargo proc-macro-hack 0.5.19 unraw().(ident: &Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Ident#) -> Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Ident# { |
| 575 |
let string = ident.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 576 |
if string.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("r#") { |
| 577 |
Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Ident#::newrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Ident]new().(&string[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().2..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()., ident.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Ident]span().()) |
| 578 |
} else { |
| 579 |
ident.clonerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Ident][Clone]clone().() |
| 580 |
} |
| 581 |
} |
| 582 |
|
| 583 |
fn wrap_in_enum_hackrust-analyzer cargo proc-macro-hack 0.5.19 wrap_in_enum_hack().(dummy: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, inner: TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#) -> TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream# { |
| 584 |
let dummy = Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Ident#::newrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Ident]new().(&dummy, Spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Span#::call_siterust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Span]call_site().()); |
| 585 |
quoterust-analyzer cargo proc-macro-hack 0.5.19 quote/quote!! { |
| 586 |
#[derive(proc_macro_hack::ProcMacroHack)] |
| 587 |
enum #dummy { |
| 588 |
Value = (stringify! { #inner }, 0).1, |
| 589 |
} |
| 590 |
} |
| 591 |
} |