rustc
prints the same type as found and expected for function item whose signature includes references
#111497
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Code
Current output
Desired output
Should mention that the lifetimes of
self
,retrieve
andR
must match.The code compiles if you write
get
asRationale and extra context
No response
Other cases
The original code compiles fine when invoked with a closure like
f.get(|_i| None::<&String>);
that does not relate input and output lifetimes.Calling
get
with a call tomaybe_get
as a closure (that does relate the lifetimes) likef.get(|i| i.maybe_get())
giveswhich I have mixed feelings about: on the one hand, you know from the error that the problem is the relation between the lifetimes.
On the other, you could write
maybe_get
asfn maybe_get<'s>(&'s self) -> Option<&'s String>
and still get the same error, even though the lifetimes are now the same in the definition (the actual problem is thatget
doesn't know this aboutR
).Writing
get
as(note that the reference to
Inner
andR
are constrained through'a
, but notself
) giveswhich is much more helpful in figuring out that one needs to bound
self
.Anything else?
No response
The text was updated successfully, but these errors were encountered: