Source of lifetime coercion is not reported starting in 1.63 #99256
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-lifetimes
Area: Lifetimes / regions
C-bug
Category: This is a bug.
P-high
High priority
regression-from-stable-to-stable
Performance or correctness regression from one stable version to another.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
WG-diagnostics
Working group: Diagnostics
Milestone
When the lifetime of a value is coerced to a longer one due to the use of an associated function or trait member and the previous lifetime used by other call sites is no longer sufficient, rustc no longer includes any mention of the coercion site (and includes a red herring that forces one to go chasing after the wrong goose). This makes it much, much harder to figure out why code is not working as all the locations rustc mentions are perfectly fine and have nothing to do with the actual cause of the error.
Code
When the commented-out line is added back in, rustc will emit the following error:
Try on playground.
The error message points to
self
and.input()
as the locations pertaining to this error, when in fact the error stems entirely from the usage of.output()
, which coerces the lifetime to'static
due to the trait impl, at the same time as.input()
, which doesn't last as long.rustc stable (1.62) emits the following error message instead, which is infinitely more helpful:
Notice that here the correct call sites (
.input()
and.output()
) are mentioned. In particular, the fact that.output()
is where'static
is required is clearly mentioned, making it easy to figure out what is going on.Needless to say, this is a highly stripped-down example for illustration purposes. It took me perhaps half-an-hour to chase down the actual issue in a real codebase; IIRC the
.output()
equivalent was part of the original code and.input()
was added some months later, and there were a lot of false trails to chase down before finding the.output()
lifetime coercion.Version it worked on
It most recently worked on: 1.62.0
Version with regression
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: