diff options
| author | Matthew Jasper <mjjasper1@gmail.com> | 2020-03-11 20:05:19 +0000 |
|---|---|---|
| committer | Matthew Jasper <mjjasper1@gmail.com> | 2020-03-16 17:13:48 +0000 |
| commit | ec862703fde44d23f7da8bc5fdd94a63354d5daf (patch) | |
| tree | 52274b2c56ff15da288b8472147a21d69fc07733 /src/librustc_span | |
| parent | 59f4ba95045e91a63e921e0d736242d7e1ffabec (diff) | |
| download | rust-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.rs | 25 |
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 |
