diff --git a/src/front/wgsl/error.rs b/src/front/wgsl/error.rs index 93fff04906..6cd2a49d33 100644 --- a/src/front/wgsl/error.rs +++ b/src/front/wgsl/error.rs @@ -177,7 +177,11 @@ pub enum Error<'a> { InconsistentBinding(Span), TypeNotConstructible(Span), TypeNotInferrable(Span), - InitializationTypeMismatch(Span, String, String), + InitializationTypeMismatch { + name: Span, + expected: String, + got: String, + }, MissingType(Span), MissingAttribute(&'static str, Span), InvalidAtomicPointer(Span), @@ -475,15 +479,15 @@ impl<'a> Error<'a> { labels: vec![(span, "type can't be inferred".into())], notes: vec![], }, - Error::InitializationTypeMismatch(name_span, ref expected_ty, ref got_ty) => { + Error::InitializationTypeMismatch { name, ref expected, ref got } => { ParseError { message: format!( "the type of `{}` is expected to be `{}`, but got `{}`", - &source[name_span], expected_ty, got_ty, + &source[name], expected, got, ), labels: vec![( - name_span, - format!("definition of `{}`", &source[name_span]).into(), + name, + format!("definition of `{}`", &source[name]).into(), )], notes: vec![], } diff --git a/src/front/wgsl/lower/mod.rs b/src/front/wgsl/lower/mod.rs index ae178cb702..b85702fab2 100644 --- a/src/front/wgsl/lower/mod.rs +++ b/src/front/wgsl/lower/mod.rs @@ -963,22 +963,22 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { if let Some(explicit) = explicit_ty { if explicit != inferred_type { let ty = &ctx.module.types[explicit]; - let explicit = ty + let expected = ty .name .clone() .unwrap_or_else(|| ty.inner.to_wgsl(ctx.module.to_ctx())); let ty = &ctx.module.types[inferred_type]; - let inferred = ty + let got = ty .name .clone() .unwrap_or_else(|| ty.inner.to_wgsl(ctx.module.to_ctx())); - return Err(Error::InitializationTypeMismatch( - c.name.span, - explicit, - inferred, - )); + return Err(Error::InitializationTypeMismatch { + name: c.name.span, + expected, + got, + }); } } @@ -1167,11 +1167,11 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { .inner .equivalent(&ctx.module.types[init_ty].inner, &ctx.module.types) { - return Err(Error::InitializationTypeMismatch( - l.name.span, - ctx.format_type(ty), - ctx.format_type(init_ty), - )); + return Err(Error::InitializationTypeMismatch { + name: l.name.span, + expected: ctx.format_type(ty), + got: ctx.format_type(init_ty), + }); } } @@ -1206,11 +1206,11 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { .inner .equivalent(initializer_ty, &ctx.module.types) { - return Err(Error::InitializationTypeMismatch( - v.name.span, - ctx.format_type(explicit), - ctx.format_typeinner(initializer_ty), - )); + return Err(Error::InitializationTypeMismatch { + name: v.name.span, + expected: ctx.format_type(explicit), + got: ctx.format_typeinner(initializer_ty), + }); } explicit }