[naga] Reduce indentation in ImageLoad expression validation.

In `naga::valid::expression::validate_expression`, use a let-else
statement so that the outermost control flow follows the success path,
and errors are close to the conditions that trigger them.
This commit is contained in:
Jim Blandy 2025-04-17 13:53:06 -07:00
parent 5304c3ca4a
commit de1b9a0899

View File

@ -631,19 +631,18 @@ impl super::Validator {
level,
} => {
let ty = Self::global_var_ty(module, function, image)?;
match module.types[ty].inner {
Ti::Image {
let Ti::Image {
class,
arrayed,
dim,
} => {
} = module.types[ty].inner
else {
return Err(ExpressionError::ExpectedImageType(ty));
};
match resolver[coordinate].image_storage_coordinates() {
Some(coord_dim) if coord_dim == dim => {}
_ => {
return Err(ExpressionError::InvalidImageCoordinateType(
dim, coordinate,
))
}
_ => return Err(ExpressionError::InvalidImageCoordinateType(dim, coordinate)),
};
if arrayed != array_index.is_some() {
return Err(ExpressionError::InvalidImageArrayIndex);
@ -662,9 +661,7 @@ impl super::Validator {
(None, false) => {}
(Some(sample), true) => {
if resolver[sample].scalar_kind() != Some(Sk::Sint) {
return Err(ExpressionError::InvalidImageOtherIndexType(
sample,
));
return Err(ExpressionError::InvalidImageOtherIndexType(sample));
}
}
_ => {
@ -679,17 +676,12 @@ impl super::Validator {
kind: Sk::Sint | Sk::Uint,
width: _,
}) => {}
_ => {
return Err(ExpressionError::InvalidImageArrayIndexType(level))
}
_ => return Err(ExpressionError::InvalidImageArrayIndexType(level)),
},
_ => {
return Err(ExpressionError::InvalidImageOtherIndex);
}
}
}
_ => return Err(ExpressionError::ExpectedImageType(ty)),
}
ShaderStages::all()
}
E::ImageQuery { image, query } => {