Some cleanup and improvement for invalid ref casting impl This PR makes some cleanups and improvements to the `invalid_reference_casting` implementation in preparation for linting on new patterns, while reusing most of the logic. r? `@est31` (feel free to re-assign)