9
9
use std:: { fmt, mem, ops} ;
10
10
11
11
use cfg:: CfgOptions ;
12
+ use intern:: Symbol ;
12
13
use la_arena:: { Arena , Idx , RawIdx } ;
13
14
use rustc_hash:: { FxHashMap , FxHashSet } ;
14
15
use span:: Edition ;
15
- use syntax:: SmolStr ;
16
16
use triomphe:: Arc ;
17
17
use vfs:: { file_set:: FileSet , AbsPathBuf , AnchoredPath , FileId , VfsPath } ;
18
18
@@ -99,8 +99,8 @@ impl fmt::Debug for CrateGraph {
99
99
100
100
pub type CrateId = Idx < CrateData > ;
101
101
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 ) ;
104
104
105
105
impl CrateName {
106
106
/// Creates a crate name, checking for dashes in the string provided.
@@ -110,16 +110,16 @@ impl CrateName {
110
110
if name. contains ( '-' ) {
111
111
Err ( name)
112
112
} else {
113
- Ok ( Self ( SmolStr :: new ( name) ) )
113
+ Ok ( Self ( Symbol :: intern ( name) ) )
114
114
}
115
115
}
116
116
117
117
/// Creates a crate name, unconditionally replacing the dashes with underscores.
118
118
pub fn normalize_dashes ( name : & str ) -> CrateName {
119
- Self ( SmolStr :: new ( name. replace ( '-' , "_" ) ) )
119
+ Self ( Symbol :: intern ( & name. replace ( '-' , "_" ) ) )
120
120
}
121
121
122
- pub fn as_smol_str ( & self ) -> & SmolStr {
122
+ pub fn symbol ( & self ) -> & Symbol {
123
123
& self . 0
124
124
}
125
125
}
@@ -133,19 +133,19 @@ impl fmt::Display for CrateName {
133
133
impl ops:: Deref for CrateName {
134
134
type Target = str ;
135
135
fn deref ( & self ) -> & str {
136
- & self . 0
136
+ self . 0 . as_str ( )
137
137
}
138
138
}
139
139
140
140
/// Origin of the crates.
141
141
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
142
142
pub enum CrateOrigin {
143
143
/// Crates that are from the rustc workspace.
144
- Rustc { name : String } ,
144
+ Rustc { name : Symbol } ,
145
145
/// Crates that are workspace members.
146
- Local { repo : Option < String > , name : Option < String > } ,
146
+ Local { repo : Option < String > , name : Option < Symbol > } ,
147
147
/// Crates that are non member libraries.
148
- Library { repo : Option < String > , name : String } ,
148
+ Library { repo : Option < String > , name : Symbol } ,
149
149
/// Crates that are provided by the language, like std, core, proc-macro, ...
150
150
Lang ( LangCrateOrigin ) ,
151
151
}
@@ -201,16 +201,16 @@ impl fmt::Display for LangCrateOrigin {
201
201
}
202
202
}
203
203
204
- #[ derive( Debug , Clone , PartialEq , Eq , Hash , PartialOrd , Ord ) ]
204
+ #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
205
205
pub struct CrateDisplayName {
206
206
// The name we use to display various paths (with `_`).
207
207
crate_name : CrateName ,
208
208
// The name as specified in Cargo.toml (with `-`).
209
- canonical_name : String ,
209
+ canonical_name : Symbol ,
210
210
}
211
211
212
212
impl CrateDisplayName {
213
- pub fn canonical_name ( & self ) -> & str {
213
+ pub fn canonical_name ( & self ) -> & Symbol {
214
214
& self . canonical_name
215
215
}
216
216
pub fn crate_name ( & self ) -> & CrateName {
@@ -220,7 +220,7 @@ impl CrateDisplayName {
220
220
221
221
impl From < CrateName > for CrateDisplayName {
222
222
fn from ( crate_name : CrateName ) -> CrateDisplayName {
223
- let canonical_name = crate_name. to_string ( ) ;
223
+ let canonical_name = crate_name. 0 . clone ( ) ;
224
224
CrateDisplayName { crate_name, canonical_name }
225
225
}
226
226
}
@@ -239,9 +239,9 @@ impl ops::Deref for CrateDisplayName {
239
239
}
240
240
241
241
impl 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 ) }
245
245
}
246
246
}
247
247
0 commit comments