Skip to content

Commit

Permalink
feat: impl FromStr for naga::wgsl::error::Severity
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler committed Oct 1, 2024
1 parent 84e4102 commit 21ab041
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
10 changes: 10 additions & 0 deletions naga/src/diagnostic_filter.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::str::FromStr;

use crate::{Handle, Span};

#[cfg(feature = "arbitrary")]
Expand Down Expand Up @@ -32,6 +34,14 @@ impl Severity {
}
}

impl FromStr for Severity {
type Err = ();

fn from_str(s: &str) -> Result<Self, Self::Err> {
Self::from_ident(s).ok_or(())
}
}

// TODO: docs
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serialize", derive(Serialize))]
Expand Down
13 changes: 7 additions & 6 deletions naga/src/front/wgsl/parse/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::diagnostic_filter::{
DiagnosticFilter, DiagnosticFilterMap, DiagnosticFilterNode, DiagnosticTriggeringRule, Severity,
DiagnosticFilter, DiagnosticFilterMap, DiagnosticFilterNode, DiagnosticTriggeringRule,
};
use crate::front::wgsl::error::{Error, ExpectedToken};
use crate::front::wgsl::parse::directive::DirectiveKind;
Expand Down Expand Up @@ -2579,11 +2579,12 @@ impl Parser {
lexer.expect(Token::Paren('('))?;

let (severity_control_name, severity_control_name_span) = lexer.next_ident_with_span()?;
let new_severity = Severity::from_ident(severity_control_name).ok_or(
Error::DiagnosticInvalidSeverity {
severity_control_name_span,
},
)?;
let new_severity =
severity_control_name
.parse()
.map_err(|()| Error::DiagnosticInvalidSeverity {
severity_control_name_span,
})?;

lexer.expect(Token::Separator(','))?;

Expand Down

0 comments on commit 21ab041

Please sign in to comment.