Skip to content

Commit a03cf1b

Browse files
committed
Avoid ambiguity by always using parens for query modifiers
Otherwise, we can get an ambiguity error (with multiple comma-separated modifiers) because the parents can either be parsed as the 'arg', or part of the undifferentiated 'other arguments'
1 parent a277c20 commit a03cf1b

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

compiler/rustc_macros/src/query.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -455,27 +455,27 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
455455

456456
// Pass on the fatal_cycle modifier
457457
if modifiers.fatal_cycle {
458-
attributes.push(quote! { fatal_cycle });
458+
attributes.push(quote! { fatal_cycle() });
459459
};
460460
// Pass on the storage modifier
461461
if let Some(ref ty) = modifiers.storage {
462462
attributes.push(quote! { storage(#ty) });
463463
};
464464
// Pass on the cycle_delay_bug modifier
465465
if modifiers.cycle_delay_bug {
466-
attributes.push(quote! { cycle_delay_bug });
466+
attributes.push(quote! { cycle_delay_bug() });
467467
};
468468
// Pass on the no_hash modifier
469469
if modifiers.no_hash {
470-
attributes.push(quote! { no_hash });
470+
attributes.push(quote! { no_hash() });
471471
};
472472
// Pass on the anon modifier
473473
if modifiers.anon {
474-
attributes.push(quote! { anon });
474+
attributes.push(quote! { anon() });
475475
};
476476
// Pass on the eval_always modifier
477477
if modifiers.eval_always {
478-
attributes.push(quote! { eval_always });
478+
attributes.push(quote! { eval_always() });
479479
};
480480

481481
let attribute_stream = quote! {#(#attributes),*};

compiler/rustc_middle/src/ty/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ macro_rules! query_storage {
116116
([storage($ty:ty) $($rest:tt)*][$K:ty, $V:ty]) => {
117117
<$ty as CacheSelector<$K, $V>>::Cache
118118
};
119-
([$other:ident $(($($other_args:tt)*))* $(, $($modifiers:tt)*)*][$($args:tt)*]) => {
119+
([$other:ident ($($other_args:tt)*) $(, $($modifiers:tt)*)*][$($args:tt)*]) => {
120120
query_storage!([$($($modifiers)*)*][$($args)*])
121121
};
122122
}

compiler/rustc_query_impl/src/plumbing.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -219,16 +219,16 @@ macro_rules! handle_cycle_error {
219219
$error.emit();
220220
Value::from_cycle_error($tcx)
221221
}};
222-
([fatal_cycle $($rest:tt)*][$tcx:expr, $error:expr]) => {{
222+
([fatal_cycle() $($rest:tt)*][$tcx:expr, $error:expr]) => {{
223223
$error.emit();
224224
$tcx.sess.abort_if_errors();
225225
unreachable!()
226226
}};
227-
([cycle_delay_bug $($rest:tt)*][$tcx:expr, $error:expr]) => {{
227+
([cycle_delay_bug() $($rest:tt)*][$tcx:expr, $error:expr]) => {{
228228
$error.delay_as_bug();
229229
Value::from_cycle_error($tcx)
230230
}};
231-
([$other:ident $(($($other_args:tt)*))* $(, $($modifiers:tt)*)*][$($args:tt)*]) => {
231+
([$other:ident ($($other_args:tt)*) $(, $($modifiers:tt)*)*][$($args:tt)*]) => {
232232
handle_cycle_error!([$($($modifiers)*)*][$($args)*])
233233
};
234234
}
@@ -237,10 +237,10 @@ macro_rules! is_anon {
237237
([]) => {{
238238
false
239239
}};
240-
([anon $($rest:tt)*]) => {{
240+
([anon() $($rest:tt)*]) => {{
241241
true
242242
}};
243-
([$other:ident $(($($other_args:tt)*))* $(, $($modifiers:tt)*)*]) => {
243+
([$other:ident ($($other_args:tt)*) $(, $($modifiers:tt)*)*]) => {
244244
is_anon!([$($($modifiers)*)*])
245245
};
246246
}
@@ -249,10 +249,10 @@ macro_rules! is_eval_always {
249249
([]) => {{
250250
false
251251
}};
252-
([eval_always $($rest:tt)*]) => {{
252+
([eval_always() $($rest:tt)*]) => {{
253253
true
254254
}};
255-
([$other:ident $(($($other_args:tt)*))* $(, $($modifiers:tt)*)*]) => {
255+
([$other:ident ($($other_args:tt)*) $(, $($modifiers:tt)*)*]) => {
256256
is_eval_always!([$($($modifiers)*)*])
257257
};
258258
}
@@ -261,10 +261,10 @@ macro_rules! hash_result {
261261
([][$hcx:expr, $result:expr]) => {{
262262
dep_graph::hash_result($hcx, &$result)
263263
}};
264-
([no_hash $($rest:tt)*][$hcx:expr, $result:expr]) => {{
264+
([no_hash() $($rest:tt)*][$hcx:expr, $result:expr]) => {{
265265
None
266266
}};
267-
([$other:ident $(($($other_args:tt)*))* $(, $($modifiers:tt)*)*][$($args:tt)*]) => {
267+
([$other:ident ($($other_args:tt)*) $(, $($modifiers:tt)*)*][$($args:tt)*]) => {
268268
hash_result!([$($($modifiers)*)*][$($args)*])
269269
};
270270
}

0 commit comments

Comments
 (0)