66//! actual IO. See `vfs` and `project_model` in the `rust-analyzer` crate for how
77//! actual IO is done and lowered to input.
88
9- use std:: { fmt, str:: FromStr } ;
9+ use std:: { fmt, ops , str:: FromStr } ;
1010
1111use ra_cfg:: CfgOptions ;
1212use ra_syntax:: SmolStr ;
@@ -174,10 +174,6 @@ impl CrateGraph {
174174 self . arena . keys ( ) . copied ( )
175175 }
176176
177- pub fn crate_data ( & self , crate_id : & CrateId ) -> & CrateData {
178- & self . arena [ crate_id]
179- }
180-
181177 // FIXME: this only finds one crate with the given root; we could have multiple
182178 pub fn crate_id_for_crate_root ( & self , file_id : FileId ) -> Option < CrateId > {
183179 let ( & crate_id, _) =
@@ -207,7 +203,7 @@ impl CrateGraph {
207203 return false ;
208204 }
209205
210- for dep in & self . crate_data ( & from) . dependencies {
206+ for dep in & self [ from] . dependencies {
211207 let crate_id = dep. crate_id ( ) ;
212208 if crate_id == target {
213209 return true ;
@@ -221,6 +217,13 @@ impl CrateGraph {
221217 }
222218}
223219
220+ impl ops:: Index < CrateId > for CrateGraph {
221+ type Output = CrateData ;
222+ fn index ( & self , crate_id : CrateId ) -> & CrateData {
223+ & self . arena [ & crate_id]
224+ }
225+ }
226+
224227impl CrateId {
225228 pub fn shift ( self , amount : u32 ) -> CrateId {
226229 CrateId ( self . 0 + amount)
@@ -376,7 +379,7 @@ mod tests {
376379 . add_dep( crate1, CrateName :: normalize_dashes( "crate-name-with-dashes" ) , crate2)
377380 . is_ok( ) ) ;
378381 assert_eq ! (
379- graph. crate_data ( & crate1) . dependencies,
382+ graph[ crate1] . dependencies,
380383 vec![ Dependency { crate_id: crate2, name: "crate_name_with_dashes" . into( ) } ]
381384 ) ;
382385 }
0 commit comments