The return type of the function b
does matter, as it makes the difference of compiling, and not compiling.
Who would the compiler figure out what you want? It's not a problem of codegen, it's figuring out what the programmer wants.
Also, the optimizer is not a magic bullet, it can't optimize away everything, and From::from
calls can also to be expensive due to allocations, for example String::from(&str)
needs to perform an allocation, and therefore is expensive, and the optimizer cannot optimize that out. Finally, relying on an optimizer to get expected behavior is bad, as even slight changes have drastic, often unpredictable, effects.