@@ -10,6 +10,7 @@ use std::{
1010 fmt, ops,
1111 path:: { Path , PathBuf } ,
1212 str:: FromStr ,
13+ sync:: Arc ,
1314} ;
1415
1516use ra_cfg:: CfgOptions ;
@@ -19,6 +20,7 @@ use rustc_hash::FxHashSet;
1920
2021use crate :: { RelativePath , RelativePathBuf } ;
2122use fmt:: Display ;
23+ use ra_tt:: TokenExpander ;
2224
2325/// `FileId` is an integer which uniquely identifies a file. File paths are
2426/// messy and system-dependent, so most of the code should work directly with
@@ -115,6 +117,22 @@ impl Display for CrateName {
115117 }
116118}
117119
120+ #[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
121+ pub struct ProcMacroId ( pub u32 ) ;
122+
123+ #[ derive( Debug , Clone ) ]
124+ pub struct ProcMacro {
125+ pub name : SmolStr ,
126+ pub expander : Arc < dyn TokenExpander > ,
127+ }
128+
129+ impl Eq for ProcMacro { }
130+ impl PartialEq for ProcMacro {
131+ fn eq ( & self , other : & ProcMacro ) -> bool {
132+ self . name == other. name && Arc :: ptr_eq ( & self . expander , & other. expander )
133+ }
134+ }
135+
118136#[ derive( Debug , Clone , PartialEq , Eq ) ]
119137pub struct CrateData {
120138 pub root_file_id : FileId ,
@@ -127,6 +145,7 @@ pub struct CrateData {
127145 pub env : Env ,
128146 pub extern_source : ExternSource ,
129147 pub dependencies : Vec < Dependency > ,
148+ pub proc_macro : Vec < ProcMacro > ,
130149}
131150
132151#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
@@ -166,14 +185,19 @@ impl CrateGraph {
166185 cfg_options : CfgOptions ,
167186 env : Env ,
168187 extern_source : ExternSource ,
188+ proc_macro : Vec < ( SmolStr , Arc < dyn ra_tt:: TokenExpander > ) > ,
169189 ) -> CrateId {
190+ let proc_macro =
191+ proc_macro. into_iter ( ) . map ( |( name, it) | ProcMacro { name, expander : it } ) . collect ( ) ;
192+
170193 let data = CrateData {
171194 root_file_id : file_id,
172195 edition,
173196 display_name,
174197 cfg_options,
175198 env,
176199 extern_source,
200+ proc_macro,
177201 dependencies : Vec :: new ( ) ,
178202 } ;
179203 let crate_id = CrateId ( self . arena . len ( ) as u32 ) ;
@@ -345,6 +369,7 @@ mod tests {
345369 CfgOptions :: default ( ) ,
346370 Env :: default ( ) ,
347371 Default :: default ( ) ,
372+ Default :: default ( ) ,
348373 ) ;
349374 let crate2 = graph. add_crate_root (
350375 FileId ( 2u32 ) ,
@@ -353,6 +378,7 @@ mod tests {
353378 CfgOptions :: default ( ) ,
354379 Env :: default ( ) ,
355380 Default :: default ( ) ,
381+ Default :: default ( ) ,
356382 ) ;
357383 let crate3 = graph. add_crate_root (
358384 FileId ( 3u32 ) ,
@@ -361,6 +387,7 @@ mod tests {
361387 CfgOptions :: default ( ) ,
362388 Env :: default ( ) ,
363389 Default :: default ( ) ,
390+ Default :: default ( ) ,
364391 ) ;
365392 assert ! ( graph. add_dep( crate1, CrateName :: new( "crate2" ) . unwrap( ) , crate2) . is_ok( ) ) ;
366393 assert ! ( graph. add_dep( crate2, CrateName :: new( "crate3" ) . unwrap( ) , crate3) . is_ok( ) ) ;
@@ -377,6 +404,7 @@ mod tests {
377404 CfgOptions :: default ( ) ,
378405 Env :: default ( ) ,
379406 Default :: default ( ) ,
407+ Default :: default ( ) ,
380408 ) ;
381409 let crate2 = graph. add_crate_root (
382410 FileId ( 2u32 ) ,
@@ -385,6 +413,7 @@ mod tests {
385413 CfgOptions :: default ( ) ,
386414 Env :: default ( ) ,
387415 Default :: default ( ) ,
416+ Default :: default ( ) ,
388417 ) ;
389418 let crate3 = graph. add_crate_root (
390419 FileId ( 3u32 ) ,
@@ -393,6 +422,7 @@ mod tests {
393422 CfgOptions :: default ( ) ,
394423 Env :: default ( ) ,
395424 Default :: default ( ) ,
425+ Default :: default ( ) ,
396426 ) ;
397427 assert ! ( graph. add_dep( crate1, CrateName :: new( "crate2" ) . unwrap( ) , crate2) . is_ok( ) ) ;
398428 assert ! ( graph. add_dep( crate2, CrateName :: new( "crate3" ) . unwrap( ) , crate3) . is_ok( ) ) ;
@@ -408,6 +438,7 @@ mod tests {
408438 CfgOptions :: default ( ) ,
409439 Env :: default ( ) ,
410440 Default :: default ( ) ,
441+ Default :: default ( ) ,
411442 ) ;
412443 let crate2 = graph. add_crate_root (
413444 FileId ( 2u32 ) ,
@@ -416,6 +447,7 @@ mod tests {
416447 CfgOptions :: default ( ) ,
417448 Env :: default ( ) ,
418449 Default :: default ( ) ,
450+ Default :: default ( ) ,
419451 ) ;
420452 assert ! ( graph
421453 . add_dep( crate1, CrateName :: normalize_dashes( "crate-name-with-dashes" ) , crate2)
0 commit comments