Document/improve DynGd<_, D>
type inference
#1026
Labels
c: core
Core components
documentation
Improvements or additions to documentation
quality-of-life
No new functionality, but improves ergonomics/internals
TLDR: we need to find ways to improve or deal with error messages arising from failed type inference of
D
inDynGd<T, D>
.Originally posted by @Yarwin in #1022 (comment)
It is worth noting that type inference doesn't work – and results in very confusing errors – in most cases (sic!) if there are multiple possible
DynGd<_, D>
trait implementations.In this example foreign::NodeHealth is implementor of two dyn_gd traits:
Health
andInstanceProvider
. Trying to compile following code:Results in bunch of very confusing errors:
It might be that
&mut (dyn Health + 'static)
- a return type declared inNodeHealth
'sAsDyn
implementation fordyn_upcast
s– is different from&mut Health
and compiler tries to enforce/satisfy this lifetime bound by making a reference static?This issue should be mentioned and documented in the book. The errors are unhelpful and confusing. It is next to impossible to know what is going on without knowledge about an inner implementation (which might require some digging –
AsDyn
is hidden behind macro invocation for example, checking descriptions ofdyn_bind
s doesn't yield anything either…).Current solutions to this problem:
fn deal_20_damage(h: &mut (dyn Health + 'static)) {…}
. (ugh)The text was updated successfully, but these errors were encountered: