1
Fork 0

Use correct article in help message for conversion or cast

Before it always used `an`; now it uses the correct article for the type.
This commit is contained in:
Camelid 2020-09-27 13:36:48 -07:00
parent 1d216fef3e
commit 549f861f7d
14 changed files with 169 additions and 147 deletions

View file

@ -210,6 +210,18 @@ impl TyKind<'tcx> {
_ => false,
}
}
/// Get the article ("a" or "an") to use with this type.
///
/// **Panics if `self` is [`TyKind::Error`].**
pub fn article(&self) -> &'static str {
match self {
Int(_) | Float(_) | Array(_, _) => "an",
Adt(def, _) if def.is_enum() => "an",
Error(_) => panic!(),
_ => "a",
}
}
}
// `TyKind` is used a lot. Make sure it doesn't unintentionally get bigger.