Misplaced "type of this value must be known ..." error #36598
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
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.
In a transformation sequence, I got a type inference error on the first function call, while the error was actually later (and below) in the chain. This was very confusing, in particular since the offending line was not shown in the error message. This could be a duplicate of #36495, or a more general issue not related to type inference.
As it should, rustc 1.11.0 on OS X fails to build the following code:
The error message is:
On nightly the error report is nicer, but no more helpful. The fix, which is obvious once one decides to ignore the line indication from rustc, is to add a type annotation to
collect()
:After poking around a bit, I suspect that this may be a more general issue related to how rustc determines the offending line number. For instance, the error message from the compiler has the same problem, while the error is "mismatched types":
While this is the kind of thing that only bites you once, it can utterly confuse a beginner. It is particularly perplexing in more complex, multi-line expressions. One could of course argue that the error location is correct as it points to the flawed expression, but that does not really help. Perhaps indicating where in the expression the error lies would be better, e.g (using the new and much better error message style from nightly)?
The text was updated successfully, but these errors were encountered: