Skip to content

Commit 3f1ae66

Browse files
theduketheduke
authored andcommitted
Refactor macros to use $crate:: method instead of local_inner_macros.
This commit refactors the macros to use the $crate::inner_macro trick instead of local_inner_macros. This is possible since we only support rust 1.30 as a minimum version. (the $crate:: method only works on 1.30+). With this change, the wrapper helper macros for std macros can also be removed.
1 parent dee849c commit 3f1ae66

File tree

6 files changed

+107
-132
lines changed

6 files changed

+107
-132
lines changed

juniper/src/macros/common.rs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ macro_rules! __juniper_parse_object_header {
6161
$($items: tt)*
6262
}
6363
) => {
64-
$callback!(
64+
$crate::$callback!(
6565
@parse,
6666
meta = {
6767
lifetimes = [$($lifetime,)*],
@@ -82,7 +82,7 @@ macro_rules! __juniper_parse_object_header {
8282
$($items: tt)*
8383
}
8484
) => {
85-
$callback!(
85+
$crate::$callback!(
8686
@parse,
8787
meta = {
8888
lifetimes = [$($lifetime,)*],
@@ -102,7 +102,7 @@ macro_rules! __juniper_parse_object_header {
102102
$($items: tt)*
103103
}
104104
) => {
105-
$callback!(
105+
$crate::$callback!(
106106
@parse,
107107
meta = {
108108
lifetimes = [$($lifetime,)*],
@@ -123,7 +123,7 @@ macro_rules! __juniper_parse_object_header {
123123
$($items: tt)*
124124
}
125125
) => {
126-
$callback!(
126+
$crate::$callback!(
127127
@parse,
128128
meta = {
129129
lifetimes = [],
@@ -144,7 +144,7 @@ macro_rules! __juniper_parse_object_header {
144144
$($items: tt)*
145145
}
146146
) => {
147-
$callback!(
147+
$crate::$callback!(
148148
@parse,
149149
meta = {
150150
lifetimes = [],
@@ -165,7 +165,7 @@ macro_rules! __juniper_parse_object_header {
165165
$($items: tt)*
166166
}
167167
) => {
168-
$callback!(
168+
$crate::$callback!(
169169
@parse,
170170
meta = {
171171
lifetimes = [],
@@ -186,7 +186,7 @@ macro_rules! __juniper_parse_object_header {
186186
$($items: tt)*
187187
}
188188
) => {
189-
$callback!(
189+
$crate::$callback!(
190190
@parse,
191191
meta = {
192192
lifetimes = [$($lifetime,)*],
@@ -207,7 +207,7 @@ macro_rules! __juniper_parse_object_header {
207207
$($items: tt)*
208208
}
209209
) => {
210-
$callback!(
210+
$crate::$callback!(
211211
@parse,
212212
meta = {
213213
lifetimes = [$($lifetime,)*],
@@ -227,7 +227,7 @@ macro_rules! __juniper_parse_object_header {
227227
$($items: tt)*
228228
}
229229
) => {
230-
$callback!(
230+
$crate::$callback!(
231231
@parse,
232232
meta = {
233233
lifetimes = [$($lifetime,)*],
@@ -250,7 +250,7 @@ macro_rules! __juniper_parse_object_header {
250250
$($items: tt)*
251251
}
252252
) => {
253-
$callback!(
253+
$crate::$callback!(
254254
@parse,
255255
meta = {
256256
lifetimes = [],
@@ -270,7 +270,7 @@ macro_rules! __juniper_parse_object_header {
270270
$($items: tt)*
271271
}
272272
) => {
273-
$callback!(
273+
$crate::$callback!(
274274
@parse,
275275
meta = {
276276
lifetimes = [],
@@ -290,7 +290,7 @@ macro_rules! __juniper_parse_object_header {
290290
$($items: tt)*
291291
}
292292
) => {
293-
$callback!(
293+
$crate::$callback!(
294294
@parse,
295295
meta = {
296296
lifetimes = [],
@@ -311,7 +311,6 @@ macro_rules! __juniper_parse_object_header {
311311
};
312312
}
313313

314-
315314
#[doc(hidden)]
316315
#[macro_export]
317316
macro_rules! __juniper_parse_field_list {
@@ -322,7 +321,7 @@ macro_rules! __juniper_parse_field_list {
322321
items = [$({$($items: tt)*},)*],
323322
rest =
324323
) => {
325-
$success_callback!(
324+
$crate::$success_callback!(
326325
@generate,
327326
meta = {$($meta)*},
328327
items = [$({$($items)*},)*],
@@ -336,7 +335,7 @@ macro_rules! __juniper_parse_field_list {
336335
items = [$({$($items: tt)*},)*],
337336
rest = , $($rest: tt)*
338337
) => {
339-
__juniper_parse_field_list!(
338+
$crate::__juniper_parse_field_list!(
340339
success_callback = $success_callback,
341340
additional_parser = {$($additional)*},
342341
meta = {$($meta)*},
@@ -363,7 +362,7 @@ macro_rules! __juniper_parse_field_list {
363362
items = [$({$($items: tt)*},)*],
364363
rest = $desc: tt $($rest:tt)*
365364
) => {
366-
__juniper_parse_field_list!(
365+
$crate::__juniper_parse_field_list!(
367366
success_callback = $success_callback,
368367
additional_parser = {$($additional)*},
369368
meta = {
@@ -388,7 +387,7 @@ macro_rules! __juniper_parse_field_list {
388387
items = [$({$($items: tt)*},)*],
389388
rest = description: $($rest:tt)*
390389
) => {
391-
__juniper_parse_field_list!(
390+
$crate::__juniper_parse_field_list!(
392391
@parse_description,
393392
success_callback = $success_callback,
394393
additional_parser = {$($additional)*},
@@ -411,7 +410,7 @@ macro_rules! __juniper_parse_field_list {
411410
) -> $return_ty: ty $body: block
412411
$($rest:tt)*
413412
) => {
414-
__juniper_parse_field_list!(
413+
$crate::__juniper_parse_field_list!(
415414
success_callback = $success_callback,
416415
additional_parser = {$($additional)*},
417416
meta = {$($meta)*},
@@ -446,7 +445,7 @@ macro_rules! __juniper_parse_field_list {
446445
) -> $return_ty: ty $body: block
447446
$($rest:tt)*
448447
) => {
449-
__juniper_parse_field_list!(
448+
$crate::__juniper_parse_field_list!(
450449
success_callback = $success_callback,
451450
additional_parser = {$($additional)*},
452451
meta = {$($meta)*},
@@ -479,7 +478,7 @@ macro_rules! __juniper_parse_field_list {
479478
) -> $return_ty: ty $(as $desc: tt)* $body: block
480479
$($rest:tt)*
481480
) => {
482-
__juniper_parse_field_list!(
481+
$crate::__juniper_parse_field_list!(
483482
success_callback = $success_callback,
484483
additional_parser = {$($additional)*},
485484
meta = {$($meta)*},
@@ -513,7 +512,7 @@ macro_rules! __juniper_parse_field_list {
513512
) -> $return_ty: ty $(as $desc: tt)* $body: block
514513
$($rest:tt)*
515514
) => {
516-
__juniper_parse_field_list!(
515+
$crate::__juniper_parse_field_list!(
517516
success_callback = $success_callback,
518517
additional_parser = {$($additional)*},
519518
meta = {$($meta)*},
@@ -546,7 +545,7 @@ macro_rules! __juniper_parse_field_list {
546545
items = [$({$($items: tt)*},)*],
547546
rest = $($rest:tt)*
548547
) => {
549-
$callback!(
548+
$crate::$callback!(
550549
$($header)*
551550
success_callback = $success_callback,
552551
additional_parser = {
@@ -586,7 +585,7 @@ macro_rules! __juniper_parse_instance_resolver {
586585
$( $srctype:ty => $resolver:expr ),* $(,)*
587586
} $($rest:tt)*
588587
) => {
589-
__juniper_parse_field_list!(
588+
$crate::__juniper_parse_field_list!(
590589
success_callback = $success_callback,
591590
additional_parser = {$($additional)*},
592591
meta = {
@@ -633,7 +632,7 @@ macro_rules! __juniper_parse_instance_resolver {
633632
items = [$({$($items: tt)*},)*],
634633
rest = instance_resolvers: |$(&)* _| {$( $srctype:ty => $resolver:expr ),* $(,)*} $($rest:tt)*
635634
) => {
636-
__juniper_parse_field_list!(
635+
$crate::__juniper_parse_field_list!(
637636
success_callback = $success_callback,
638637
additional_parser = {$($additional)*},
639638
meta = {

juniper/src/macros/interface.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ graphql_interface!(<'a> &'a Character: Database as "Character" |&self| {
8585
[1]: macro.graphql_object!.html
8686
8787
*/
88-
#[macro_export(local_inner_macros)]
88+
#[macro_export]
8989
macro_rules! graphql_interface {
9090

9191
(
@@ -127,7 +127,7 @@ macro_rules! graphql_interface {
127127
$(executor_var = $executor: ident,)*
128128
},)*],
129129
) => {
130-
__juniper_impl_trait!(
130+
$crate::__juniper_impl_trait!(
131131
impl<$($scalar)* $(, $lifetimes)* > GraphQLType for $name {
132132
type Context = $ctx;
133133
type TypeInfo = ();
@@ -138,25 +138,25 @@ macro_rules! graphql_interface {
138138

139139
fn meta<'r>(
140140
info: &Self::TypeInfo,
141-
registry: &mut $crate::Registry<'r, __juniper_insert_generic!($($scalar)+)>
142-
) -> $crate::meta::MetaType<'r, __juniper_insert_generic!($($scalar)+)>
143-
where for<'__b> &'__b __juniper_insert_generic!($($scalar)+): $crate::ScalarRefValue<'__b>,
144-
__juniper_insert_generic!($($scalar)+): 'r
141+
registry: &mut $crate::Registry<'r, $crate::__juniper_insert_generic!($($scalar)+)>
142+
) -> $crate::meta::MetaType<'r, $crate::__juniper_insert_generic!($($scalar)+)>
143+
where for<'__b> &'__b $crate::__juniper_insert_generic!($($scalar)+): $crate::ScalarRefValue<'__b>,
144+
$crate::__juniper_insert_generic!($($scalar)+): 'r
145145
{
146146
// Ensure all child types are registered
147147
$(
148148
let _ = registry.get_type::<$resolver_src>(info);
149149
)*
150150
let fields = &[$(
151151
registry.field_convert::<$return_ty, _, Self::Context>(
152-
&$crate::to_camel_case(__graphql__stringify!($fn_name)),
152+
&$crate::to_camel_case(stringify!($fn_name)),
153153
info
154154
)
155155
$(.description($fn_description))*
156156
.push_docstring(&[$($docstring,)*])
157157
$(.deprecated($deprecated))*
158158
$(.argument(
159-
__juniper_create_arg!(
159+
$crate::__juniper_create_arg!(
160160
registry = registry,
161161
info = info,
162162
arg_ty = $arg_ty,
@@ -180,17 +180,17 @@ macro_rules! graphql_interface {
180180
&$main_self,
181181
info: &Self::TypeInfo,
182182
field: &str,
183-
args: &$crate::Arguments<__juniper_insert_generic!($($scalar)+)>,
184-
executor: &$crate::Executor<Self::Context, __juniper_insert_generic!($($scalar)+)>
185-
) -> $crate::ExecutionResult<__juniper_insert_generic!($($scalar)+)> {
183+
args: &$crate::Arguments<$crate::__juniper_insert_generic!($($scalar)+)>,
184+
executor: &$crate::Executor<Self::Context, $crate::__juniper_insert_generic!($($scalar)+)>
185+
) -> $crate::ExecutionResult<$crate::__juniper_insert_generic!($($scalar)+)> {
186186
$(
187-
if field == &$crate::to_camel_case(__graphql__stringify!($fn_name)) {
187+
if field == &$crate::to_camel_case(stringify!($fn_name)) {
188188
let result: $return_ty = (|| {
189189
$(
190190
let $arg_name: $arg_ty = args.get(&$crate::to_camel_case(stringify!($arg_name)))
191-
.expect(__graphql__concat!(
191+
.expect(concat!(
192192
"Argument ",
193-
__graphql__stringify!($arg_name),
193+
stringify!($arg_name),
194194
" missing - validation must have failed"
195195
));
196196
)*
@@ -213,7 +213,7 @@ macro_rules! graphql_interface {
213213
}
214214
)*
215215

216-
__graphql__panic!("Field {} not found on type {}", field, $($outname)*)
216+
panic!("Field {} not found on type {}", field, $($outname)*)
217217
}
218218

219219
#[allow(unused_variables)]
@@ -227,16 +227,16 @@ macro_rules! graphql_interface {
227227
}
228228
)*
229229

230-
__graphql__panic!("Concrete type not handled by instance resolvers on {}", $($outname)*);
230+
panic!("Concrete type not handled by instance resolvers on {}", $($outname)*);
231231
}
232232

233233
fn resolve_into_type(
234234
&$main_self,
235235
_info: &Self::TypeInfo,
236236
type_name: &str,
237-
_: Option<&[$crate::Selection<__juniper_insert_generic!($($scalar)*)>]>,
238-
executor: &$crate::Executor<Self::Context, __juniper_insert_generic!($($scalar)*)>,
239-
) -> $crate::ExecutionResult<__juniper_insert_generic!($($scalar)*)> {
237+
_: Option<&[$crate::Selection<$crate::__juniper_insert_generic!($($scalar)*)>]>,
238+
executor: &$crate::Executor<Self::Context, $crate::__juniper_insert_generic!($($scalar)*)>,
239+
) -> $crate::ExecutionResult<$crate::__juniper_insert_generic!($($scalar)*)> {
240240
$(let $resolver_ctx = &executor.context();)*
241241

242242
$(
@@ -245,7 +245,7 @@ macro_rules! graphql_interface {
245245
}
246246
)*
247247

248-
__graphql__panic!("Concrete type not handled by instance resolvers on {}", $($outname)*);
248+
panic!("Concrete type not handled by instance resolvers on {}", $($outname)*);
249249
}
250250
}
251251
);
@@ -256,7 +256,7 @@ macro_rules! graphql_interface {
256256
meta = {$($meta:tt)*},
257257
rest = $($rest:tt)*
258258
) => {
259-
__juniper_parse_field_list!(
259+
$crate::__juniper_parse_field_list!(
260260
success_callback = graphql_interface,
261261
additional_parser = {
262262
callback = __juniper_parse_instance_resolver,
@@ -269,13 +269,13 @@ macro_rules! graphql_interface {
269269
};
270270

271271
(@$($stuff:tt)*) => {
272-
__graphql__compile_error!("Invalid syntax for `graphql_interface!`");
272+
compile_error!("Invalid syntax for `graphql_interface!`");
273273
};
274274

275275
(
276276
$($rest:tt)*
277277
) => {
278-
__juniper_parse_object_header!(
278+
$crate::__juniper_parse_object_header!(
279279
callback = graphql_interface,
280280
rest = $($rest)*
281281
);

juniper/src/macros/mod.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,5 @@
11
// Wrapper macros which allows built-in macros to be recognized as "crate-local".
22

3-
#[doc(hidden)]
4-
#[macro_export]
5-
macro_rules! __graphql__panic {
6-
($($t:tt)*) => ( panic!($($t)*) );
7-
}
8-
9-
#[doc(hidden)]
10-
#[macro_export]
11-
macro_rules! __graphql__stringify {
12-
($($t:tt)*) => ( stringify!($($t)*) );
13-
}
14-
15-
#[doc(hidden)]
16-
#[macro_export]
17-
macro_rules! __graphql__concat {
18-
($($t:tt)*) => ( concat!($($t)*) );
19-
}
20-
21-
#[doc(hidden)]
22-
#[macro_export]
23-
macro_rules! __graphql__compile_error {
24-
($t:expr) => ( compile_error!($t) );
25-
}
26-
273
#[macro_use]
284
mod common;
295
#[macro_use]

0 commit comments

Comments
 (0)