Skip to content

Commit b85a451

Browse files
jimblandyErichDonGubler
authored andcommitted
[naga wgsl-in] Use String in error, not Box<str>.
Use `String` in variants of `naga::front::wgsl::Error`, not `Box<str>`. Delete test `naga::front::wgsl::error::test_error_size`. Since `Error` is always returned boxed, its size should have no effect on `Result` size.
1 parent 5c9c6ea commit b85a451

File tree

4 files changed

+24
-29
lines changed

4 files changed

+24
-29
lines changed

naga/src/front/wgsl/error.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ pub(crate) enum Error<'a> {
174174
BadTexture(Span),
175175
BadTypeCast {
176176
span: Span,
177-
from_type: Box<str>,
178-
to_type: Box<str>,
177+
from_type: String,
178+
to_type: String,
179179
},
180180
BadTextureSampleType {
181181
span: Span,
@@ -211,8 +211,8 @@ pub(crate) enum Error<'a> {
211211
TypeNotInferable(Span),
212212
InitializationTypeMismatch {
213213
name: Span,
214-
expected: Box<str>,
215-
got: Box<str>,
214+
expected: String,
215+
got: String,
216216
},
217217
DeclMissingTypeAndInit(Span),
218218
MissingAttribute(&'static str, Span),
@@ -342,24 +342,24 @@ impl From<&'static str> for DiagnosticAttributeNotSupportedPosition {
342342
#[derive(Clone, Debug)]
343343
pub(crate) struct AutoConversionError {
344344
pub dest_span: Span,
345-
pub dest_type: Box<str>,
345+
pub dest_type: String,
346346
pub source_span: Span,
347-
pub source_type: Box<str>,
347+
pub source_type: String,
348348
}
349349

350350
#[derive(Clone, Debug)]
351351
pub(crate) struct AutoConversionLeafScalarError {
352352
pub dest_span: Span,
353-
pub dest_scalar: Box<str>,
353+
pub dest_scalar: String,
354354
pub source_span: Span,
355-
pub source_type: Box<str>,
355+
pub source_type: String,
356356
}
357357

358358
#[derive(Clone, Debug)]
359359
pub(crate) struct ConcretizationFailedError {
360360
pub expr_span: Span,
361-
pub expr_type: Box<str>,
362-
pub scalar: Box<str>,
361+
pub expr_type: String,
362+
pub scalar: String,
363363
pub inner: ConstantEvaluatorError,
364364
}
365365

@@ -1179,8 +1179,3 @@ impl<'a> Error<'a> {
11791179
}
11801180
}
11811181
}
1182-
1183-
#[test]
1184-
fn test_error_size() {
1185-
assert!(size_of::<Error<'_>>() <= 48);
1186-
}

naga/src/front/wgsl/lower/construction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,11 @@ impl<'source> Lowerer<'source, '_> {
536536

537537
// Bad conversion (type cast)
538538
(Components::One { span, ty_inner, .. }, constructor) => {
539-
let from_type = ty_inner.to_wgsl(&ctx.module.to_ctx()).into();
539+
let from_type = ty_inner.to_wgsl(&ctx.module.to_ctx());
540540
return Err(Box::new(Error::BadTypeCast {
541541
span,
542542
from_type,
543-
to_type: constructor.to_error_string(ctx).into(),
543+
to_type: constructor.to_error_string(ctx),
544544
}));
545545
}
546546

naga/src/front/wgsl/lower/conversion.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ impl<'source> super::ExpressionContext<'source, '_, '_> {
5454
Some(scalars) => scalars,
5555
None => {
5656
let gctx = &self.module.to_ctx();
57-
let source_type = expr_resolution.to_wgsl(gctx).into();
58-
let dest_type = goal_ty.to_wgsl(gctx).into();
57+
let source_type = expr_resolution.to_wgsl(gctx);
58+
let dest_type = goal_ty.to_wgsl(gctx);
5959

6060
return Err(Box::new(super::Error::AutoConversion(Box::new(
6161
AutoConversionError {
@@ -96,10 +96,10 @@ impl<'source> super::ExpressionContext<'source, '_, '_> {
9696

9797
let make_error = || {
9898
let gctx = &self.module.to_ctx();
99-
let source_type = expr_resolution.to_wgsl(gctx).into();
99+
let source_type = expr_resolution.to_wgsl(gctx);
100100
super::Error::AutoConversionLeafScalar(Box::new(AutoConversionLeafScalarError {
101101
dest_span: goal_span,
102-
dest_scalar: goal_scalar.to_wgsl().into(),
102+
dest_scalar: goal_scalar.to_wgsl(),
103103
source_span: expr_span,
104104
source_type,
105105
}))
@@ -275,8 +275,8 @@ impl<'source> super::ExpressionContext<'source, '_, '_> {
275275
let expr_type = &self.typifier()[expr];
276276
super::Error::ConcretizationFailed(Box::new(ConcretizationFailedError {
277277
expr_span,
278-
expr_type: expr_type.to_wgsl(&self.module.to_ctx()).into(),
279-
scalar: concretized.to_wgsl().into(),
278+
expr_type: expr_type.to_wgsl(&self.module.to_ctx()),
279+
scalar: concretized.to_wgsl(),
280280
inner: err,
281281
}))
282282
})?;

naga/src/front/wgsl/lower/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,8 +1256,8 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
12561256
if !explicit_inner.equivalent(init_inner, &ectx.module.types) {
12571257
return Err(Box::new(Error::InitializationTypeMismatch {
12581258
name: name.span,
1259-
expected: explicit_inner.to_wgsl(&ectx.module.to_ctx()).into(),
1260-
got: init_inner.to_wgsl(&ectx.module.to_ctx()).into(),
1259+
expected: explicit_inner.to_wgsl(&ectx.module.to_ctx()),
1260+
got: init_inner.to_wgsl(&ectx.module.to_ctx()),
12611261
}));
12621262
}
12631263
ty = explicit_ty;
@@ -1490,8 +1490,8 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
14901490
let gctx = &ctx.module.to_ctx();
14911491
return Err(Box::new(Error::InitializationTypeMismatch {
14921492
name: l.name.span,
1493-
expected: ty.to_wgsl(gctx).into(),
1494-
got: init_ty.to_wgsl(gctx).into(),
1493+
expected: ty.to_wgsl(gctx),
1494+
got: init_ty.to_wgsl(gctx),
14951495
}));
14961496
}
14971497
}
@@ -2194,9 +2194,9 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
21942194
let ty = resolve!(ctx, expr);
21952195
let gctx = &ctx.module.to_ctx();
21962196
return Err(Box::new(Error::BadTypeCast {
2197-
from_type: ty.to_wgsl(gctx).into(),
2197+
from_type: ty.to_wgsl(gctx),
21982198
span: ty_span,
2199-
to_type: to_resolved.to_wgsl(gctx).into(),
2199+
to_type: to_resolved.to_wgsl(gctx),
22002200
}));
22012201
}
22022202
};

0 commit comments

Comments
 (0)