about summary refs log tree commit diff
path: root/src/librustc_span
diff options
context:
space:
mode:
authorMatthew Jasper <mjjasper1@gmail.com>2020-03-11 20:05:19 +0000
committerMatthew Jasper <mjjasper1@gmail.com>2020-03-16 17:13:48 +0000
commitec862703fde44d23f7da8bc5fdd94a63354d5daf (patch)
tree52274b2c56ff15da288b8472147a21d69fc07733 /src/librustc_span
parent59f4ba95045e91a63e921e0d736242d7e1ffabec (diff)
downloadrust-ec862703fde44d23f7da8bc5fdd94a63354d5daf.tar.gz
rust-ec862703fde44d23f7da8bc5fdd94a63354d5daf.zip
Make macro metavars respect (non-)hygiene
Diffstat (limited to 'src/librustc_span')
-rw-r--r--src/librustc_span/symbol.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/librustc_span/symbol.rs b/src/librustc_span/symbol.rs
index 5760e1d004e..7dfd6c58046 100644
--- a/src/librustc_span/symbol.rs
+++ b/src/librustc_span/symbol.rs
@@ -979,6 +979,31 @@ impl fmt::Display for IdentPrinter {
     }
 }
 
+/// An newtype around `Ident` that calls [Ident::normalize_to_macro_rules] on
+/// construction.
+// FIXME(matthewj, petrochenkov) Use this more often, add a similar
+// `ModernIdent` struct and use that as well.
+#[derive(Copy, Clone, Eq, PartialEq, Hash)]
+pub struct MacroRulesNormalizedIdent(Ident);
+
+impl MacroRulesNormalizedIdent {
+    pub fn new(ident: Ident) -> Self {
+        Self(ident.normalize_to_macro_rules())
+    }
+}
+
+impl fmt::Debug for MacroRulesNormalizedIdent {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        fmt::Debug::fmt(&self.0, f)
+    }
+}
+
+impl fmt::Display for MacroRulesNormalizedIdent {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        fmt::Display::fmt(&self.0, f)
+    }
+}
+
 /// An interned string.
 ///
 /// Internally, a `Symbol` is implemented as an index, and all operations