Repository navigation
add note when there's a type mismatch due to param_env shadowing #149910
Copy link
Copy link
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemArea: Trait systemD-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Description
Activity
- addedneeds-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triagingThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
on Dec 12, 2025 example with worse error msg by @jdonszelmann
pub trait Supertrait { type Assoc; fn decoder(self) -> Self::Assoc; } pub trait Trait: Supertrait {} impl<T: Trait> Supertrait for T { type Assoc = (); fn decoder(self) -> Self::Assoc {} }
error[E0308]: mismatched types --> src/lib.rs:10:25 | 10 | fn decoder(self) -> Self::Assoc {} | ------- ^^^^^^^^^^^ expected associated type, found `()` | | | implicitly returns `()` as its body has no tail or `return` expression | = note: expected associated type `<T as Supertrait>::Assoc` found unit type `()` = help: consider constraining the associated type `<T as Supertrait>::Assoc` to `()` or calling a method that returns `<T as Supertrait>::Assoc` = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html- addedA-trait-systemArea: Trait systemArea: Trait systemT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsand removedneeds-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triagingThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
on Dec 14, 2025 @lcnr like adding a check inside the error reporting function?
yes, when reporting type mismatch errors, check whether one side is an alias, if so, check whether the alias could have been normalized to another type via an impl, if so, check whether these types would be equal, in either case, add a note explaining that the alias is rigid due to a where-bound and could have otherwise been normalized
Reacted by xonxGreat , makes so much sense now . Thanks
- added a commit that references this issue
on Feb 15, 2026 - added a commit that references this issue
on Feb 16, 2026
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemArea: Trait systemD-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
results in the following error
The reason this fails is that we do not normalize via impls if there is a where-bound in scope https://rustc-dev-guide.rust-lang.org/solve/candidate-preference.html#where-bounds-shadow-impls
If we get a type equality error and one side is an alias, we should check whether the alias would successfully normalize without param_env shadowing (using a
ProofTreeVisitorin the new solver and maybe looking at all candidates and checking for impl ones in the old), and then add a note explaining why this error happens and suggesting ways to avoid it (mostly by dropping trivial where-clauses)