Fix an ICE when using struct patterns with traits

Fixes #18986.