@@ -56,15 +56,22 @@ pub struct CyclicDependencies;
5656#[ derive( Debug , Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
5757pub struct CrateId ( pub u32 ) ;
5858
59+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
60+ pub enum Edition {
61+ Edition2018 ,
62+ Edition2015 ,
63+ }
64+
5965#[ derive( Debug , Clone , PartialEq , Eq ) ]
6066struct CrateData {
6167 file_id : FileId ,
68+ edition : Edition ,
6269 dependencies : Vec < Dependency > ,
6370}
6471
6572impl CrateData {
66- fn new ( file_id : FileId ) -> CrateData {
67- CrateData { file_id, dependencies : Vec :: new ( ) }
73+ fn new ( file_id : FileId , edition : Edition ) -> CrateData {
74+ CrateData { file_id, edition , dependencies : Vec :: new ( ) }
6875 }
6976
7077 fn add_dep ( & mut self , name : SmolStr , crate_id : CrateId ) {
@@ -85,9 +92,9 @@ impl Dependency {
8592}
8693
8794impl CrateGraph {
88- pub fn add_crate_root ( & mut self , file_id : FileId ) -> CrateId {
95+ pub fn add_crate_root ( & mut self , file_id : FileId , edition : Edition ) -> CrateId {
8996 let crate_id = CrateId ( self . arena . len ( ) as u32 ) ;
90- let prev = self . arena . insert ( crate_id, CrateData :: new ( file_id) ) ;
97+ let prev = self . arena . insert ( crate_id, CrateData :: new ( file_id, edition ) ) ;
9198 assert ! ( prev. is_none( ) ) ;
9299 crate_id
93100 }
@@ -159,14 +166,14 @@ impl CrateGraph {
159166
160167#[ cfg( test) ]
161168mod tests {
162- use super :: { CrateGraph , FileId , SmolStr } ;
169+ use super :: { CrateGraph , FileId , SmolStr , Edition :: Edition2018 } ;
163170
164171 #[ test]
165- fn it_should_painc_because_of_cycle_dependencies ( ) {
172+ fn it_should_panic_because_of_cycle_dependencies ( ) {
166173 let mut graph = CrateGraph :: default ( ) ;
167- let crate1 = graph. add_crate_root ( FileId ( 1u32 ) ) ;
168- let crate2 = graph. add_crate_root ( FileId ( 2u32 ) ) ;
169- let crate3 = graph. add_crate_root ( FileId ( 3u32 ) ) ;
174+ let crate1 = graph. add_crate_root ( FileId ( 1u32 ) , Edition2018 ) ;
175+ let crate2 = graph. add_crate_root ( FileId ( 2u32 ) , Edition2018 ) ;
176+ let crate3 = graph. add_crate_root ( FileId ( 3u32 ) , Edition2018 ) ;
170177 assert ! ( graph. add_dep( crate1, SmolStr :: new( "crate2" ) , crate2) . is_ok( ) ) ;
171178 assert ! ( graph. add_dep( crate2, SmolStr :: new( "crate3" ) , crate3) . is_ok( ) ) ;
172179 assert ! ( graph. add_dep( crate3, SmolStr :: new( "crate1" ) , crate1) . is_err( ) ) ;
@@ -175,9 +182,9 @@ mod tests {
175182 #[ test]
176183 fn it_works ( ) {
177184 let mut graph = CrateGraph :: default ( ) ;
178- let crate1 = graph. add_crate_root ( FileId ( 1u32 ) ) ;
179- let crate2 = graph. add_crate_root ( FileId ( 2u32 ) ) ;
180- let crate3 = graph. add_crate_root ( FileId ( 3u32 ) ) ;
185+ let crate1 = graph. add_crate_root ( FileId ( 1u32 ) , Edition2018 ) ;
186+ let crate2 = graph. add_crate_root ( FileId ( 2u32 ) , Edition2018 ) ;
187+ let crate3 = graph. add_crate_root ( FileId ( 3u32 ) , Edition2018 ) ;
181188 assert ! ( graph. add_dep( crate1, SmolStr :: new( "crate2" ) , crate2) . is_ok( ) ) ;
182189 assert ! ( graph. add_dep( crate2, SmolStr :: new( "crate3" ) , crate3) . is_ok( ) ) ;
183190 }
0 commit comments