diff --git a/naga/src/diagnostic_filter.rs b/naga/src/diagnostic_filter.rs index 95655462d5..05c98063ae 100644 --- a/naga/src/diagnostic_filter.rs +++ b/naga/src/diagnostic_filter.rs @@ -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")] @@ -52,6 +54,14 @@ impl Severity { } } +impl FromStr for Severity { + type Err = (); + + fn from_str(s: &str) -> Result { + 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))] diff --git a/naga/src/front/wgsl/parse/mod.rs b/naga/src/front/wgsl/parse/mod.rs index 4c7b3a20ef..abe993862e 100644 --- a/naga/src/front/wgsl/parse/mod.rs +++ b/naga/src/front/wgsl/parse/mod.rs @@ -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; @@ -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(','))?;