Skip to content

Commit 2e34322

Browse files
authored
[naga] De-indent mainline control flow in interface validation. (#8359)
In `naga::valid::interface::VaryingContext::validate`, use `let else` instead of `match`, to promote the main flow of control to a lower indentation level, and move error reporting closer to the check that failed.
1 parent 59a03ea commit 2e34322

File tree

1 file changed

+33
-35
lines changed

1 file changed

+33
-35
lines changed

naga/src/valid/interface.rs

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -549,47 +549,45 @@ impl VaryingContext<'_> {
549549
.validate_impl(ep, ty, binding)
550550
.map_err(|e| e.with_span_context(span_context)),
551551
None => {
552-
match self.types[ty].inner {
553-
crate::TypeInner::Struct { ref members, .. } => {
554-
for (index, member) in members.iter().enumerate() {
555-
let span_context = self.types.get_span_context(ty);
556-
match member.binding {
557-
None => {
558-
if self.flags.contains(super::ValidationFlags::BINDINGS) {
559-
return Err(VaryingError::MemberMissingBinding(
560-
index as u32,
561-
)
562-
.with_span_context(span_context));
563-
}
564-
}
565-
Some(ref binding) => self
566-
.validate_impl(ep, member.ty, binding)
567-
.map_err(|e| e.with_span_context(span_context))?,
568-
}
569-
}
570-
571-
if !self.blend_src_mask.is_empty() {
572-
let span_context = self.types.get_span_context(ty);
552+
let crate::TypeInner::Struct { ref members, .. } = self.types[ty].inner else {
553+
if self.flags.contains(super::ValidationFlags::BINDINGS) {
554+
return Err(VaryingError::MissingBinding.with_span());
555+
} else {
556+
return Ok(());
557+
}
558+
};
573559

574-
// If there's any blend_src usage, it must apply to all members of which there must be exactly 2.
575-
if members.len() != 2 || self.blend_src_mask.len() != 2 {
576-
return Err(VaryingError::IncompleteBlendSrcUsage
560+
for (index, member) in members.iter().enumerate() {
561+
let span_context = self.types.get_span_context(ty);
562+
match member.binding {
563+
None => {
564+
if self.flags.contains(super::ValidationFlags::BINDINGS) {
565+
return Err(VaryingError::MemberMissingBinding(index as u32)
577566
.with_span_context(span_context));
578567
}
579-
// Also, all members must have the same type.
580-
if members[0].ty != members[1].ty {
581-
return Err(VaryingError::BlendSrcOutputTypeMismatch {
582-
blend_src_0_type: members[0].ty,
583-
blend_src_1_type: members[1].ty,
584-
}
585-
.with_span_context(span_context));
586-
}
587568
}
569+
Some(ref binding) => self
570+
.validate_impl(ep, member.ty, binding)
571+
.map_err(|e| e.with_span_context(span_context))?,
588572
}
589-
_ => {
590-
if self.flags.contains(super::ValidationFlags::BINDINGS) {
591-
return Err(VaryingError::MissingBinding.with_span());
573+
}
574+
575+
if !self.blend_src_mask.is_empty() {
576+
let span_context = self.types.get_span_context(ty);
577+
578+
// If there's any blend_src usage, it must apply to all members of which there must be exactly 2.
579+
if members.len() != 2 || self.blend_src_mask.len() != 2 {
580+
return Err(
581+
VaryingError::IncompleteBlendSrcUsage.with_span_context(span_context)
582+
);
583+
}
584+
// Also, all members must have the same type.
585+
if members[0].ty != members[1].ty {
586+
return Err(VaryingError::BlendSrcOutputTypeMismatch {
587+
blend_src_0_type: members[0].ty,
588+
blend_src_1_type: members[1].ty,
592589
}
590+
.with_span_context(span_context));
593591
}
594592
}
595593
Ok(())

0 commit comments

Comments
 (0)