mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-19 06:59:22 +01:00
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
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user