Account for coercions in trait resolution? #62530
Labels
A-coercions
Area: implicit and explicit `expr as Type` coercions
A-trait-system
Area: Trait system
T-lang
Relevant to the language team, which will review and decide on the PR/issue.
This came up in #62528, see “Joining strings with
char
”.Reduced test case:
Output: (Identical in rustc 1.36.0 (a53f9df 2019-07-03) and rustc 1.38.0-nightly (78ca1bd 2019-07-08).)
In the
takes_str(&string)
call, the type of the_x
parameter is known to be&str
.&String
can be coerced through auto-deref.In the
takes_type_parameter(&string)
call, I imagine that trait resolution finds two solution (the_x
parameter is either&str
orchar
) but neither of them match with&string
directly, so trait resolution emits an error. Presumably, coercion are only attempted in a later phase of compilation.Is there a language design reason it has to be this way, or could we make programs like the above valid? (It then “only” be a matter of compiler implementation.)
The text was updated successfully, but these errors were encountered: