Skip to content

Commit

Permalink
Use slice pattern to make function nicer
Browse files Browse the repository at this point in the history
  • Loading branch information
yannham committed Nov 22, 2024
1 parent 01a2688 commit 09170e3
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions core/src/bytecode/ast/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,11 @@ impl<'ast> FieldDef<'ast> {
/// Returns the identifier corresponding to this definition if the path is composed of exactly
/// one element which is a static identifier. Returns `None` otherwise.
pub fn path_as_ident(&self) -> Option<LocIdent> {
if self.path.len() > 1 {
return None;
if let [FieldPathElem::Ident(ident)] = self.path {
Some(*ident)
} else {
None
}

self.path.first().and_then(|path_elem| match path_elem {
FieldPathElem::Expr(..) => None,
FieldPathElem::Ident(ident) => Some(*ident),
})
}
}

Expand Down

0 comments on commit 09170e3

Please sign in to comment.