Skip to content

Commit

Permalink
clarify & shorten assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
mumbleskates committed May 24, 2024
1 parent aa45a14 commit af24da1
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions prost-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,17 +413,10 @@ fn try_oneof(input: TokenStream) -> Result<TokenStream, Error> {
}
}

for (variant_ident, field) in &fields {
// Not clear if this condition is reachable since multiple "tag" attributes are already
// rejected, but good to be safe
if field.tags().len() > 1 {
bail!(
"invalid oneof variant {}::{}: oneof variants may only have a single tag",
ident,
variant_ident
);
}
}
// Oneof variants cannot be oneofs themselves, so it's impossible to have a field with multiple
// tags.
assert!(fields.iter().all(|(_, field)| field.tags().len() == 1));

if let Some(duplicate_tag) = fields
.iter()
.flat_map(|(_, field)| field.tags())
Expand Down

0 comments on commit af24da1

Please sign in to comment.