@@ -216,7 +216,7 @@ impl<'a> Error<'a> {
216
216
ExpectedToken :: WorkgroupSizeSeparator => "workgroup size separator (',') or a closing parenthesis" . to_string ( ) ,
217
217
ExpectedToken :: GlobalItem => "global item ('struct', 'let', 'var', 'type', ';', 'fn') or the end of the file" . to_string ( ) ,
218
218
} ;
219
- ParseError {
219
+ ParseError {
220
220
message : format ! (
221
221
"expected {}, found '{}'" ,
222
222
expected_str,
@@ -228,17 +228,14 @@ impl<'a> Error<'a> {
228
228
) ] ,
229
229
notes : vec ! [ ] ,
230
230
}
231
- } ,
231
+ }
232
232
Error :: UnexpectedComponents ( ref bad_span) => ParseError {
233
233
message : "unexpected components" . to_string ( ) ,
234
234
labels : vec ! [ ( bad_span. clone( ) , "unexpected components" . into( ) ) ] ,
235
235
notes : vec ! [ ] ,
236
236
} ,
237
237
Error :: BadNumber ( ref bad_span, ref err) => ParseError {
238
- message : format ! (
239
- "{}: `{}`" ,
240
- err, & source[ bad_span. clone( ) ] ,
241
- ) ,
238
+ message : format ! ( "{}: `{}`" , err, & source[ bad_span. clone( ) ] , ) ,
242
239
labels : vec ! [ ( bad_span. clone( ) , err. to_string( ) . into( ) ) ] ,
243
240
notes : vec ! [ ] ,
244
241
} ,
@@ -258,12 +255,11 @@ impl<'a> Error<'a> {
258
255
labels : vec ! [ ( bad_span. clone( ) , "expected unsigned integer" . into( ) ) ] ,
259
256
notes : vec ! [ ] ,
260
257
} ,
261
- Error :: BadMatrixScalarKind (
262
- ref span,
263
- kind,
264
- width,
265
- ) => ParseError {
266
- message : format ! ( "matrix scalar type must be floating-point, but found `{}`" , kind. to_wgsl( width) ) ,
258
+ Error :: BadMatrixScalarKind ( ref span, kind, width) => ParseError {
259
+ message : format ! (
260
+ "matrix scalar type must be floating-point, but found `{}`" ,
261
+ kind. to_wgsl( width)
262
+ ) ,
267
263
labels : vec ! [ ( span. clone( ) , "must be floating-point (e.g. `f32`)" . into( ) ) ] ,
268
264
notes : vec ! [ ] ,
269
265
} ,
@@ -283,39 +279,67 @@ impl<'a> Error<'a> {
283
279
Error :: UnknownScalarType ( ref bad_span) => ParseError {
284
280
message : format ! ( "unknown scalar type: '{}'" , & source[ bad_span. clone( ) ] ) ,
285
281
labels : vec ! [ ( bad_span. clone( ) , "unknown scalar type" . into( ) ) ] ,
286
- notes : vec ! [ "Valid scalar types are f16, f32, f64, i8, i16, i32, i64, u8, u16, u32, u64, bool" . into( ) ] ,
282
+ notes : vec ! [ "Valid scalar types are f16, f32, f64, \
283
+ i8, i16, i32, i64, \
284
+ u8, u16, u32, u64, bool"
285
+ . into( ) ] ,
287
286
} ,
288
- Error :: BadTextureSampleType { ref span, kind, width } => ParseError {
289
- message : format ! ( "texture sample type must be one of f32, i32 or u32, but found {}" , kind. to_wgsl( width) ) ,
287
+ Error :: BadTextureSampleType {
288
+ ref span,
289
+ kind,
290
+ width,
291
+ } => ParseError {
292
+ message : format ! (
293
+ "texture sample type must be one of f32, i32 or u32, but found {}" ,
294
+ kind. to_wgsl( width)
295
+ ) ,
290
296
labels : vec ! [ ( span. clone( ) , "must be one of f32, i32 or u32" . into( ) ) ] ,
291
297
notes : vec ! [ ] ,
292
298
} ,
293
299
Error :: BadIncrDecrReferenceType ( ref span) => ParseError {
294
- message : "increment/decrement operation requires reference type to be one of i32 or u32" . to_string ( ) ,
295
- labels : vec ! [ ( span. clone( ) , "must be a reference type of i32 or u32" . into( ) ) ] ,
300
+ message :
301
+ "increment/decrement operation requires reference type to be one of i32 or u32"
302
+ . to_string ( ) ,
303
+ labels : vec ! [ (
304
+ span. clone( ) ,
305
+ "must be a reference type of i32 or u32" . into( ) ,
306
+ ) ] ,
296
307
notes : vec ! [ ] ,
297
308
} ,
298
309
Error :: BadTexture ( ref bad_span) => ParseError {
299
- message : format ! ( "expected an image, but found '{}' which is not an image" , & source[ bad_span. clone( ) ] ) ,
310
+ message : format ! (
311
+ "expected an image, but found '{}' which is not an image" ,
312
+ & source[ bad_span. clone( ) ]
313
+ ) ,
300
314
labels : vec ! [ ( bad_span. clone( ) , "not an image" . into( ) ) ] ,
301
315
notes : vec ! [ ] ,
302
316
} ,
303
- Error :: BadTypeCast { ref span, ref from_type, ref to_type } => {
317
+ Error :: BadTypeCast {
318
+ ref span,
319
+ ref from_type,
320
+ ref to_type,
321
+ } => {
304
322
let msg = format ! ( "cannot cast a {} to a {}" , from_type, to_type) ;
305
323
ParseError {
306
324
message : msg. clone ( ) ,
307
325
labels : vec ! [ ( span. clone( ) , msg. into( ) ) ] ,
308
326
notes : vec ! [ ] ,
309
327
}
310
- } ,
328
+ }
311
329
Error :: InvalidResolve ( ref resolve_error) => ParseError {
312
330
message : resolve_error. to_string ( ) ,
313
331
labels : vec ! [ ] ,
314
332
notes : vec ! [ ] ,
315
333
} ,
316
334
Error :: InvalidForInitializer ( ref bad_span) => ParseError {
317
- message : format ! ( "for(;;) initializer is not an assignment or a function call: '{}'" , & source[ bad_span. clone( ) ] ) ,
318
- labels : vec ! [ ( bad_span. clone( ) , "not an assignment or function call" . into( ) ) ] ,
335
+ message : format ! (
336
+ "for(;;) initializer is not an assignment or a function call: '{}'" ,
337
+ & source[ bad_span. clone( ) ]
338
+ ) ,
339
+ labels : vec ! [ (
340
+ bad_span. clone( ) ,
341
+ "not an assignment or function call" . into( ) ,
342
+ ) ] ,
319
343
notes : vec ! [ ] ,
320
344
} ,
321
345
Error :: InvalidBreakIf ( ref bad_span) => ParseError {
@@ -324,22 +348,34 @@ impl<'a> Error<'a> {
324
348
notes : vec ! [ ] ,
325
349
} ,
326
350
Error :: InvalidGatherComponent ( ref bad_span, component) => ParseError {
327
- message : format ! ( "textureGather component {} doesn't exist, must be 0, 1, 2, or 3" , component) ,
351
+ message : format ! (
352
+ "textureGather component {} doesn't exist, must be 0, 1, 2, or 3" ,
353
+ component
354
+ ) ,
328
355
labels : vec ! [ ( bad_span. clone( ) , "invalid component" . into( ) ) ] ,
329
356
notes : vec ! [ ] ,
330
357
} ,
331
358
Error :: InvalidConstructorComponentType ( ref bad_span, component) => ParseError {
332
- message : format ! ( "invalid type for constructor component at index [{}]" , component) ,
359
+ message : format ! (
360
+ "invalid type for constructor component at index [{}]" ,
361
+ component
362
+ ) ,
333
363
labels : vec ! [ ( bad_span. clone( ) , "invalid component type" . into( ) ) ] ,
334
364
notes : vec ! [ ] ,
335
365
} ,
336
366
Error :: InvalidIdentifierUnderscore ( ref bad_span) => ParseError {
337
367
message : "Identifier can't be '_'" . to_string ( ) ,
338
368
labels : vec ! [ ( bad_span. clone( ) , "invalid identifier" . into( ) ) ] ,
339
- notes : vec ! [ "Use phony assignment instead ('_ =' notice the absence of 'let' or 'var')" . to_string( ) ] ,
369
+ notes : vec ! [
370
+ "Use phony assignment instead ('_ =' notice the absence of 'let' or 'var')"
371
+ . to_string( ) ,
372
+ ] ,
340
373
} ,
341
374
Error :: ReservedIdentifierPrefix ( ref bad_span) => ParseError {
342
- message : format ! ( "Identifier starts with a reserved prefix: '{}'" , & source[ bad_span. clone( ) ] ) ,
375
+ message : format ! (
376
+ "Identifier starts with a reserved prefix: '{}'" ,
377
+ & source[ bad_span. clone( ) ]
378
+ ) ,
343
379
labels : vec ! [ ( bad_span. clone( ) , "invalid identifier" . into( ) ) ] ,
344
380
notes : vec ! [ ] ,
345
381
} ,
@@ -374,7 +410,10 @@ impl<'a> Error<'a> {
374
410
notes : vec ! [ ] ,
375
411
} ,
376
412
Error :: UnknownConservativeDepth ( ref bad_span) => ParseError {
377
- message : format ! ( "unknown conservative depth: '{}'" , & source[ bad_span. clone( ) ] ) ,
413
+ message : format ! (
414
+ "unknown conservative depth: '{}'" ,
415
+ & source[ bad_span. clone( ) ]
416
+ ) ,
378
417
labels : vec ! [ ( bad_span. clone( ) , "unknown conservative depth" . into( ) ) ] ,
379
418
notes : vec ! [ ] ,
380
419
} ,
@@ -385,12 +424,18 @@ impl<'a> Error<'a> {
385
424
} ,
386
425
Error :: SizeAttributeTooLow ( ref bad_span, min_size) => ParseError {
387
426
message : format ! ( "struct member size must be at least {}" , min_size) ,
388
- labels : vec ! [ ( bad_span. clone( ) , format!( "must be at least {}" , min_size) . into( ) ) ] ,
427
+ labels : vec ! [ (
428
+ bad_span. clone( ) ,
429
+ format!( "must be at least {}" , min_size) . into( ) ,
430
+ ) ] ,
389
431
notes : vec ! [ ] ,
390
432
} ,
391
433
Error :: AlignAttributeTooLow ( ref bad_span, min_align) => ParseError {
392
434
message : format ! ( "struct member alignment must be at least {}" , min_align) ,
393
- labels : vec ! [ ( bad_span. clone( ) , format!( "must be at least {}" , min_align) . into( ) ) ] ,
435
+ labels : vec ! [ (
436
+ bad_span. clone( ) ,
437
+ format!( "must be at least {}" , min_align) . into( ) ,
438
+ ) ] ,
394
439
notes : vec ! [ ] ,
395
440
} ,
396
441
Error :: NonPowerOfTwoAlignAttribute ( ref bad_span) => ParseError {
@@ -400,7 +445,10 @@ impl<'a> Error<'a> {
400
445
} ,
401
446
Error :: InconsistentBinding ( ref span) => ParseError {
402
447
message : "input/output binding is not consistent" . to_string ( ) ,
403
- labels : vec ! [ ( span. clone( ) , "input/output binding is not consistent" . into( ) ) ] ,
448
+ labels : vec ! [ (
449
+ span. clone( ) ,
450
+ "input/output binding is not consistent" . into( ) ,
451
+ ) ] ,
404
452
notes : vec ! [ ] ,
405
453
} ,
406
454
Error :: UnknownLocalFunction ( ref span) => ParseError {
@@ -419,18 +467,35 @@ impl<'a> Error<'a> {
419
467
notes : vec ! [ ] ,
420
468
} ,
421
469
Error :: InitializationTypeMismatch ( ref name_span, ref expected_ty) => ParseError {
422
- message : format ! ( "the type of `{}` is expected to be `{}`" , & source[ name_span. clone( ) ] , expected_ty) ,
423
- labels : vec ! [ ( name_span. clone( ) , format!( "definition of `{}`" , & source[ name_span. clone( ) ] ) . into( ) ) ] ,
470
+ message : format ! (
471
+ "the type of `{}` is expected to be `{}`" ,
472
+ & source[ name_span. clone( ) ] ,
473
+ expected_ty
474
+ ) ,
475
+ labels : vec ! [ (
476
+ name_span. clone( ) ,
477
+ format!( "definition of `{}`" , & source[ name_span. clone( ) ] ) . into( ) ,
478
+ ) ] ,
424
479
notes : vec ! [ ] ,
425
480
} ,
426
481
Error :: MissingType ( ref name_span) => ParseError {
427
482
message : format ! ( "variable `{}` needs a type" , & source[ name_span. clone( ) ] ) ,
428
- labels : vec ! [ ( name_span. clone( ) , format!( "definition of `{}`" , & source[ name_span. clone( ) ] ) . into( ) ) ] ,
483
+ labels : vec ! [ (
484
+ name_span. clone( ) ,
485
+ format!( "definition of `{}`" , & source[ name_span. clone( ) ] ) . into( ) ,
486
+ ) ] ,
429
487
notes : vec ! [ ] ,
430
488
} ,
431
489
Error :: MissingAttribute ( name, ref name_span) => ParseError {
432
- message : format ! ( "variable `{}` needs a '{}' attribute" , & source[ name_span. clone( ) ] , name) ,
433
- labels : vec ! [ ( name_span. clone( ) , format!( "definition of `{}`" , & source[ name_span. clone( ) ] ) . into( ) ) ] ,
490
+ message : format ! (
491
+ "variable `{}` needs a '{}' attribute" ,
492
+ & source[ name_span. clone( ) ] ,
493
+ name
494
+ ) ,
495
+ labels : vec ! [ (
496
+ name_span. clone( ) ,
497
+ format!( "definition of `{}`" , & source[ name_span. clone( ) ] ) . into( ) ,
498
+ ) ] ,
434
499
notes : vec ! [ ] ,
435
500
} ,
436
501
Error :: InvalidAtomicPointer ( ref span) => ParseError {
@@ -453,16 +518,17 @@ impl<'a> Error<'a> {
453
518
labels : vec ! [ ( span. clone( ) , "expression is not a reference" . into( ) ) ] ,
454
519
notes : vec ! [ ] ,
455
520
} ,
456
- Error :: InvalidAssignment { ref span, ty} => ParseError {
521
+ Error :: InvalidAssignment { ref span, ty } => ParseError {
457
522
message : "invalid left-hand side of assignment" . into ( ) ,
458
523
labels : vec ! [ ( span. clone( ) , "cannot assign to this expression" . into( ) ) ] ,
459
524
notes : match ty {
460
525
InvalidAssignmentType :: Swizzle => vec ! [
461
526
"WGSL does not support assignments to swizzles" . into( ) ,
462
- "consider assigning each component individually" . into( )
527
+ "consider assigning each component individually" . into( ) ,
463
528
] ,
464
529
InvalidAssignmentType :: ImmutableBinding => vec ! [
465
- format!( "'{}' is an immutable binding" , & source[ span. clone( ) ] ) , "consider declaring it with `var` instead of `let`" . into( )
530
+ format!( "'{}' is an immutable binding" , & source[ span. clone( ) ] ) ,
531
+ "consider declaring it with `var` instead of `let`" . into( ) ,
466
532
] ,
467
533
InvalidAssignmentType :: Other => vec ! [ ] ,
468
534
} ,
@@ -473,14 +539,30 @@ impl<'a> Error<'a> {
473
539
notes : vec ! [ ] ,
474
540
} ,
475
541
Error :: ReservedKeyword ( ref name_span) => ParseError {
476
- message : format ! ( "name `{}` is a reserved keyword" , & source[ name_span. clone( ) ] ) ,
477
- labels : vec ! [ ( name_span. clone( ) , format!( "definition of `{}`" , & source[ name_span. clone( ) ] ) . into( ) ) ] ,
542
+ message : format ! (
543
+ "name `{}` is a reserved keyword" ,
544
+ & source[ name_span. clone( ) ]
545
+ ) ,
546
+ labels : vec ! [ (
547
+ name_span. clone( ) ,
548
+ format!( "definition of `{}`" , & source[ name_span. clone( ) ] ) . into( ) ,
549
+ ) ] ,
478
550
notes : vec ! [ ] ,
479
551
} ,
480
- Error :: Redefinition { ref previous, ref current } => ParseError {
552
+ Error :: Redefinition {
553
+ ref previous,
554
+ ref current,
555
+ } => ParseError {
481
556
message : format ! ( "redefinition of `{}`" , & source[ current. clone( ) ] ) ,
482
- labels : vec ! [ ( current. clone( ) , format!( "redefinition of `{}`" , & source[ current. clone( ) ] ) . into( ) ) ,
483
- ( previous. clone( ) , format!( "previous definition of `{}`" , & source[ previous. clone( ) ] ) . into( ) )
557
+ labels : vec ! [
558
+ (
559
+ current. clone( ) ,
560
+ format!( "redefinition of `{}`" , & source[ current. clone( ) ] ) . into( ) ,
561
+ ) ,
562
+ (
563
+ previous. clone( ) ,
564
+ format!( "previous definition of `{}`" , & source[ previous. clone( ) ] ) . into( ) ,
565
+ ) ,
484
566
] ,
485
567
notes : vec ! [ ] ,
486
568
} ,
0 commit comments