From a03cf1b502484a1edb443436c9fbf48df0b7664f Mon Sep 17 00:00:00 2001
From: Aaron Hill <aa1ronham@gmail.com>
Date: Mon, 7 Jun 2021 17:06:47 -0500
Subject: [PATCH] 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'
---
 compiler/rustc_macros/src/query.rs        | 10 +++++-----
 compiler/rustc_middle/src/ty/query/mod.rs |  2 +-
 compiler/rustc_query_impl/src/plumbing.rs | 18 +++++++++---------
 3 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/compiler/rustc_macros/src/query.rs b/compiler/rustc_macros/src/query.rs
index 291e7ef045e4f..6b664a662833f 100644
--- a/compiler/rustc_macros/src/query.rs
+++ b/compiler/rustc_macros/src/query.rs
@@ -455,7 +455,7 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
 
         // Pass on the fatal_cycle modifier
         if modifiers.fatal_cycle {
-            attributes.push(quote! { fatal_cycle });
+            attributes.push(quote! { fatal_cycle() });
         };
         // Pass on the storage modifier
         if let Some(ref ty) = modifiers.storage {
@@ -463,19 +463,19 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
         };
         // Pass on the cycle_delay_bug modifier
         if modifiers.cycle_delay_bug {
-            attributes.push(quote! { cycle_delay_bug });
+            attributes.push(quote! { cycle_delay_bug() });
         };
         // Pass on the no_hash modifier
         if modifiers.no_hash {
-            attributes.push(quote! { no_hash });
+            attributes.push(quote! { no_hash() });
         };
         // Pass on the anon modifier
         if modifiers.anon {
-            attributes.push(quote! { anon });
+            attributes.push(quote! { anon() });
         };
         // Pass on the eval_always modifier
         if modifiers.eval_always {
-            attributes.push(quote! { eval_always });
+            attributes.push(quote! { eval_always() });
         };
 
         let attribute_stream = quote! {#(#attributes),*};
diff --git a/compiler/rustc_middle/src/ty/query/mod.rs b/compiler/rustc_middle/src/ty/query/mod.rs
index 297110ee3ecff..0aa2cd3d23ecc 100644
--- a/compiler/rustc_middle/src/ty/query/mod.rs
+++ b/compiler/rustc_middle/src/ty/query/mod.rs
@@ -116,7 +116,7 @@ macro_rules! query_storage {
     ([storage($ty:ty) $($rest:tt)*][$K:ty, $V:ty]) => {
         <$ty as CacheSelector<$K, $V>>::Cache
     };
-    ([$other:ident $(($($other_args:tt)*))* $(, $($modifiers:tt)*)*][$($args:tt)*]) => {
+    ([$other:ident ($($other_args:tt)*) $(, $($modifiers:tt)*)*][$($args:tt)*]) => {
         query_storage!([$($($modifiers)*)*][$($args)*])
     };
 }
diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs
index b4191c135b4f9..4044ae0e355fb 100644
--- a/compiler/rustc_query_impl/src/plumbing.rs
+++ b/compiler/rustc_query_impl/src/plumbing.rs
@@ -219,16 +219,16 @@ macro_rules! handle_cycle_error {
         $error.emit();
         Value::from_cycle_error($tcx)
     }};
-    ([fatal_cycle $($rest:tt)*][$tcx:expr, $error:expr]) => {{
+    ([fatal_cycle() $($rest:tt)*][$tcx:expr, $error:expr]) => {{
         $error.emit();
         $tcx.sess.abort_if_errors();
         unreachable!()
     }};
-    ([cycle_delay_bug $($rest:tt)*][$tcx:expr, $error:expr]) => {{
+    ([cycle_delay_bug() $($rest:tt)*][$tcx:expr, $error:expr]) => {{
         $error.delay_as_bug();
         Value::from_cycle_error($tcx)
     }};
-    ([$other:ident $(($($other_args:tt)*))* $(, $($modifiers:tt)*)*][$($args:tt)*]) => {
+    ([$other:ident ($($other_args:tt)*) $(, $($modifiers:tt)*)*][$($args:tt)*]) => {
         handle_cycle_error!([$($($modifiers)*)*][$($args)*])
     };
 }
@@ -237,10 +237,10 @@ macro_rules! is_anon {
     ([]) => {{
         false
     }};
-    ([anon $($rest:tt)*]) => {{
+    ([anon() $($rest:tt)*]) => {{
         true
     }};
-    ([$other:ident $(($($other_args:tt)*))* $(, $($modifiers:tt)*)*]) => {
+    ([$other:ident ($($other_args:tt)*) $(, $($modifiers:tt)*)*]) => {
         is_anon!([$($($modifiers)*)*])
     };
 }
@@ -249,10 +249,10 @@ macro_rules! is_eval_always {
     ([]) => {{
         false
     }};
-    ([eval_always $($rest:tt)*]) => {{
+    ([eval_always() $($rest:tt)*]) => {{
         true
     }};
-    ([$other:ident $(($($other_args:tt)*))* $(, $($modifiers:tt)*)*]) => {
+    ([$other:ident ($($other_args:tt)*) $(, $($modifiers:tt)*)*]) => {
         is_eval_always!([$($($modifiers)*)*])
     };
 }
@@ -261,10 +261,10 @@ macro_rules! hash_result {
     ([][$hcx:expr, $result:expr]) => {{
         dep_graph::hash_result($hcx, &$result)
     }};
-    ([no_hash $($rest:tt)*][$hcx:expr, $result:expr]) => {{
+    ([no_hash() $($rest:tt)*][$hcx:expr, $result:expr]) => {{
         None
     }};
-    ([$other:ident $(($($other_args:tt)*))* $(, $($modifiers:tt)*)*][$($args:tt)*]) => {
+    ([$other:ident ($($other_args:tt)*) $(, $($modifiers:tt)*)*][$($args:tt)*]) => {
         hash_result!([$($($modifiers)*)*][$($args)*])
     };
 }