@@ -14,10 +14,6 @@ use syntax::{ast, SmolStr, SyntaxKind};
1414#[ derive( Debug , Clone , PartialEq , Eq , Hash , PartialOrd , Ord ) ]
1515pub struct Name ( Repr ) ;
1616
17- /// `EscapedName` will add a prefix "r#" to the wrapped `Name` when it is a raw identifier
18- #[ derive( Debug , Clone , PartialEq , Eq , Hash , PartialOrd , Ord ) ]
19- pub struct EscapedName < ' a > ( & ' a Name ) ;
20-
2117/// Wrapper of `Name` to print the name without "r#" even when it is a raw identifier.
2218#[ derive( Debug , Clone , PartialEq , Eq , Hash , PartialOrd , Ord ) ]
2319pub struct UnescapedName < ' a > ( & ' a Name ) ;
@@ -42,21 +38,6 @@ fn is_raw_identifier(name: &str) -> bool {
4238 is_keyword && !matches ! ( name, "self" | "crate" | "super" | "Self" )
4339}
4440
45- impl < ' a > fmt:: Display for EscapedName < ' a > {
46- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
47- match & self . 0 . 0 {
48- Repr :: Text ( text) => {
49- if is_raw_identifier ( text) {
50- write ! ( f, "r#{}" , & text)
51- } else {
52- fmt:: Display :: fmt ( & text, f)
53- }
54- }
55- Repr :: TupleField ( idx) => fmt:: Display :: fmt ( & idx, f) ,
56- }
57- }
58- }
59-
6041impl < ' a > fmt:: Display for UnescapedName < ' a > {
6142 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
6243 match & self . 0 . 0 {
@@ -86,31 +67,6 @@ impl<'a> UnescapedName<'a> {
8667 }
8768}
8869
89- impl < ' a > EscapedName < ' a > {
90- pub fn is_escaped ( & self ) -> bool {
91- match & self . 0 . 0 {
92- Repr :: Text ( it) => is_raw_identifier ( & it) ,
93- Repr :: TupleField ( _) => false ,
94- }
95- }
96-
97- /// Returns the textual representation of this name as a [`SmolStr`].
98- /// Prefer using this over [`ToString::to_string`] if possible as this conversion is cheaper in
99- /// the general case.
100- pub fn to_smol_str ( & self ) -> SmolStr {
101- match & self . 0 . 0 {
102- Repr :: Text ( it) => {
103- if is_raw_identifier ( & it) {
104- SmolStr :: from_iter ( [ "r#" , & it] )
105- } else {
106- it. clone ( )
107- }
108- }
109- Repr :: TupleField ( it) => SmolStr :: new ( & it. to_string ( ) ) ,
110- }
111- }
112- }
113-
11470impl Name {
11571 /// Note: this is private to make creating name from random string hard.
11672 /// Hopefully, this should allow us to integrate hygiene cleaner in the
@@ -181,10 +137,6 @@ impl Name {
181137 }
182138 }
183139
184- pub fn escaped ( & self ) -> EscapedName < ' _ > {
185- EscapedName ( self )
186- }
187-
188140 pub fn unescaped ( & self ) -> UnescapedName < ' _ > {
189141 UnescapedName ( self )
190142 }
0 commit comments