@@ -67,7 +67,7 @@ pub struct CrateGraph {
6767#[ derive( Debug , Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
6868pub struct CrateId ( pub u32 ) ;
6969
70- #[ derive( Debug , Clone , PartialEq , Eq ) ]
70+ #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
7171pub struct CrateName ( SmolStr ) ;
7272
7373impl CrateName {
@@ -94,6 +94,13 @@ impl fmt::Display for CrateName {
9494 }
9595}
9696
97+ impl ops:: Deref for CrateName {
98+ type Target = str ;
99+ fn deref ( & self ) -> & Self :: Target {
100+ & * self . 0
101+ }
102+ }
103+
97104#[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
98105pub struct ProcMacroId ( pub u32 ) ;
99106
@@ -117,7 +124,7 @@ pub struct CrateData {
117124 /// The name to display to the end user.
118125 /// This actual crate name can be different in a particular dependent crate
119126 /// or may even be missing for some cases, such as a dummy crate for the code snippet.
120- pub display_name : Option < CrateName > ,
127+ pub display_name : Option < String > ,
121128 pub cfg_options : CfgOptions ,
122129 pub env : Env ,
123130 pub dependencies : Vec < Dependency > ,
@@ -138,15 +145,15 @@ pub struct Env {
138145#[ derive( Debug , Clone , PartialEq , Eq ) ]
139146pub struct Dependency {
140147 pub crate_id : CrateId ,
141- pub name : SmolStr ,
148+ pub name : CrateName ,
142149}
143150
144151impl CrateGraph {
145152 pub fn add_crate_root (
146153 & mut self ,
147154 file_id : FileId ,
148155 edition : Edition ,
149- display_name : Option < CrateName > ,
156+ display_name : Option < String > ,
150157 cfg_options : CfgOptions ,
151158 env : Env ,
152159 proc_macro : Vec < ( SmolStr , Arc < dyn ra_tt:: TokenExpander > ) > ,
@@ -178,7 +185,7 @@ impl CrateGraph {
178185 if self . dfs_find ( from, to, & mut FxHashSet :: default ( ) ) {
179186 return Err ( CyclicDependenciesError ) ;
180187 }
181- self . arena . get_mut ( & from) . unwrap ( ) . add_dep ( name. 0 , to) ;
188+ self . arena . get_mut ( & from) . unwrap ( ) . add_dep ( name, to) ;
182189 Ok ( ( ) )
183190 }
184191
@@ -247,7 +254,7 @@ impl CrateId {
247254}
248255
249256impl CrateData {
250- fn add_dep ( & mut self , name : SmolStr , crate_id : CrateId ) {
257+ fn add_dep ( & mut self , name : CrateName , crate_id : CrateId ) {
251258 self . dependencies . push ( Dependency { name, crate_id } )
252259 }
253260}
@@ -429,7 +436,10 @@ mod tests {
429436 . is_ok( ) ) ;
430437 assert_eq ! (
431438 graph[ crate1] . dependencies,
432- vec![ Dependency { crate_id: crate2, name: "crate_name_with_dashes" . into( ) } ]
439+ vec![ Dependency {
440+ crate_id: crate2,
441+ name: CrateName :: new( "crate_name_with_dashes" ) . unwrap( )
442+ } ]
433443 ) ;
434444 }
435445}
0 commit comments