Lack of variance information for subtypes in error messages (E0495) #58771
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-lifetimes
Area: Lifetimes / regions
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
We tried to build some more complex traits and this lead to a situation where the compiler would refuse to compile the trait implementation for a certain type. The reason for this turned out to be that an embedded unsafe cell somewhere deep inside the type made it invariant.
Here is an example of this:
This compiles, but if
Wrapper<T>
is changed to the Invariant version, then it refuses to compile with this error:This is a pretty gnarly situation one finds itself in because a) the compiler says
rustc --explain E0495
but there is no extended help for E0495 and b) the actual problem here is rooted in variance and subtyping and not necessarily lifetimes as such. Would it be possible to indicate that the compiler considersWrapper<T>
invariant because it contains anUnsafeCell<T>
(or&mut T
) and maybe even where and link to the variance docs? This would help tremendously understanding what's happening here.I think this is somewhat related to #51243 and #42516
The text was updated successfully, but these errors were encountered: