Skip to content

Suppress redundant E0308 for ADT const type mismatches - #163593

Open
reddevilmidzy wants to merge 1 commit into
rust-lang:mainfrom
reddevilmidzy:gca-diag
Open

reddevilmidzy wants to merge 1 commit into
rust-lang:mainfrom
reddevilmidzy:gca-diag

Conversation

@reddevilmidzy

Copy link
Copy Markdown
Member

part of #162851

r? khyperia

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 1, 2026
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`

@reddevilmidzy reddevilmidzy Oct 1, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"?

View changes since the review

return false;
};

if expected_value.ty != found_value.ty {

@khyperia khyperia Oct 2, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

View changes since the review

@khyperia khyperia added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 2, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants