@@ -56,15 +56,22 @@ pub struct CyclicDependencies;
56
56
#[ derive( Debug , Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
57
57
pub struct CrateId ( pub u32 ) ;
58
58
59
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
60
+ pub enum Edition {
61
+ Edition2018 ,
62
+ Edition2015 ,
63
+ }
64
+
59
65
#[ derive( Debug , Clone , PartialEq , Eq ) ]
60
66
struct CrateData {
61
67
file_id : FileId ,
68
+ edition : Edition ,
62
69
dependencies : Vec < Dependency > ,
63
70
}
64
71
65
72
impl 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 ( ) }
68
75
}
69
76
70
77
fn add_dep ( & mut self , name : SmolStr , crate_id : CrateId ) {
@@ -85,9 +92,9 @@ impl Dependency {
85
92
}
86
93
87
94
impl 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 {
89
96
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 ) ) ;
91
98
assert ! ( prev. is_none( ) ) ;
92
99
crate_id
93
100
}
@@ -159,14 +166,14 @@ impl CrateGraph {
159
166
160
167
#[ cfg( test) ]
161
168
mod tests {
162
- use super :: { CrateGraph , FileId , SmolStr } ;
169
+ use super :: { CrateGraph , FileId , SmolStr , Edition :: Edition2018 } ;
163
170
164
171
#[ test]
165
- fn it_should_painc_because_of_cycle_dependencies ( ) {
172
+ fn it_should_panic_because_of_cycle_dependencies ( ) {
166
173
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 ) ;
170
177
assert ! ( graph. add_dep( crate1, SmolStr :: new( "crate2" ) , crate2) . is_ok( ) ) ;
171
178
assert ! ( graph. add_dep( crate2, SmolStr :: new( "crate3" ) , crate3) . is_ok( ) ) ;
172
179
assert ! ( graph. add_dep( crate3, SmolStr :: new( "crate1" ) , crate1) . is_err( ) ) ;
@@ -175,9 +182,9 @@ mod tests {
175
182
#[ test]
176
183
fn it_works ( ) {
177
184
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 ) ;
181
188
assert ! ( graph. add_dep( crate1, SmolStr :: new( "crate2" ) , crate2) . is_ok( ) ) ;
182
189
assert ! ( graph. add_dep( crate2, SmolStr :: new( "crate3" ) , crate3) . is_ok( ) ) ;
183
190
}
0 commit comments