Skip to content
This repository was archived by the owner on Mar 1, 2019. It is now read-only.

Commit 653d704

Browse files
committed
Don't duplicate children
Fixes #105
1 parent 2e100d5 commit 653d704

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/analysis.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
use std::collections::HashMap;
9+
use std::collections::{HashMap, HashSet};
1010
use std::path::{Path, PathBuf};
1111
use std::time::SystemTime;
1212

@@ -30,7 +30,7 @@ pub struct PerCrateAnalysis {
3030
pub def_id_for_span: HashMap<Span, Id>,
3131
pub defs: HashMap<Id, Def>,
3232
pub defs_per_file: HashMap<PathBuf, Vec<Id>>,
33-
pub children: HashMap<Id, Vec<Id>>,
33+
pub children: HashMap<Id, HashSet<Id>>,
3434
pub def_names: HashMap<String, Vec<Id>>,
3535
pub ref_spans: HashMap<Id, Vec<Span>>,
3636
pub globs: HashMap<Span, Glob>,

src/lowering.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use util;
1717

1818
use span;
1919

20-
use std::collections::HashMap;
20+
use std::collections::{HashSet, HashMap};
2121
use std::iter::Extend;
2222
use std::path::{Path, PathBuf};
2323
use std::time::Instant;
@@ -205,14 +205,14 @@ impl CrateReader {
205205
.push(id);
206206
let parent = d.parent.map(|id| self.id_from_compiler_id(&id));
207207
if let Some(parent) = parent {
208-
analysis
208+
let children = analysis
209209
.children
210210
.entry(parent)
211-
.or_insert_with(|| vec![])
212-
.push(id);
211+
.or_insert_with(HashSet::new);
212+
children.insert(id);
213213
}
214214
if !d.children.is_empty() {
215-
let children_for_id = analysis.children.entry(id).or_insert_with(Vec::new);
215+
let children_for_id = analysis.children.entry(id).or_insert_with(HashSet::new);
216216
children_for_id
217217
.extend(d.children.iter().map(|id| self.id_from_compiler_id(id)));
218218
}

src/test/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,23 @@ fn test_types() {
290290
assert_type(&host, "TEST_STATIC", DefKind::Static, &[13]);
291291
assert_type(&host, "test_module", DefKind::Mod, &[17]);
292292
assert_type(&host, "TestType", DefKind::Type, &[18]);
293+
//assert_type(&host, "TestUnion", DefKind::Union, &[21]);
293294
assert_type(&host, "TestTrait", DefKind::Trait, &[25]);
294295
assert_type(&host, "test_method", DefKind::Method, &[26]);
295296
assert_type(&host, "FooEnum", DefKind::Enum, &[29]);
296297
assert_type(&host, "TupleVariant", DefKind::TupleVariant, &[30]);
297298
assert_type(&host, "StructVariant", DefKind::StructVariant, &[31]);
298299
}
300+
301+
#[test]
302+
fn test_child_count() {
303+
let host = AnalysisHost::new_with_loader(TestAnalysisLoader::new(
304+
Path::new("test_data/types/save-analysis").to_owned(),
305+
));
306+
host.reload(Path::new("test_data/types"), Path::new("test_data/types"))
307+
.unwrap();
308+
309+
let ids = host.search_for_id("Foo").unwrap();
310+
let id = ids[0];
311+
assert_eq!(host.for_each_child_def(id, |id, _| id).unwrap().len(), 1);
312+
}

0 commit comments

Comments
 (0)