Various minor Idx-related tweaks

Nothing particularly exciting here, but a couple of things I noticed as I was looking for more index conversions to simplify.
This commit is contained in:
Scott McMurray
2023-04-16 01:06:55 -07:00
parent 2a71115261
commit c98895d9f2
17 changed files with 55 additions and 52 deletions

View File

@@ -1969,6 +1969,16 @@ impl VariantDef {
pub fn ctor_def_id(&self) -> Option<DefId> {
self.ctor.map(|(_, def_id)| def_id)
}
/// Returns the one field in this variant.
///
/// `panic!`s if there are no fields or multiple fields.
#[inline]
pub fn single_field(&self) -> &FieldDef {
assert!(self.fields.len() == 1);
&self.fields[FieldIdx::from_u32(0)]
}
}
impl PartialEq for VariantDef {