Rollup merge of #139654 - nnethercote:AssocKind-descr, r=compiler-errors

Improve `AssocItem::descr`.

The commit adds "associated" to the description of associated types and associated consts, to match the description of associated functions. This increases error message precision and consistency with `AssocKind::fmt`.

The commit also notes an imperfection in `AssocKind::fmt`; fixing this imperfection is possible but beyond the scope of this PR.

r? `@estebank`
This commit is contained in:
Stuart Cook 2025-04-11 13:31:50 +10:00 committed by GitHub
commit 96d282c87b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 53 additions and 51 deletions

View file

@ -98,10 +98,10 @@ impl AssocItem {
pub fn descr(&self) -> &'static str {
match self.kind {
ty::AssocKind::Const => "const",
ty::AssocKind::Const => "associated const",
ty::AssocKind::Fn if self.fn_has_self_parameter => "method",
ty::AssocKind::Fn => "associated function",
ty::AssocKind::Type => "type",
ty::AssocKind::Type => "associated type",
}
}
@ -155,6 +155,8 @@ impl AssocKind {
impl std::fmt::Display for AssocKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
// FIXME: fails to distinguish between "associated function" and
// "method" because `has_self` isn't known here.
AssocKind::Fn => write!(f, "method"),
AssocKind::Const => write!(f, "associated const"),
AssocKind::Type => write!(f, "associated type"),