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 18, 2024
1 parent df34823 commit 6479c1d
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
Expand Up @@ -2,6 +2,8 @@
//!
//! This functionality is typically used by front ends via [`DiagnosticFilterMap`].

use std::str::FromStr;

use crate::{Handle, Span};

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

impl FromStr for Severity {
type Err = ();

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

/// The rule being configured in a [`DiagnosticFilter`].
#[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 @@ -2572,11 +2572,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 6479c1d

Please sign in to comment.