Suggest Self::CONST
when trying to use an associated constant lexically
#107199
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Code
Current output
Desired output
help: try referring to the associated constant: `Self::A_CONST`
Rationale and extra context
Associated constants work entirely differently from constants at a higher scope (module) or lower (function) which are looked up lexically — if either of the other two declarations in the sample code are uncommented, compilation succeeds. This may be surprising to beginners (example that inspired this post), and the “what they meant” is fairly obvious, so this should be a good opportunity to help in the error message.
Additionally, if the suggestion is machine-applicable then it can be used to help refactor code when a constant was intentionally converted into an associated constant.
Other cases
No response
Anything else?
No response
The text was updated successfully, but these errors were encountered: