librustc: Implement coercion for traits.

This ports over @pcwalton's old pull that bitrotted (#5597). Fixes #10039.

r? @pcwalton / @nikomatsakis