aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_db
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-02-08 11:49:43 +0000
committerAleksey Kladov <[email protected]>2019-02-08 11:49:43 +0000
commit12e3b4c70b5ef23b2fdfc197296d483680e125f9 (patch)
tree71baa0e0a62f9f6b61450501c5f821f67badf9e4 /crates/ra_db
parent5cb1d41a30d25cbe136402644bf5434dd667f1e5 (diff)
reformat the world
Diffstat (limited to 'crates/ra_db')
-rw-r--r--crates/ra_db/src/input.rs30
-rw-r--r--crates/ra_db/src/lib.rs7
-rw-r--r--crates/ra_db/src/loc2id.rs9
3 files changed, 11 insertions, 35 deletions
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs
index 275894252..614325a0f 100644
--- a/crates/ra_db/src/input.rs
+++ b/crates/ra_db/src/input.rs
@@ -64,10 +64,7 @@ struct CrateData {
64 64
65impl CrateData { 65impl CrateData {
66 fn new(file_id: FileId) -> CrateData { 66 fn new(file_id: FileId) -> CrateData {
67 CrateData { 67 CrateData { file_id, dependencies: Vec::new() }
68 file_id,
69 dependencies: Vec::new(),
70 }
71 } 68 }
72 69
73 fn add_dep(&mut self, name: SmolStr, crate_id: CrateId) { 70 fn add_dep(&mut self, name: SmolStr, crate_id: CrateId) {
@@ -112,10 +109,7 @@ impl CrateGraph {
112 self.arena[&crate_id].file_id 109 self.arena[&crate_id].file_id
113 } 110 }
114 pub fn crate_id_for_crate_root(&self, file_id: FileId) -> Option<CrateId> { 111 pub fn crate_id_for_crate_root(&self, file_id: FileId) -> Option<CrateId> {
115 let (&crate_id, _) = self 112 let (&crate_id, _) = self.arena.iter().find(|(_crate_id, data)| data.file_id == file_id)?;
116 .arena
117 .iter()
118 .find(|(_crate_id, data)| data.file_id == file_id)?;
119 Some(crate_id) 113 Some(crate_id)
120 } 114 }
121 pub fn dependencies<'a>( 115 pub fn dependencies<'a>(
@@ -153,15 +147,9 @@ mod tests {
153 let crate1 = graph.add_crate_root(FileId(1u32)); 147 let crate1 = graph.add_crate_root(FileId(1u32));
154 let crate2 = graph.add_crate_root(FileId(2u32)); 148 let crate2 = graph.add_crate_root(FileId(2u32));
155 let crate3 = graph.add_crate_root(FileId(3u32)); 149 let crate3 = graph.add_crate_root(FileId(3u32));
156 assert!(graph 150 assert!(graph.add_dep(crate1, SmolStr::new("crate2"), crate2).is_ok());
157 .add_dep(crate1, SmolStr::new("crate2"), crate2) 151 assert!(graph.add_dep(crate2, SmolStr::new("crate3"), crate3).is_ok());
158 .is_ok()); 152 assert!(graph.add_dep(crate3, SmolStr::new("crate1"), crate1).is_err());
159 assert!(graph
160 .add_dep(crate2, SmolStr::new("crate3"), crate3)
161 .is_ok());
162 assert!(graph
163 .add_dep(crate3, SmolStr::new("crate1"), crate1)
164 .is_err());
165 } 153 }
166 154
167 #[test] 155 #[test]
@@ -170,11 +158,7 @@ mod tests {
170 let crate1 = graph.add_crate_root(FileId(1u32)); 158 let crate1 = graph.add_crate_root(FileId(1u32));
171 let crate2 = graph.add_crate_root(FileId(2u32)); 159 let crate2 = graph.add_crate_root(FileId(2u32));
172 let crate3 = graph.add_crate_root(FileId(3u32)); 160 let crate3 = graph.add_crate_root(FileId(3u32));
173 assert!(graph 161 assert!(graph.add_dep(crate1, SmolStr::new("crate2"), crate2).is_ok());
174 .add_dep(crate1, SmolStr::new("crate2"), crate2) 162 assert!(graph.add_dep(crate2, SmolStr::new("crate3"), crate3).is_ok());
175 .is_ok());
176 assert!(graph
177 .add_dep(crate2, SmolStr::new("crate3"), crate3)
178 .is_ok());
179 } 163 }
180} 164}
diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs
index 66634e05b..31442713d 100644
--- a/crates/ra_db/src/lib.rs
+++ b/crates/ra_db/src/lib.rs
@@ -94,11 +94,8 @@ pub trait SourceDatabase: CheckCanceled + std::fmt::Debug {
94fn source_root_crates(db: &impl SourceDatabase, id: SourceRootId) -> Arc<Vec<CrateId>> { 94fn source_root_crates(db: &impl SourceDatabase, id: SourceRootId) -> Arc<Vec<CrateId>> {
95 let root = db.source_root(id); 95 let root = db.source_root(id);
96 let graph = db.crate_graph(); 96 let graph = db.crate_graph();
97 let res = root 97 let res =
98 .files 98 root.files.values().filter_map(|&it| graph.crate_id_for_crate_root(it)).collect::<Vec<_>>();
99 .values()
100 .filter_map(|&it| graph.crate_id_for_crate_root(it))
101 .collect::<Vec<_>>();
102 Arc::new(res) 99 Arc::new(res)
103} 100}
104 101
diff --git a/crates/ra_db/src/loc2id.rs b/crates/ra_db/src/loc2id.rs
index 359cd893d..d27fa7682 100644
--- a/crates/ra_db/src/loc2id.rs
+++ b/crates/ra_db/src/loc2id.rs
@@ -30,10 +30,7 @@ where
30 LOC: Clone + Eq + Hash, 30 LOC: Clone + Eq + Hash,
31{ 31{
32 fn default() -> Self { 32 fn default() -> Self {
33 Loc2IdMap { 33 Loc2IdMap { id2loc: Arena::default(), loc2id: FxHashMap::default() }
34 id2loc: Arena::default(),
35 loc2id: FxHashMap::default(),
36 }
37 } 34 }
38} 35}
39 36
@@ -85,9 +82,7 @@ where
85 LOC: Clone + Eq + Hash, 82 LOC: Clone + Eq + Hash,
86{ 83{
87 fn default() -> Self { 84 fn default() -> Self {
88 LocationIntener { 85 LocationIntener { map: Default::default() }
89 map: Default::default(),
90 }
91 } 86 }
92} 87}
93 88