Skip to content

Commit

Permalink
ir: Use early return in c_naming_prefix.
Browse files Browse the repository at this point in the history
  • Loading branch information
emilio authored and LoganBarnett committed Dec 2, 2023
1 parent 060b665 commit 57863c2
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/ir/item.rs
Expand Up @@ -1063,18 +1063,19 @@ impl Item {

/// Returns a prefix for the canonical name when C naming is enabled.
fn c_naming_prefix(&self) -> Option<&str> {
if let ItemKind::Type(typ) = &self.kind {
match typ.kind() {
TypeKind::Comp(comp_info) => match comp_info.kind() {
CompKind::Struct => Some("struct"),
CompKind::Union => Some("union"),
},
TypeKind::Enum(_) => Some("enum"),
_ => None,
}
} else {
None
}
let ty = match self.kind {
ItemKind::Type(ref ty) => ty,
_ => return None,
};

Some(match ty.kind() {
TypeKind::Comp(ref ci) => match ci.kind() {
CompKind::Struct => "struct",
CompKind::Union => "union",
},
TypeKind::Enum(..) => "enum",
_ => return None,
})
}
}

Expand Down

0 comments on commit 57863c2

Please sign in to comment.