#[feature(nll)] produces unintelligible error message in corner case with invariance #67007
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-NLL
Area: Non-lexical lifetimes (NLL)
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
D-confusing
Diagnostics: Confusing error or lint that should be reworked.
NLL-diagnostics
Working towards the "diagnostic parity" goal
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
While working on a diagnostics improvement for the compiler, I came across an essentially unreadable error. The following (minimized) code:
produces this error:
There are several problems with this error message:
fcx.use_it(other);
causes this code to compile (I think due to the fact that the lifetime ofother
is no longer required to outlivetcx
). However, the error message points to a completely different line, which is not really the source of the problem.fcx
touse_fcx
, we (indirectly) end up constraininga
.'a: 'tcx
. Without reading the hint, you might not even realize that the named lifetimes are involved in any way.'tcx
lifetime (caused by the raw pointer, which is invariant over the pointee type). I discovered this through blind luck, as I've seen variance-related errors before. If someone has never even heard of variance, it would be virtually impossible for them to discover this - the invariance of a lifetime may be caused by the lifetime being passed to a deeply nested invariant type.Removing
#![feature(nll)]
makes the error marginally better:Here, we at least know that
'a
and'tcx
are involved. However, the span is still bad - there's no indication that the call tofcx.use_it(other)
is involved at all. The note 'so that the expression is assignable' also lacks a span entirely, making it difficult to tell what it actually means.For some reason, removing the
'tcx: 'a
requirement from theFnCtxt
definition (e.g. changing it to just'tcx
) results in a better span with#![feature(nll)]
:but the error is unchanged when
#![feature(nll)]
is not enabled.cc #62953
The text was updated successfully, but these errors were encountered: