From 4e1a302efc0a0bcacba92d3d1a59052db1901e6c Mon Sep 17 00:00:00 2001 From: Amos Wenger Date: Sun, 24 Jul 2022 16:04:20 +0200 Subject: [PATCH] Sort in DefMap::dump, since HashMap iteration order isn't defined --- .../crates/hir-def/src/nameres.rs | 15 +++++++------- .../crates/hir-def/src/nameres/tests.rs | 20 +++++++++---------- .../crates/hir-def/src/nameres/tests/globs.rs | 18 ++++++++--------- .../hir-def/src/nameres/tests/macros.rs | 14 ++++++------- 4 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/tools/rust-analyzer/crates/hir-def/src/nameres.rs b/src/tools/rust-analyzer/crates/hir-def/src/nameres.rs index c67046dfdab..756fd583af4 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/nameres.rs +++ b/src/tools/rust-analyzer/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/src/tools/rust-analyzer/crates/hir-def/src/nameres/tests.rs b/src/tools/rust-analyzer/crates/hir-def/src/nameres/tests.rs index 80e54760714..70dd2eb3ade 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/nameres/tests.rs +++ b/src/tools/rust-analyzer/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/src/tools/rust-analyzer/crates/hir-def/src/nameres/tests/globs.rs b/src/tools/rust-analyzer/crates/hir-def/src/nameres/tests/globs.rs index 17426d54d40..b2a6a592cf3 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/nameres/tests/globs.rs +++ b/src/tools/rust-analyzer/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 + crate::d + Y: t v foo: t - - crate::a - foo: t - - crate::a::foo - X: t v "#]], ); } diff --git a/src/tools/rust-analyzer/crates/hir-def/src/nameres/tests/macros.rs b/src/tools/rust-analyzer/crates/hir-def/src/nameres/tests/macros.rs index 520a6ae1cba..7b7f94c5333 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/nameres/tests/macros.rs +++ b/src/tools/rust-analyzer/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`