99use std:: { fmt, mem, ops} ;
1010
1111use cfg:: CfgOptions ;
12+ use intern:: Symbol ;
1213use la_arena:: { Arena , Idx , RawIdx } ;
1314use rustc_hash:: { FxHashMap , FxHashSet } ;
1415use span:: Edition ;
15- use syntax:: SmolStr ;
1616use triomphe:: Arc ;
1717use vfs:: { file_set:: FileSet , AbsPathBuf , AnchoredPath , FileId , VfsPath } ;
1818
@@ -99,8 +99,8 @@ impl fmt::Debug for CrateGraph {
9999
100100pub type CrateId = Idx < CrateData > ;
101101
102- #[ derive( Debug , Clone , PartialEq , Eq , Hash , PartialOrd , Ord ) ]
103- pub struct CrateName ( SmolStr ) ;
102+ #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
103+ pub struct CrateName ( Symbol ) ;
104104
105105impl CrateName {
106106 /// Creates a crate name, checking for dashes in the string provided.
@@ -110,16 +110,16 @@ impl CrateName {
110110 if name. contains ( '-' ) {
111111 Err ( name)
112112 } else {
113- Ok ( Self ( SmolStr :: new ( name) ) )
113+ Ok ( Self ( Symbol :: intern ( name) ) )
114114 }
115115 }
116116
117117 /// Creates a crate name, unconditionally replacing the dashes with underscores.
118118 pub fn normalize_dashes ( name : & str ) -> CrateName {
119- Self ( SmolStr :: new ( name. replace ( '-' , "_" ) ) )
119+ Self ( Symbol :: intern ( & name. replace ( '-' , "_" ) ) )
120120 }
121121
122- pub fn as_smol_str ( & self ) -> & SmolStr {
122+ pub fn symbol ( & self ) -> & Symbol {
123123 & self . 0
124124 }
125125}
@@ -133,19 +133,19 @@ impl fmt::Display for CrateName {
133133impl ops:: Deref for CrateName {
134134 type Target = str ;
135135 fn deref ( & self ) -> & str {
136- & self . 0
136+ self . 0 . as_str ( )
137137 }
138138}
139139
140140/// Origin of the crates.
141141#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
142142pub enum CrateOrigin {
143143 /// Crates that are from the rustc workspace.
144- Rustc { name : String } ,
144+ Rustc { name : Symbol } ,
145145 /// Crates that are workspace members.
146- Local { repo : Option < String > , name : Option < String > } ,
146+ Local { repo : Option < String > , name : Option < Symbol > } ,
147147 /// Crates that are non member libraries.
148- Library { repo : Option < String > , name : String } ,
148+ Library { repo : Option < String > , name : Symbol } ,
149149 /// Crates that are provided by the language, like std, core, proc-macro, ...
150150 Lang ( LangCrateOrigin ) ,
151151}
@@ -201,16 +201,16 @@ impl fmt::Display for LangCrateOrigin {
201201 }
202202}
203203
204- #[ derive( Debug , Clone , PartialEq , Eq , Hash , PartialOrd , Ord ) ]
204+ #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
205205pub struct CrateDisplayName {
206206 // The name we use to display various paths (with `_`).
207207 crate_name : CrateName ,
208208 // The name as specified in Cargo.toml (with `-`).
209- canonical_name : String ,
209+ canonical_name : Symbol ,
210210}
211211
212212impl CrateDisplayName {
213- pub fn canonical_name ( & self ) -> & str {
213+ pub fn canonical_name ( & self ) -> & Symbol {
214214 & self . canonical_name
215215 }
216216 pub fn crate_name ( & self ) -> & CrateName {
@@ -220,7 +220,7 @@ impl CrateDisplayName {
220220
221221impl From < CrateName > for CrateDisplayName {
222222 fn from ( crate_name : CrateName ) -> CrateDisplayName {
223- let canonical_name = crate_name. to_string ( ) ;
223+ let canonical_name = crate_name. 0 . clone ( ) ;
224224 CrateDisplayName { crate_name, canonical_name }
225225 }
226226}
@@ -239,9 +239,9 @@ impl ops::Deref for CrateDisplayName {
239239}
240240
241241impl CrateDisplayName {
242- pub fn from_canonical_name ( canonical_name : String ) -> CrateDisplayName {
243- let crate_name = CrateName :: normalize_dashes ( & canonical_name) ;
244- CrateDisplayName { crate_name, canonical_name }
242+ pub fn from_canonical_name ( canonical_name : & str ) -> CrateDisplayName {
243+ let crate_name = CrateName :: normalize_dashes ( canonical_name) ;
244+ CrateDisplayName { crate_name, canonical_name : Symbol :: intern ( canonical_name ) }
245245 }
246246}
247247
0 commit comments