test: Add a test for variance in trait matching.

I believe that #5781 got fixed by the DST work. It duplicated the
variance inference work in #12828. Therefore, all that is left in #5781
is adding the tests mentioned in that issue and its dependent issues.

Closes #5781.