Skip to content
This repository was archived by the owner on Jan 29, 2025. It is now read-only.

Commit 3339238

Browse files
authored
[wgsl-in] Break up long string, reformat rest of file. (#2057)
Whitespace and formatting changes only. It turns out that if `cargo fmt` comes across a single line it can't make fit within the margins, then it sort of gives up on the surrounding construct. So breaking up the error message for `Error::UnknownScalarType` in `Error::as_parse_error` and then re-running `cargo fmt` cleans up lots of other stuff in the file. cargo fmt issue: rust-lang/rustfmt#3863
1 parent 5166c2a commit 3339238

File tree

1 file changed

+125
-43
lines changed

1 file changed

+125
-43
lines changed

src/front/wgsl/mod.rs

Lines changed: 125 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ impl<'a> Error<'a> {
216216
ExpectedToken::WorkgroupSizeSeparator => "workgroup size separator (',') or a closing parenthesis".to_string(),
217217
ExpectedToken::GlobalItem => "global item ('struct', 'let', 'var', 'type', ';', 'fn') or the end of the file".to_string(),
218218
};
219-
ParseError {
219+
ParseError {
220220
message: format!(
221221
"expected {}, found '{}'",
222222
expected_str,
@@ -228,17 +228,14 @@ impl<'a> Error<'a> {
228228
)],
229229
notes: vec![],
230230
}
231-
},
231+
}
232232
Error::UnexpectedComponents(ref bad_span) => ParseError {
233233
message: "unexpected components".to_string(),
234234
labels: vec![(bad_span.clone(), "unexpected components".into())],
235235
notes: vec![],
236236
},
237237
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()],),
242239
labels: vec![(bad_span.clone(), err.to_string().into())],
243240
notes: vec![],
244241
},
@@ -258,12 +255,11 @@ impl<'a> Error<'a> {
258255
labels: vec![(bad_span.clone(), "expected unsigned integer".into())],
259256
notes: vec![],
260257
},
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+
),
267263
labels: vec![(span.clone(), "must be floating-point (e.g. `f32`)".into())],
268264
notes: vec![],
269265
},
@@ -283,39 +279,67 @@ impl<'a> Error<'a> {
283279
Error::UnknownScalarType(ref bad_span) => ParseError {
284280
message: format!("unknown scalar type: '{}'", &source[bad_span.clone()]),
285281
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()],
287286
},
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+
),
290296
labels: vec![(span.clone(), "must be one of f32, i32 or u32".into())],
291297
notes: vec![],
292298
},
293299
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+
)],
296307
notes: vec![],
297308
},
298309
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+
),
300314
labels: vec![(bad_span.clone(), "not an image".into())],
301315
notes: vec![],
302316
},
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+
} => {
304322
let msg = format!("cannot cast a {} to a {}", from_type, to_type);
305323
ParseError {
306324
message: msg.clone(),
307325
labels: vec![(span.clone(), msg.into())],
308326
notes: vec![],
309327
}
310-
},
328+
}
311329
Error::InvalidResolve(ref resolve_error) => ParseError {
312330
message: resolve_error.to_string(),
313331
labels: vec![],
314332
notes: vec![],
315333
},
316334
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+
)],
319343
notes: vec![],
320344
},
321345
Error::InvalidBreakIf(ref bad_span) => ParseError {
@@ -324,22 +348,34 @@ impl<'a> Error<'a> {
324348
notes: vec![],
325349
},
326350
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+
),
328355
labels: vec![(bad_span.clone(), "invalid component".into())],
329356
notes: vec![],
330357
},
331358
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+
),
333363
labels: vec![(bad_span.clone(), "invalid component type".into())],
334364
notes: vec![],
335365
},
336366
Error::InvalidIdentifierUnderscore(ref bad_span) => ParseError {
337367
message: "Identifier can't be '_'".to_string(),
338368
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+
],
340373
},
341374
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+
),
343379
labels: vec![(bad_span.clone(), "invalid identifier".into())],
344380
notes: vec![],
345381
},
@@ -374,7 +410,10 @@ impl<'a> Error<'a> {
374410
notes: vec![],
375411
},
376412
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+
),
378417
labels: vec![(bad_span.clone(), "unknown conservative depth".into())],
379418
notes: vec![],
380419
},
@@ -385,12 +424,18 @@ impl<'a> Error<'a> {
385424
},
386425
Error::SizeAttributeTooLow(ref bad_span, min_size) => ParseError {
387426
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+
)],
389431
notes: vec![],
390432
},
391433
Error::AlignAttributeTooLow(ref bad_span, min_align) => ParseError {
392434
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+
)],
394439
notes: vec![],
395440
},
396441
Error::NonPowerOfTwoAlignAttribute(ref bad_span) => ParseError {
@@ -400,7 +445,10 @@ impl<'a> Error<'a> {
400445
},
401446
Error::InconsistentBinding(ref span) => ParseError {
402447
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+
)],
404452
notes: vec![],
405453
},
406454
Error::UnknownLocalFunction(ref span) => ParseError {
@@ -419,18 +467,35 @@ impl<'a> Error<'a> {
419467
notes: vec![],
420468
},
421469
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+
)],
424479
notes: vec![],
425480
},
426481
Error::MissingType(ref name_span) => ParseError {
427482
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+
)],
429487
notes: vec![],
430488
},
431489
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+
)],
434499
notes: vec![],
435500
},
436501
Error::InvalidAtomicPointer(ref span) => ParseError {
@@ -453,16 +518,17 @@ impl<'a> Error<'a> {
453518
labels: vec![(span.clone(), "expression is not a reference".into())],
454519
notes: vec![],
455520
},
456-
Error::InvalidAssignment{ ref span, ty} => ParseError {
521+
Error::InvalidAssignment { ref span, ty } => ParseError {
457522
message: "invalid left-hand side of assignment".into(),
458523
labels: vec![(span.clone(), "cannot assign to this expression".into())],
459524
notes: match ty {
460525
InvalidAssignmentType::Swizzle => vec![
461526
"WGSL does not support assignments to swizzles".into(),
462-
"consider assigning each component individually".into()
527+
"consider assigning each component individually".into(),
463528
],
464529
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(),
466532
],
467533
InvalidAssignmentType::Other => vec![],
468534
},
@@ -473,14 +539,30 @@ impl<'a> Error<'a> {
473539
notes: vec![],
474540
},
475541
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+
)],
478550
notes: vec![],
479551
},
480-
Error::Redefinition { ref previous, ref current } => ParseError {
552+
Error::Redefinition {
553+
ref previous,
554+
ref current,
555+
} => ParseError {
481556
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+
),
484566
],
485567
notes: vec![],
486568
},

0 commit comments

Comments
 (0)