Skip to content

Commit 50d570d

Browse files
committed
fix(utils): Derive Hash manually
in `pane_size` since the `PartialEq` trait is also implemented manually. Previously the `Hash` impl wasn't consistent with the `Eq` impl, which can have weird effects when using these types in e.g. `HashMap`s or similar types. For additional information, see: - https://rust-lang.github.io/rust-clippy/master/index.html#derived_hash_with_manual_eq - https://doc.rust-lang.org/stable/std/hash/trait.Hash.html#hash-and-eq
1 parent 5a2ca0e commit 50d570d

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

zellij-utils/src/pane_size.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::position::Position;
1010

1111
/// Contains the position and size of a [`Pane`], or more generally of any terminal, measured
1212
/// in character rows and columns.
13-
#[derive(Clone, Copy, Default, Debug, Serialize, Deserialize, Hash)]
13+
#[derive(Clone, Copy, Default, Debug, Serialize, Deserialize)]
1414
pub struct PaneGeom {
1515
pub x: usize,
1616
pub y: usize,
@@ -24,6 +24,7 @@ pub struct PaneGeom {
2424
impl PartialEq for PaneGeom {
2525
fn eq(&self, other: &Self) -> bool {
2626
// compare all except is_pinned
27+
// NOTE: Keep this in sync with what the `Hash` trait impl does.
2728
self.x == other.x
2829
&& self.y == other.y
2930
&& self.rows == other.rows
@@ -32,6 +33,17 @@ impl PartialEq for PaneGeom {
3233
}
3334
}
3435

36+
impl std::hash::Hash for PaneGeom {
37+
fn hash<H: Hasher>(&self, state: &mut H) {
38+
// NOTE: Keep this in sync with what the `PartiqlEq` trait impl does.
39+
self.x.hash(state);
40+
self.y.hash(state);
41+
self.rows.hash(state);
42+
self.cols.hash(state);
43+
self.is_stacked.hash(state);
44+
}
45+
}
46+
3547
impl Eq for PaneGeom {}
3648

3749
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]

0 commit comments

Comments
 (0)