From 43155ab5868cb06e8caf5afb7fe753bbcbdd71b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gast=C3=B3n=20Zanitti?= Date: Fri, 30 Aug 2024 10:26:16 -0300 Subject: [PATCH] Add Hash trait for Type (#1732) Small PR that adds the `Hash` trait to `Type` and some of its internal types. Needed to be able to store `Vec` in order to solve trait implementations based on its `type_args`. --- ast/src/parsed/asm.rs | 6 ++++-- ast/src/parsed/types.rs | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/ast/src/parsed/asm.rs b/ast/src/parsed/asm.rs index 3f066c4a8..cfa9e1253 100644 --- a/ast/src/parsed/asm.rs +++ b/ast/src/parsed/asm.rs @@ -137,7 +137,7 @@ pub struct Import { /// It can contain the special word `super`, which goes up a level. /// If it does not start with `::`, it is relative. #[derive( - Default, Debug, PartialEq, Eq, Clone, PartialOrd, Ord, Serialize, Deserialize, JsonSchema, + Default, Debug, PartialEq, Eq, Clone, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema, )] pub struct SymbolPath { /// The parts between each `::`. @@ -358,7 +358,9 @@ impl Display for AbsoluteSymbolPath { } } -#[derive(Debug, PartialEq, Eq, Clone, PartialOrd, Ord, Serialize, Deserialize, JsonSchema)] +#[derive( + Debug, PartialEq, Eq, Clone, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema, +)] pub enum Part { Super, Named(String), diff --git a/ast/src/parsed/types.rs b/ast/src/parsed/types.rs index b9de603f9..6b086beb0 100644 --- a/ast/src/parsed/types.rs +++ b/ast/src/parsed/types.rs @@ -10,7 +10,9 @@ use serde::{Deserialize, Serialize}; use super::{asm::SymbolPath, visitor::Children, Expression, Number}; -#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Serialize, Deserialize, JsonSchema)] +#[derive( + Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Serialize, Deserialize, JsonSchema, +)] pub enum Type { /// The bottom type `!`, which cannot have a value but is /// compatible with all other types. @@ -260,7 +262,9 @@ impl From>> for Type { } } -#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Serialize, Deserialize, JsonSchema)] +#[derive( + Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Serialize, Deserialize, JsonSchema, +)] pub struct ArrayType { pub base: Box>, pub length: Option, @@ -295,7 +299,9 @@ impl Children> for ArrayType> { } } -#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Serialize, Deserialize, JsonSchema)] +#[derive( + Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Serialize, Deserialize, JsonSchema, +)] pub struct TupleType { pub items: Vec>, } @@ -317,7 +323,9 @@ impl From>> for TupleType { } } -#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Serialize, Deserialize, JsonSchema)] +#[derive( + Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Serialize, Deserialize, JsonSchema, +)] pub struct FunctionType { pub params: Vec>, pub value: Box>,