From f070c7ff6c27d8bcec4ac14014cd2190a8b98eb0 Mon Sep 17 00:00:00 2001 From: Parker Loflin Date: Wed, 18 Nov 2026 09:50:35 +0000 Subject: [PATCH] settings: Make `SettingsFile::Global` compare equal to itself (#67121) ## Summary `Ord for SettingsFile` had no `(Global, Global)` arm, so `Global.cmp(&Global)` returned `Less`. Each global settings parse added a duplicate `file_errors` entry, and lookups of `Global` returned `None`. Nothing reads `Global` errors, so there is no user-visible change. ## Testing - `test_file_ord` now includes `Global` and checks `cmp` on every pair. It fails without the fix. - `cargo test -p settings` and `./script/clippy -p settings` pass. ## Self-review - [x] I've reviewed my diff for quality, security, reliability, and performance. - [x] UI changes follow the [checklist](https://zed.dev/docs/development/ui-checklist). - [x] Tests cover the new or changed behavior. Release Notes: - N/A --- crates/settings/src/settings_store.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/crates/settings/src/settings_store.rs b/crates/settings/src/settings_store.rs index dd0ec9fbb0c..3c03c6fcfec 100644 --- a/crates/settings/src/settings_store.rs +++ b/crates/settings/src/settings_store.rs @@ -199,6 +199,7 @@ impl Ord for SettingsFile { use std::cmp::Ordering; match (self, other) { (User, User) => Ordering::Equal, + (Global, Global) => Ordering::Equal, (Server, Server) => Ordering::Equal, (Default, Default) => Ordering::Equal, (Project((id1, rel_path1)), Project((id2, rel_path2))) => id1 @@ -3153,6 +3154,7 @@ mod tests { &wt1_subdir, &wt0_child2, &SettingsFile::Server, + &SettingsFile::Global, &wt0_child1, &SettingsFile::User, ]; @@ -3168,9 +3170,27 @@ mod tests { &wt1_root, &SettingsFile::Server, &SettingsFile::User, + &SettingsFile::Global, &SettingsFile::Default, ] - ) + ); + + // The sort above can't detect a non-reflexive `cmp`. + for (left_index, left) in files.iter().enumerate() { + for (right_index, right) in files.iter().enumerate() { + assert_eq!( + left.cmp(right), + left_index.cmp(&right_index), + "{left:?} compared to {right:?}" + ); + } + } + + let mut file_errors = BTreeMap::default(); + file_errors.insert(SettingsFile::Global, 1); + file_errors.insert(SettingsFile::Global, 2); + assert_eq!(file_errors.len(), 1); + assert_eq!(file_errors.get(&SettingsFile::Global), Some(&2)); } #[test]