Skip to content

Commit cf698d4

Browse files
authored
Add derives for Severity and Diagnostics (#1323)
Add derives for `Diagnostic`, `Severity` and `Diagnostics`, also `Deref` for `Diagnostics`. In current shape these are very hard to work with, which is caused by lack of basic functionalities (like `Eq`), also `Diagnostics` can't be merged or extended with ready `Diagnostic` (only by matching on it's `Severity` and then choosing correct method to reconstruct in again)
1 parent eff29c7 commit cf698d4

File tree

1 file changed

+15
-3
lines changed
  • plugins/cairo-lang-macro/src/types

1 file changed

+15
-3
lines changed

plugins/cairo-lang-macro/src/types/mod.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl From<AuxData> for Vec<u8> {
158158
}
159159

160160
/// Diagnostic returned by the procedural macro.
161-
#[derive(Debug)]
161+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
162162
pub struct Diagnostic {
163163
/// A human addressed message associated with the [`Diagnostic`].
164164
///
@@ -176,7 +176,7 @@ pub struct Diagnostic {
176176
/// This should be roughly equivalent to the severity of Cairo diagnostics.
177177
///
178178
/// The appropriate action for each diagnostic kind will be taken by `Scarb`.
179-
#[derive(Debug)]
179+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
180180
pub enum Severity {
181181
/// An error has occurred.
182182
///
@@ -189,7 +189,7 @@ pub enum Severity {
189189
}
190190

191191
/// A set of diagnostics that arose during the computation.
192-
#[derive(Debug)]
192+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
193193
pub struct Diagnostics(Vec<Diagnostic>);
194194

195195
impl Diagnostic {
@@ -252,6 +252,18 @@ impl IntoIterator for Diagnostics {
252252
}
253253
}
254254

255+
impl FromIterator<Diagnostic> for Diagnostics {
256+
fn from_iter<T: IntoIterator<Item = Diagnostic>>(iter: T) -> Self {
257+
Self(iter.into_iter().collect())
258+
}
259+
}
260+
261+
impl Extend<Diagnostic> for Diagnostics {
262+
fn extend<T: IntoIterator<Item = Diagnostic>>(&mut self, iter: T) {
263+
self.0.extend(iter);
264+
}
265+
}
266+
255267
impl ProcMacroResult {
256268
/// Create new [`ProcMacroResult`], empty diagnostics set.
257269
pub fn new(token_stream: TokenStream) -> Self {

0 commit comments

Comments
 (0)