diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2025-04-11 10:10:06 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2025-04-11 11:03:08 +1000 |
| commit | 7e8184fa2a712356f1827c8abc01bafcd359b122 (patch) | |
| tree | 2a9d6c6ed41d01a277877631565179171725c5fa /compiler | |
| parent | 2205455d444f5f9da3a52e50f43c0306480218fb (diff) | |
| download | rust-7e8184fa2a712356f1827c8abc01bafcd359b122.tar.gz rust-7e8184fa2a712356f1827c8abc01bafcd359b122.zip | |
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.
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_middle/src/ty/assoc.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/compiler/rustc_middle/src/ty/assoc.rs b/compiler/rustc_middle/src/ty/assoc.rs index e3d332036f1..bbaf735fbdb 100644 --- a/compiler/rustc_middle/src/ty/assoc.rs +++ b/compiler/rustc_middle/src/ty/assoc.rs @@ -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"), |
