From a2389eeaa85a79ff8c58525df912ff1aafb16e9f Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 19 Jun 2022 19:05:44 -0700 Subject: [PATCH] Call 'format!' through an unambiguous path Repro: use quote::format_ident; macro_rules! format { () => {}; } fn main() { let _ = format_ident!("foo"); } Previously: error: no rules expected the token `"foo"` --> src/main.rs:8:13 | 3 | macro_rules! format { | ------------------- when calling this macro ... 8 | let _ = format_ident!("foo"); | ^^^^^^^^^^^^^^^^^^^^ no rules expected this token in macro call | = note: this error originates in the macro `format_ident` (in Nightly builds, run with -Z macro-backtrace for more info) --- src/format.rs | 5 ++++- src/runtime.rs | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/format.rs b/src/format.rs index 5e44b01..f7b1e03 100644 --- a/src/format.rs +++ b/src/format.rs @@ -129,7 +129,10 @@ macro_rules! format_ident { macro_rules! format_ident_impl { // Final state ([$span:expr, $($fmt:tt)*]) => { - $crate::__private::mk_ident(&format!($($fmt)*), $span) + $crate::__private::mk_ident( + &$crate::__private::format!($($fmt)*), + $span, + ) }; // Span argument diff --git a/src/runtime.rs b/src/runtime.rs index 14dd3ba..b6950ba 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -4,6 +4,7 @@ use std::iter; use std::ops::BitOr; pub use proc_macro2::*; +pub use std::format; pub struct HasIterator; // True pub struct ThereIsNoIteratorInRepetition; // False