Misleading diagnostic when implementing const Trait
method
#103040
Labels
A-const-eval
Area: Constant evaluation, covers all const contexts (static, const fn, ...)
A-diagnostics
Area: Messages for errors, warnings, and lints
D-confusing
Diagnostics: Confusing error or lint that should be reworked.
F-const_trait_impl
`#![feature(const_trait_impl)]`
requires-nightly
This issue requires a nightly compiler in some way.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Uh oh!
There was an error while loading. Please reload this page.
(playground)
This error is technically correct, as the only const
eq
method onstd::time::Instant
is the one being written. However, it is quite misleading.&Instant
is the type that we want to accept as a parameter, with one caveat.Instant
has to implementconst PartialEq
. It doesn't so the code shouldn't compile, but with a significantly different error message — ideally one pointing to that fact.I have deliberately chosen
Instant
for this example because it is unlikely to ever implementconst PartialEq
. As such it can be used in tests without much concern.For reference, the diagnostic is pretty much as expected (although still a bit suboptimal in my opinion) when not writing a trait method with the same name. (playground)
@rustbot label +A-const-fn +A-diagnostics +D-confusing +F-const-trait-impl +T-compiler +requires-nightly
The text was updated successfully, but these errors were encountered: