Repository navigation
Suppress redundant E0308 for ADT const type mismatches - #163593
reddevilmidzy wants to merge 1 commit into
Conversation
| let _: ArrWrap<{ [1_u8] }> = ArrWrap::<{ [1_u16] }>; | ||
| //~^ ERROR: mismatched types | ||
| //~| ERROR the constant `1` is not of type `u8` | ||
| //~^ ERROR the constant `1` is not of type `u8` |
There was a problem hiding this comment.
While working on this, I also found "the constant 1 is not of type u8" a bit unclear. If it’s a integer literal, would it make sense to print its type after the value, e.g. "the constant 1_u16 is not of typeu8"?
| return false; | ||
| }; | ||
|
|
||
| if expected_value.ty != found_value.ty { |
There was a problem hiding this comment.
Hmmm. Directly comparing types like this feels scary, and potentially unsound - typically directly comparing with the ty's == to check for type equality is not what you want.
In any case, my thought is: is it possible to hook into this earlier/at a different location, when the wfcheck is done, rather than when the coercion is done? for example, in the wfcheck, is it easily possible to taint/make the offending type be ty::Error or something? doing so is potentially quite a large change that widely impacts quite a few diagnostics, for example, I imagine the following code would no longer emit the type mismatch error:
trait Trait {}
impl Trait for u32 {}
struct Struct<T: Trait>(T);
fn main() {
let _: Struct<u32> = Struct::<u64>(1);
}
in other words, whether or not the above (providing a bad type) emits a type mismatch error ought to probably match whether or not this PR emits a type mismatch error (providing a bad const).
That's a change that we may or may not want to do. If you want to keep this change contained and focused, it might be better to focus on the formatting of the bad error message, I think either way is fine. (Perhaps you're able to do two birds with one stone for the 1 is not of type u8 message as well)
part of #162851
r? khyperia