Fix a bug with cross-crate trait impls

Closes #19056