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:
parent
1d216fef3e
commit
549f861f7d
14 changed files with 169 additions and 147 deletions
|
@ -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.
|
||||
|
|
|
@ -752,8 +752,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
let msg = format!("you can convert an `{}` to `{}`", checked_ty, expected_ty);
|
||||
let cast_msg = format!("you can cast an `{} to `{}`", checked_ty, expected_ty);
|
||||
let msg = format!(
|
||||
"you can convert {} `{}` to `{}`",
|
||||
checked_ty.kind().article(),
|
||||
checked_ty,
|
||||
expected_ty
|
||||
);
|
||||
let cast_msg = format!(
|
||||
"you can cast {} `{} to `{}`",
|
||||
checked_ty.kind().article(),
|
||||
checked_ty,
|
||||
expected_ty
|
||||
);
|
||||
let lit_msg = format!(
|
||||
"change the type of the numeric literal from `{}` to `{}`",
|
||||
checked_ty, expected_ty,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue