Skip to content

Commit 1963eb7

Browse files
diag(wgsl-in): use backticks for code-like text in WGSL FE errors (#6908)
1 parent cc74173 commit 1963eb7

File tree

2 files changed

+70
-70
lines changed

2 files changed

+70
-70
lines changed

naga/src/front/wgsl/error.rs

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -359,52 +359,52 @@ impl<'a> Error<'a> {
359359
Error::Unexpected(unexpected_span, expected) => {
360360
let expected_str = match expected {
361361
ExpectedToken::Token(token) => match token {
362-
Token::Separator(c) => format!("'{c}'"),
363-
Token::Paren(c) => format!("'{c}'"),
362+
Token::Separator(c) => format!("`{c}`"),
363+
Token::Paren(c) => format!("`{c}`"),
364364
Token::Attribute => "@".to_string(),
365365
Token::Number(_) => "number".to_string(),
366366
Token::Word(s) => s.to_string(),
367-
Token::Operation(c) => format!("operation ('{c}')"),
368-
Token::LogicalOperation(c) => format!("logical operation ('{c}')"),
369-
Token::ShiftOperation(c) => format!("bitshift ('{c}{c}')"),
367+
Token::Operation(c) => format!("operation (`{c}`)"),
368+
Token::LogicalOperation(c) => format!("logical operation (`{c}`)"),
369+
Token::ShiftOperation(c) => format!("bitshift (`{c}{c}`)"),
370370
Token::AssignmentOperation(c) if c == '<' || c == '>' => {
371-
format!("bitshift ('{c}{c}=')")
371+
format!("bitshift (`{c}{c}=`)")
372372
}
373-
Token::AssignmentOperation(c) => format!("operation ('{c}=')"),
373+
Token::AssignmentOperation(c) => format!("operation (`{c}=`)"),
374374
Token::IncrementOperation => "increment operation".to_string(),
375375
Token::DecrementOperation => "decrement operation".to_string(),
376376
Token::Arrow => "->".to_string(),
377-
Token::Unknown(c) => format!("unknown ('{c}')"),
377+
Token::Unknown(c) => format!("unknown (`{c}`)"),
378378
Token::Trivia => "trivia".to_string(),
379379
Token::End => "end".to_string(),
380380
},
381381
ExpectedToken::Identifier => "identifier".to_string(),
382382
ExpectedToken::PrimaryExpression => "expression".to_string(),
383383
ExpectedToken::Assignment => "assignment or increment/decrement".to_string(),
384384
ExpectedToken::SwitchItem => concat!(
385-
"switch item ('case' or 'default') or a closing curly bracket ",
386-
"to signify the end of the switch statement ('}')"
385+
"switch item (`case` or `default`) or a closing curly bracket ",
386+
"to signify the end of the switch statement (`}`)"
387387
)
388388
.to_string(),
389389
ExpectedToken::WorkgroupSizeSeparator => {
390-
"workgroup size separator (',') or a closing parenthesis".to_string()
390+
"workgroup size separator (`,`) or a closing parenthesis".to_string()
391391
}
392392
ExpectedToken::GlobalItem => concat!(
393-
"global item ('struct', 'const', 'var', 'alias', 'fn', 'diagnostic', 'enable', 'requires', ';') ",
393+
"global item (`struct`, `const`, `var`, `alias`, `fn`, `diagnostic`, `enable`, `requires`, `;`) ",
394394
"or the end of the file"
395395
)
396396
.to_string(),
397397
ExpectedToken::Type => "type".to_string(),
398398
ExpectedToken::Variable => "variable access".to_string(),
399399
ExpectedToken::Function => "function name".to_string(),
400400
ExpectedToken::AfterIdentListArg => {
401-
"next argument, trailing comma, or end of list (',' or ';')".to_string()
401+
"next argument, trailing comma, or end of list (`,` or `;`)".to_string()
402402
}
403403
ExpectedToken::AfterIdentListComma => {
404-
"next argument or end of list (';')".to_string()
404+
"next argument or end of list (`;`)".to_string()
405405
}
406406
ExpectedToken::DiagnosticAttribute => {
407-
"the 'diagnostic' attribute identifier".to_string()
407+
"the `diagnostic` attribute identifier".to_string()
408408
}
409409
};
410410
ParseError {
@@ -445,12 +445,12 @@ impl<'a> Error<'a> {
445445
notes: vec![],
446446
},
447447
Error::UnknownIdent(ident_span, ident) => ParseError {
448-
message: format!("no definition in scope for identifier: '{ident}'"),
448+
message: format!("no definition in scope for identifier: `{ident}`"),
449449
labels: vec![(ident_span, "unknown identifier".into())],
450450
notes: vec![],
451451
},
452452
Error::UnknownScalarType(bad_span) => ParseError {
453-
message: format!("unknown scalar type: '{}'", &source[bad_span]),
453+
message: format!("unknown scalar type: `{}`", &source[bad_span]),
454454
labels: vec![(bad_span, "unknown scalar type".into())],
455455
notes: vec!["Valid scalar types are f32, f64, i32, u32, bool".into()],
456456
},
@@ -473,7 +473,7 @@ impl<'a> Error<'a> {
473473
},
474474
Error::BadTexture(bad_span) => ParseError {
475475
message: format!(
476-
"expected an image, but found '{}' which is not an image",
476+
"expected an image, but found `{}` which is not an image",
477477
&source[bad_span]
478478
),
479479
labels: vec![(bad_span, "not an image".into())],
@@ -498,7 +498,7 @@ impl<'a> Error<'a> {
498498
},
499499
Error::InvalidForInitializer(bad_span) => ParseError {
500500
message: format!(
501-
"for(;;) initializer is not an assignment or a function call: '{}'",
501+
"for(;;) initializer is not an assignment or a function call: `{}`",
502502
&source[bad_span]
503503
),
504504
labels: vec![(bad_span, "not an assignment or function call".into())],
@@ -511,7 +511,7 @@ impl<'a> Error<'a> {
511511
},
512512
Error::InvalidGatherComponent(bad_span) => ParseError {
513513
message: format!(
514-
"textureGather component '{}' doesn't exist, must be 0, 1, 2, or 3",
514+
"textureGather component `{}` doesn't exist, must be 0, 1, 2, or 3",
515515
&source[bad_span]
516516
),
517517
labels: vec![(bad_span, "invalid component".into())],
@@ -523,58 +523,58 @@ impl<'a> Error<'a> {
523523
notes: vec![],
524524
},
525525
Error::InvalidIdentifierUnderscore(bad_span) => ParseError {
526-
message: "Identifier can't be '_'".to_string(),
526+
message: "Identifier can't be `_`".to_string(),
527527
labels: vec![(bad_span, "invalid identifier".into())],
528528
notes: vec![
529-
"Use phony assignment instead ('_ =' notice the absence of 'let' or 'var')"
529+
"Use phony assignment instead (`_ =` notice the absence of `let` or `var`)"
530530
.to_string(),
531531
],
532532
},
533533
Error::ReservedIdentifierPrefix(bad_span) => ParseError {
534534
message: format!(
535-
"Identifier starts with a reserved prefix: '{}'",
535+
"Identifier starts with a reserved prefix: `{}`",
536536
&source[bad_span]
537537
),
538538
labels: vec![(bad_span, "invalid identifier".into())],
539539
notes: vec![],
540540
},
541541
Error::UnknownAddressSpace(bad_span) => ParseError {
542-
message: format!("unknown address space: '{}'", &source[bad_span]),
542+
message: format!("unknown address space: `{}`", &source[bad_span]),
543543
labels: vec![(bad_span, "unknown address space".into())],
544544
notes: vec![],
545545
},
546546
Error::RepeatedAttribute(bad_span) => ParseError {
547-
message: format!("repeated attribute: '{}'", &source[bad_span]),
547+
message: format!("repeated attribute: `{}`", &source[bad_span]),
548548
labels: vec![(bad_span, "repeated attribute".into())],
549549
notes: vec![],
550550
},
551551
Error::UnknownAttribute(bad_span) => ParseError {
552-
message: format!("unknown attribute: '{}'", &source[bad_span]),
552+
message: format!("unknown attribute: `{}`", &source[bad_span]),
553553
labels: vec![(bad_span, "unknown attribute".into())],
554554
notes: vec![],
555555
},
556556
Error::UnknownBuiltin(bad_span) => ParseError {
557-
message: format!("unknown builtin: '{}'", &source[bad_span]),
557+
message: format!("unknown builtin: `{}`", &source[bad_span]),
558558
labels: vec![(bad_span, "unknown builtin".into())],
559559
notes: vec![],
560560
},
561561
Error::UnknownAccess(bad_span) => ParseError {
562-
message: format!("unknown access: '{}'", &source[bad_span]),
562+
message: format!("unknown access: `{}`", &source[bad_span]),
563563
labels: vec![(bad_span, "unknown access".into())],
564564
notes: vec![],
565565
},
566566
Error::UnknownStorageFormat(bad_span) => ParseError {
567-
message: format!("unknown storage format: '{}'", &source[bad_span]),
567+
message: format!("unknown storage format: `{}`", &source[bad_span]),
568568
labels: vec![(bad_span, "unknown storage format".into())],
569569
notes: vec![],
570570
},
571571
Error::UnknownConservativeDepth(bad_span) => ParseError {
572-
message: format!("unknown conservative depth: '{}'", &source[bad_span]),
572+
message: format!("unknown conservative depth: `{}`", &source[bad_span]),
573573
labels: vec![(bad_span, "unknown conservative depth".into())],
574574
notes: vec![],
575575
},
576576
Error::UnknownType(bad_span) => ParseError {
577-
message: format!("unknown type: '{}'", &source[bad_span]),
577+
message: format!("unknown type: `{}`", &source[bad_span]),
578578
labels: vec![(bad_span, "unknown type".into())],
579579
notes: vec![],
580580
},
@@ -702,7 +702,7 @@ impl<'a> Error<'a> {
702702
InvalidAssignmentType::ImmutableBinding(binding_span) => (
703703
Some((binding_span, "this is an immutable binding".into())),
704704
vec![format!(
705-
"consider declaring '{}' with `var` instead of `let`",
705+
"consider declaring `{}` with `var` instead of `let`",
706706
&source[binding_span]
707707
)],
708708
),
@@ -782,11 +782,11 @@ impl<'a> Error<'a> {
782782
.into(),
783783
)],
784784
notes: vec![if uint {
785-
format!("suffix the integer with a `u`: '{}u'", &source[span])
785+
format!("suffix the integer with a `u`: `{}u`", &source[span])
786786
} else {
787787
let span = span.to_range().unwrap();
788788
format!(
789-
"remove the `u` suffix: '{}'",
789+
"remove the `u` suffix: `{}`",
790790
&source[span.start..span.end - 1]
791791
)
792792
}],
@@ -833,10 +833,10 @@ impl<'a> Error<'a> {
833833
Error::ExpectedConstExprConcreteIntegerScalar(span) => ParseError {
834834
message: concat!(
835835
"must be a const-expression that ",
836-
"resolves to a concrete integer scalar (u32 or i32)"
836+
"resolves to a concrete integer scalar (`u32` or `i32`)"
837837
)
838838
.to_string(),
839-
labels: vec![(span, "must resolve to u32 or i32".into())],
839+
labels: vec![(span, "must resolve to `u32` or `i32`".into())],
840840
notes: vec![],
841841
},
842842
Error::ExpectedNonNegative(span) => ParseError {
@@ -858,7 +858,7 @@ impl<'a> Error<'a> {
858858
message: "workgroup size is missing on compute shader entry point".to_string(),
859859
labels: vec![(
860860
span,
861-
"must be paired with a @workgroup_size attribute".into(),
861+
"must be paired with a `@workgroup_size` attribute".into(),
862862
)],
863863
notes: vec![],
864864
},
@@ -947,13 +947,13 @@ impl<'a> Error<'a> {
947947
notes: vec![],
948948
},
949949
Error::NotBool(span) => ParseError {
950-
message: "must be a const-expression that resolves to a bool".to_string(),
951-
labels: vec![(span, "must resolve to bool".into())],
950+
message: "must be a const-expression that resolves to a `bool`".to_string(),
951+
labels: vec![(span, "must resolve to `bool`".into())],
952952
notes: vec![],
953953
},
954954
Error::ConstAssertFailed(span) => ParseError {
955-
message: "const_assert failure".to_string(),
956-
labels: vec![(span, "evaluates to false".into())],
955+
message: "`const_assert` failure".to_string(),
956+
labels: vec![(span, "evaluates to `false`".into())],
957957
notes: vec![],
958958
},
959959
Error::DirectiveAfterFirstGlobalDecl { directive_span } => ParseError {

0 commit comments

Comments
 (0)