Unnamed repository; edit this file 'description' to name the repository.
Sort in DefMap::dump, since HashMap iteration order isn't defined
Amos Wenger 2022-07-24
parent ff31785 · commit d8c0d88
-rw-r--r--crates/hir-def/src/nameres.rs15
-rw-r--r--crates/hir-def/src/nameres/tests.rs20
-rw-r--r--crates/hir-def/src/nameres/tests/globs.rs18
-rw-r--r--crates/hir-def/src/nameres/tests/macros.rs14
4 files changed, 33 insertions, 34 deletions
diff --git a/crates/hir-def/src/nameres.rs b/crates/hir-def/src/nameres.rs
index c67046dfda..756fd583af 100644
--- a/crates/hir-def/src/nameres.rs
+++ b/crates/hir-def/src/nameres.rs
@@ -48,8 +48,8 @@
//! the result
pub mod attr_resolution;
-pub mod diagnostics;
mod collector;
+pub mod diagnostics;
mod mod_resolution;
mod path_resolution;
mod proc_macro;
@@ -57,10 +57,11 @@ mod proc_macro;
#[cfg(test)]
mod tests;
-use std::sync::Arc;
+use std::{cmp::Ord, sync::Arc};
use base_db::{CrateId, Edition, FileId};
use hir_expand::{name::Name, InFile, MacroDefId};
+use itertools::Itertools;
use la_arena::Arena;
use profile::Count;
use rustc_hash::FxHashMap;
@@ -333,11 +334,7 @@ impl DefMap {
pub(crate) fn crate_root(&self, db: &dyn DefDatabase) -> ModuleId {
self.with_ancestor_maps(db, self.root, &mut |def_map, _module| {
- if def_map.block.is_none() {
- Some(def_map.module_id(def_map.root))
- } else {
- None
- }
+ if def_map.block.is_none() { Some(def_map.module_id(def_map.root)) } else { None }
})
.expect("DefMap chain without root")
}
@@ -431,7 +428,9 @@ impl DefMap {
map.modules[module].scope.dump(buf);
- for (name, child) in map.modules[module].children.iter() {
+ for (name, child) in
+ map.modules[module].children.iter().sorted_by(|a, b| Ord::cmp(&a.0, &b.0))
+ {
let path = format!("{}::{}", path, name);
buf.push('\n');
go(buf, map, &path, *child);
diff --git a/crates/hir-def/src/nameres/tests.rs b/crates/hir-def/src/nameres/tests.rs
index 80e5476071..70dd2eb3ad 100644
--- a/crates/hir-def/src/nameres/tests.rs
+++ b/crates/hir-def/src/nameres/tests.rs
@@ -648,11 +648,11 @@ mod b {
a: t
b: t
- crate::b
- T: v
-
crate::a
T: t v
+
+ crate::b
+ T: v
"#]],
);
}
@@ -704,13 +704,13 @@ use crate::reex::*;
reex: t
tr: t
- crate::tr
- PrivTr: t
- PubTr: t
-
crate::reex
_: t
_: t
+
+ crate::tr
+ PrivTr: t
+ PubTr: t
"#]],
);
}
@@ -920,14 +920,14 @@ use some_module::unknown_func;
some_module: t
unknown_func: v
- crate::some_module
- unknown_func: v
-
crate::other_module
some_submodule: t
crate::other_module::some_submodule
unknown_func: v
+
+ crate::some_module
+ unknown_func: v
"#]],
)
}
diff --git a/crates/hir-def/src/nameres/tests/globs.rs b/crates/hir-def/src/nameres/tests/globs.rs
index 17426d54d4..b2a6a592cf 100644
--- a/crates/hir-def/src/nameres/tests/globs.rs
+++ b/crates/hir-def/src/nameres/tests/globs.rs
@@ -315,8 +315,13 @@ mod d {
c: t
d: t
- crate::d
- Y: t v
+ crate::a
+ foo: t
+
+ crate::a::foo
+ X: t v
+
+ crate::b
foo: t
crate::c
@@ -325,14 +330,9 @@ mod d {
crate::c::foo
Y: t v
- crate::b
- foo: t
-
- crate::a
+ crate::d
+ Y: t v
foo: t
-
- crate::a::foo
- X: t v
"#]],
);
}
diff --git a/crates/hir-def/src/nameres/tests/macros.rs b/crates/hir-def/src/nameres/tests/macros.rs
index 520a6ae1cb..7b7f94c533 100644
--- a/crates/hir-def/src/nameres/tests/macros.rs
+++ b/crates/hir-def/src/nameres/tests/macros.rs
@@ -439,15 +439,8 @@ macro_rules! baz {
m7: t
ok_double_macro_use_shadow: v
- crate::m7
-
crate::m1
- crate::m5
- m6: t
-
- crate::m5::m6
-
crate::m2
crate::m3
@@ -462,6 +455,13 @@ macro_rules! baz {
ok_shadow_deep: v
crate::m3::m5
+
+ crate::m5
+ m6: t
+
+ crate::m5::m6
+
+ crate::m7
"#]],
);
// FIXME: should not see `NotFoundBefore`