Skip to content

Commit e2d3e09

Browse files
bjorn3Mark-Simulacrum
authored andcommitted
Prevent macro ambiguity errors
The previous macro_rules! parsers failed when an additional modifier was added with ambiguity errors. The error is pretty unclear as to what exactly the cause here is, but this change simplifies the argument parsing code such that the error is avoided.
1 parent 6e12110 commit e2d3e09

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

compiler/rustc_macros/src/query.rs

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

456456
// Pass on the fatal_cycle modifier
457457
if let Some(fatal_cycle) = &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
let span = ty.span();
463-
attributes.push(quote_spanned! {span=> storage(#ty) });
463+
attributes.push(quote_spanned! {span=> (storage #ty) });
464464
};
465465
// Pass on the cycle_delay_bug modifier
466466
if let Some(cycle_delay_bug) = &modifiers.cycle_delay_bug {
467-
attributes.push(quote! { #cycle_delay_bug });
467+
attributes.push(quote! { (#cycle_delay_bug) });
468468
};
469469
// Pass on the no_hash modifier
470470
if let Some(no_hash) = &modifiers.no_hash {
471-
attributes.push(quote! { #no_hash });
471+
attributes.push(quote! { (#no_hash) });
472472
};
473473
// Pass on the anon modifier
474474
if let Some(anon) = &modifiers.anon {
475-
attributes.push(quote! { #anon });
475+
attributes.push(quote! { (#anon) });
476476
};
477477
// Pass on the eval_always modifier
478478
if let Some(eval_always) = &modifiers.eval_always {
479-
attributes.push(quote! { #eval_always });
479+
attributes.push(quote! { (#eval_always) });
480480
};
481481

482482
// This uses the span of the query definition for the commas,

compiler/rustc_middle/src/dep_graph/dep_node.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ macro_rules! is_eval_always_attr {
140140
}
141141

142142
macro_rules! contains_anon_attr {
143-
($($attr:ident $(($($attr_args:tt)*))* ),*) => ({$(is_anon_attr!($attr) | )* false});
143+
($(($attr:ident $($attr_args:tt)* )),*) => ({$(is_anon_attr!($attr) | )* false});
144144
}
145145

146146
macro_rules! contains_eval_always_attr {
147-
($($attr:ident $(($($attr_args:tt)*))* ),*) => ({$(is_eval_always_attr!($attr) | )* false});
147+
($(($attr:ident $($attr_args:tt)* )),*) => ({$(is_eval_always_attr!($attr) | )* false});
148148
}
149149

150150
#[allow(non_upper_case_globals)]

compiler/rustc_middle/src/ty/query.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ macro_rules! query_storage {
111111
([][$K:ty, $V:ty]) => {
112112
<DefaultCacheSelector as CacheSelector<$K, $V>>::Cache
113113
};
114-
([storage($ty:ty) $($rest:tt)*][$K:ty, $V:ty]) => {
114+
([(storage $ty:ty) $($rest:tt)*][$K:ty, $V:ty]) => {
115115
<$ty as CacheSelector<$K, $V>>::Cache
116116
};
117-
([$other:ident $(($($other_args:tt)*))* $(, $($modifiers:tt)*)*][$($args:tt)*]) => {
118-
query_storage!([$($($modifiers)*)*][$($args)*])
117+
([$other:tt $($modifiers:tt)*][$($args:tt)*]) => {
118+
query_storage!([$($modifiers)*][$($args)*])
119119
};
120120
}
121121

compiler/rustc_query_impl/src/plumbing.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -253,53 +253,53 @@ macro_rules! handle_cycle_error {
253253
$error.emit();
254254
Value::from_cycle_error($tcx)
255255
}};
256-
([fatal_cycle $($rest:tt)*][$tcx:expr, $error:expr]) => {{
256+
([(fatal_cycle) $($rest:tt)*][$tcx:expr, $error:expr]) => {{
257257
$error.emit();
258258
$tcx.sess.abort_if_errors();
259259
unreachable!()
260260
}};
261-
([cycle_delay_bug $($rest:tt)*][$tcx:expr, $error:expr]) => {{
261+
([(cycle_delay_bug) $($rest:tt)*][$tcx:expr, $error:expr]) => {{
262262
$error.delay_as_bug();
263263
Value::from_cycle_error($tcx)
264264
}};
265-
([$other:ident $(($($other_args:tt)*))* $(, $($modifiers:tt)*)*][$($args:tt)*]) => {
266-
handle_cycle_error!([$($($modifiers)*)*][$($args)*])
265+
([$other:tt $($modifiers:tt)*][$($args:tt)*]) => {
266+
handle_cycle_error!([$($modifiers)*][$($args)*])
267267
};
268268
}
269269

270270
macro_rules! is_anon {
271271
([]) => {{
272272
false
273273
}};
274-
([anon $($rest:tt)*]) => {{
274+
([(anon) $($rest:tt)*]) => {{
275275
true
276276
}};
277-
([$other:ident $(($($other_args:tt)*))* $(, $($modifiers:tt)*)*]) => {
278-
is_anon!([$($($modifiers)*)*])
277+
([$other:tt $($modifiers:tt)*]) => {
278+
is_anon!([$($modifiers)*])
279279
};
280280
}
281281

282282
macro_rules! is_eval_always {
283283
([]) => {{
284284
false
285285
}};
286-
([eval_always $($rest:tt)*]) => {{
286+
([(eval_always) $($rest:tt)*]) => {{
287287
true
288288
}};
289-
([$other:ident $(($($other_args:tt)*))* $(, $($modifiers:tt)*)*]) => {
290-
is_eval_always!([$($($modifiers)*)*])
289+
([$other:tt $($modifiers:tt)*]) => {
290+
is_eval_always!([$($modifiers)*])
291291
};
292292
}
293293

294294
macro_rules! hash_result {
295295
([][$hcx:expr, $result:expr]) => {{
296296
dep_graph::hash_result($hcx, &$result)
297297
}};
298-
([no_hash $($rest:tt)*][$hcx:expr, $result:expr]) => {{
298+
([(no_hash) $($rest:tt)*][$hcx:expr, $result:expr]) => {{
299299
None
300300
}};
301-
([$other:ident $(($($other_args:tt)*))* $(, $($modifiers:tt)*)*][$($args:tt)*]) => {
302-
hash_result!([$($($modifiers)*)*][$($args)*])
301+
([$other:tt $($modifiers:tt)*][$($args:tt)*]) => {
302+
hash_result!([$($modifiers)*][$($args)*])
303303
};
304304
}
305305

0 commit comments

Comments
 (0)