From ce445e882e47fd3b058f3e6e818a052add2a77d0 Mon Sep 17 00:00:00 2001 From: kwillemsen Date: Fri, 22 May 2026 16:01:01 +0200 Subject: [PATCH] Expose notes from wgsl::ParseError (#9572) Co-authored-by: Koen Willemsen --- CHANGELOG.md | 1 + naga/src/front/wgsl/error.rs | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9811a44ef..24f9c31a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -163,6 +163,7 @@ By @beholdnec in [#8505](https://github.com/gfx-rs/wgpu/pull/8505). #### naga - spirv-out ray tracing pipelines. By @Vecvec in [#9085](https://github.com/gfx-rs/wgpu/pull/9085). +- Add `naga::front::wgsl::ParseError::notes()`. By @kwillemsen in [#9572](https://github.com/gfx-rs/wgpu/pull/9572). ### Changes diff --git a/naga/src/front/wgsl/error.rs b/naga/src/front/wgsl/error.rs index 59d226833..c744d5fb1 100644 --- a/naga/src/front/wgsl/error.rs +++ b/naga/src/front/wgsl/error.rs @@ -46,6 +46,10 @@ impl ParseError { &self.message } + pub fn notes(&self) -> impl ExactSizeIterator + '_ { + self.notes.iter().map(|note| note.as_str()) + } + fn diagnostic(&self) -> Diagnostic<()> { let diagnostic = Diagnostic::error() .with_message(self.message.to_string()) @@ -130,6 +134,36 @@ impl core::fmt::Display for ParseError { impl core::error::Error for ParseError {} +#[cfg(test)] +mod parse_error_tests { + + #[test] + fn test_notes() { + use crate::front::wgsl::parse_str; + // wgsl code and notes taken from: `cross_vec2()` in naga/tests/naga/wgsl_errors.rs + assert_eq!( + parse_str( + r#" + fn x() -> f32 { + return cross(vec2(0., 1.), vec2(0., 1.)); + } + "#, + ) + .unwrap_err() + .notes() + .collect::>(), + [ + "`cross` accepts the following types for argument #1:", + "allowed type: vec3<{AbstractFloat}>", + "allowed type: vec3", + "allowed type: vec3", + "allowed type: vec3" + ] + .to_vec() + ); + } +} + #[derive(Copy, Clone, Debug, PartialEq)] pub enum ExpectedToken<'a> { Token(Token<'a>),