aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_db/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-09-09 15:35:21 +0100
committerGitHub <[email protected]>2019-09-09 15:35:21 +0100
commit7258523a519207a033dedde8c498debe8da4a15e (patch)
tree4d2c08f9b357040ba135fa66aa5a981058f6f55c /crates/ra_db/src
parent76f39b4b20d32b67fb60220e9d2a6ceb3f44fbb7 (diff)
parente5a8093dd497518c177d3c22404d80da44905336 (diff)
Merge #1789
1789: Debug r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_db/src')
-rw-r--r--crates/ra_db/src/input.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs
index d1ee3c036..a1ace61b6 100644
--- a/crates/ra_db/src/input.rs
+++ b/crates/ra_db/src/input.rs
@@ -82,6 +82,12 @@ pub struct CyclicDependencies;
82#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] 82#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
83pub struct CrateId(pub u32); 83pub struct CrateId(pub u32);
84 84
85impl CrateId {
86 pub fn shift(self, amount: u32) -> CrateId {
87 CrateId(self.0 + amount)
88 }
89}
90
85#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 91#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
86pub enum Edition { 92pub enum Edition {
87 Edition2018, 93 Edition2018,
@@ -178,15 +184,19 @@ impl CrateGraph {
178 184
179 /// Extends this crate graph by adding a complete disjoint second crate 185 /// Extends this crate graph by adding a complete disjoint second crate
180 /// graph. 186 /// graph.
181 pub fn extend(&mut self, other: CrateGraph) { 187 ///
188 /// The ids of the crates in the `other` graph are shifted by the return
189 /// amount.
190 pub fn extend(&mut self, other: CrateGraph) -> u32 {
182 let start = self.arena.len() as u32; 191 let start = self.arena.len() as u32;
183 self.arena.extend(other.arena.into_iter().map(|(id, mut data)| { 192 self.arena.extend(other.arena.into_iter().map(|(id, mut data)| {
184 let new_id = CrateId(id.0 + start); 193 let new_id = id.shift(start);
185 for dep in &mut data.dependencies { 194 for dep in &mut data.dependencies {
186 dep.crate_id = CrateId(dep.crate_id.0 + start); 195 dep.crate_id = dep.crate_id.shift(start);
187 } 196 }
188 (new_id, data) 197 (new_id, data)
189 })); 198 }));
199 start
190 } 200 }
191 201
192 fn dfs_find(&self, target: CrateId, from: CrateId, visited: &mut FxHashSet<CrateId>) -> bool { 202 fn dfs_find(&self, target: CrateId, from: CrateId, visited: &mut FxHashSet<CrateId>) -> bool {