Skip to content

Avoid duplicate type check errors for constrained struct - #159848

Open
chenyukang wants to merge 2 commits into
rust-lang:mainfrom
chenyukang:yukang-fix-104637-constrained-struct-errors
Open

chenyukang wants to merge 2 commits into
rust-lang:mainfrom
chenyukang:yukang-fix-104637-constrained-struct-errors

Conversation

@chenyukang

@chenyukang chenyukang commented Jul 24, 2026 •

Copy link
Copy Markdown
Member

Fixes #104637

When a struct literal has an equivalent concrete expected type, avoid registering the same struct bounds again, remove some noise.

@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 Jul 24, 2026
@rustbot

rustbot commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

r? @oli-obk

rustbot has assigned @oli-obk.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 74 candidates
  • Random selection from 18 candidates

Comment on lines +1076 to +1079
let expected_ty_provides_bounds = expected_ty.is_some_and(|expected_ty| {
!expected_ty.has_non_region_infer()
&& self.can_eq(self.param_env, expected_ty, ty.normalized)
});

@oli-obk oli-obk Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's a funky solution. I get how that would work, but it's very targeted to the duplication seen if there are expectations, when the same duplication happens without expectations, too. I'm nominating this for T-types discussion as I think we can find more general solutions to "compiler fails to prove the same thing 20 times and reports 20 slightly differently spanned errors.

View changes since the review

@oli-obk oli-obk added I-types-nominated Nominated for discussion during a types team meeting. S-waiting-on-t-types Status: Awaiting decision from T-types and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. I-types-nominated Nominated for discussion during a types team meeting. labels Jul 29, 2026
@oli-obk

oli-obk commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Brought this up with the rest of T-types

https://rust-lang.zulipchat.com/#narrow/channel/326866-t-types.2Fnominated/topic/.23159848.3A.20Avoid.20duplicate.20type.20check.20errors.20for.20constrained.20.E2.80.A6/near/613397158

The gist is:

Your solution is scary even if carefully crafted to prevent the issues that would occur with a naive version. It also doesn't apply generally to such errors.

The only difference in the errors is the root span, all the extra information in the diagnostic pointing to the where bound is duplicated. With the information about which type and which where bound part of the error, we can deduplicate those errors simply by root span order (only report the top one if they are all the same file).

Basically change report_fulfillment_errors to not just suppress duplicate errors with the same span, but also ones where solely the root span differs, but the erroring obligation is the same

@rust-bors

rust-bors Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #163111) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

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-t-types Status: Awaiting decision from T-types 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.

Duplicate errors on mismatched types on constrained structs

3 participants