From 58db7e3a65ac96664ebd8c73bdff7185e59b8cff Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Wed, 10 Aug 2022 20:42:54 +0300 Subject: fix(tvix/value): ensure only string values of NixString are hashed Change-Id: I1b97cf5a9e4e235fac72a507de49a8df508bcaa1 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6138 Tested-by: BuildkiteCI Reviewed-by: sterni --- tvix/eval/src/value/string.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'tvix/eval') diff --git a/tvix/eval/src/value/string.rs b/tvix/eval/src/value/string.rs index 1b4f349f1ac5..f9178ca7f4bb 100644 --- a/tvix/eval/src/value/string.rs +++ b/tvix/eval/src/value/string.rs @@ -1,9 +1,10 @@ +use std::hash::Hash; use std::{borrow::Cow, fmt::Display}; /// This module implements Nix language strings and their different /// backing implementations. -#[derive(Clone, Debug, Hash, Eq, Ord)] +#[derive(Clone, Debug, Eq, Ord)] pub enum NixString { Static(&'static str), Heap(String), @@ -33,6 +34,12 @@ impl From for NixString { } } +impl Hash for NixString { + fn hash(&self, state: &mut H) { + self.as_str().hash(state) + } +} + impl NixString { pub const NAME: Self = NixString::Static("name"); pub const VALUE: Self = NixString::Static("value"); -- cgit 1.4.1