Skip to content

Commit 4e1a302

Browse files
Sort in DefMap::dump, since HashMap iteration order isn't defined
1 parent e436260 commit 4e1a302

File tree

4 files changed

+33
-34
lines changed

4 files changed

+33
-34
lines changed

Diff for: src/tools/rust-analyzer/crates/hir-def/src/nameres.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,20 @@
4848
//! the result
4949
5050
pub mod attr_resolution;
51-
pub mod diagnostics;
5251
mod collector;
52+
pub mod diagnostics;
5353
mod mod_resolution;
5454
mod path_resolution;
5555
mod proc_macro;
5656

5757
#[cfg(test)]
5858
mod tests;
5959

60-
use std::sync::Arc;
60+
use std::{cmp::Ord, sync::Arc};
6161

6262
use base_db::{CrateId, Edition, FileId};
6363
use hir_expand::{name::Name, InFile, MacroDefId};
64+
use itertools::Itertools;
6465
use la_arena::Arena;
6566
use profile::Count;
6667
use rustc_hash::FxHashMap;
@@ -333,11 +334,7 @@ impl DefMap {
333334

334335
pub(crate) fn crate_root(&self, db: &dyn DefDatabase) -> ModuleId {
335336
self.with_ancestor_maps(db, self.root, &mut |def_map, _module| {
336-
if def_map.block.is_none() {
337-
Some(def_map.module_id(def_map.root))
338-
} else {
339-
None
340-
}
337+
if def_map.block.is_none() { Some(def_map.module_id(def_map.root)) } else { None }
341338
})
342339
.expect("DefMap chain without root")
343340
}
@@ -431,7 +428,9 @@ impl DefMap {
431428

432429
map.modules[module].scope.dump(buf);
433430

434-
for (name, child) in map.modules[module].children.iter() {
431+
for (name, child) in
432+
map.modules[module].children.iter().sorted_by(|a, b| Ord::cmp(&a.0, &b.0))
433+
{
435434
let path = format!("{}::{}", path, name);
436435
buf.push('\n');
437436
go(buf, map, &path, *child);

Diff for: src/tools/rust-analyzer/crates/hir-def/src/nameres/tests.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -648,11 +648,11 @@ mod b {
648648
a: t
649649
b: t
650650
651-
crate::b
652-
T: v
653-
654651
crate::a
655652
T: t v
653+
654+
crate::b
655+
T: v
656656
"#]],
657657
);
658658
}
@@ -704,13 +704,13 @@ use crate::reex::*;
704704
reex: t
705705
tr: t
706706
707-
crate::tr
708-
PrivTr: t
709-
PubTr: t
710-
711707
crate::reex
712708
_: t
713709
_: t
710+
711+
crate::tr
712+
PrivTr: t
713+
PubTr: t
714714
"#]],
715715
);
716716
}
@@ -920,14 +920,14 @@ use some_module::unknown_func;
920920
some_module: t
921921
unknown_func: v
922922
923-
crate::some_module
924-
unknown_func: v
925-
926923
crate::other_module
927924
some_submodule: t
928925
929926
crate::other_module::some_submodule
930927
unknown_func: v
928+
929+
crate::some_module
930+
unknown_func: v
931931
"#]],
932932
)
933933
}

Diff for: src/tools/rust-analyzer/crates/hir-def/src/nameres/tests/globs.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,13 @@ mod d {
315315
c: t
316316
d: t
317317
318-
crate::d
319-
Y: t v
318+
crate::a
319+
foo: t
320+
321+
crate::a::foo
322+
X: t v
323+
324+
crate::b
320325
foo: t
321326
322327
crate::c
@@ -325,14 +330,9 @@ mod d {
325330
crate::c::foo
326331
Y: t v
327332
328-
crate::b
329-
foo: t
330-
331-
crate::a
333+
crate::d
334+
Y: t v
332335
foo: t
333-
334-
crate::a::foo
335-
X: t v
336336
"#]],
337337
);
338338
}

Diff for: src/tools/rust-analyzer/crates/hir-def/src/nameres/tests/macros.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -439,15 +439,8 @@ macro_rules! baz {
439439
m7: t
440440
ok_double_macro_use_shadow: v
441441
442-
crate::m7
443-
444442
crate::m1
445443
446-
crate::m5
447-
m6: t
448-
449-
crate::m5::m6
450-
451444
crate::m2
452445
453446
crate::m3
@@ -462,6 +455,13 @@ macro_rules! baz {
462455
ok_shadow_deep: v
463456
464457
crate::m3::m5
458+
459+
crate::m5
460+
m6: t
461+
462+
crate::m5::m6
463+
464+
crate::m7
465465
"#]],
466466
);
467467
// FIXME: should not see `NotFoundBefore`

0 commit comments

Comments
 (0)