diff --git a/naga/src/front/wgsl/error.rs b/naga/src/front/wgsl/error.rs index 8b1e4f354f5..56b730c23aa 100644 --- a/naga/src/front/wgsl/error.rs +++ b/naga/src/front/wgsl/error.rs @@ -409,7 +409,7 @@ impl<'a> Error<'a> { }; ParseError { message: format!( - "expected {}, found '{}'", + "expected {}, found {:?}", expected_str, &source[unexpected_span], ), labels: vec![(unexpected_span, format!("expected {expected_str}").into())], diff --git a/naga/tests/wgsl_errors.rs b/naga/tests/wgsl_errors.rs index abba829d5f6..aaeed294cbd 100644 --- a/naga/tests/wgsl_errors.rs +++ b/naga/tests/wgsl_errors.rs @@ -2432,3 +2432,17 @@ fn const_assert_failed() { "###, ); } + +#[test] +fn reject_utf8_bom() { + check( + "\u{FEFF}fn main() {}", + r#"error: expected global item ('struct', 'const', 'var', 'alias', 'fn', 'diagnostic', 'enable', 'requires', ';') or the end of the file, found "\u{feff}" + ┌─ wgsl:1:1 + │ +1 │ fn main() {} + │ expected global item ('struct', 'const', 'var', 'alias', 'fn', 'diagnostic', 'enable', 'requires', ';') or the end of the file + +"#, + ); +}