Add regression test for issue #10766

This test verifies that casting from the same lifetime on a value
to the same lifetime on a trait succeeds. Closes #10766.