mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-22 15:31:03 +01:00
Expose notes from wgsl::ParseError (#9572)
Co-authored-by: Koen Willemsen <Koen.Willemsen@materialise.be>
This commit is contained in:
1 parent
e940ef9103
commit
ce445e882e
2 files changed
+35
No files matched your search
@@ -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
|
||||
|
||||
|
||||
@@ -46,6 +46,10 @@ impl ParseError {
|
||||
&self.message
|
||||
}
|
||||
|
||||
pub fn notes(&self) -> impl ExactSizeIterator<Item = &str> + '_ {
|
||||
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::<super::Vec<_>>(),
|
||||
[
|
||||
"`cross` accepts the following types for argument #1:",
|
||||
"allowed type: vec3<{AbstractFloat}>",
|
||||
"allowed type: vec3<f32>",
|
||||
"allowed type: vec3<f16>",
|
||||
"allowed type: vec3<f64>"
|
||||
]
|
||||
.to_vec()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
pub enum ExpectedToken<'a> {
|
||||
Token(Token<'a>),
|
||||
|
||||
Reference in new issue
Block a user