Skip to content

Don't suggest blanket impls with unconstrained parameters - #165442

Open
vignesh-chaturvedi wants to merge 1 commit into
rust-lang:mainfrom
vignesh-chaturvedi:fix-101174-blanket-impl-suggestion
Open

vignesh-chaturvedi wants to merge 1 commit into
rust-lang:mainfrom
vignesh-chaturvedi:fix-101174-blanket-impl-suggestion

Conversation

@vignesh-chaturvedi

@vignesh-chaturvedi vignesh-chaturvedi commented Nov 4, 2026 •

Copy link
Copy Markdown

Fixes #101174

The "alternatively use a blanket implementation" suggestion on E0782 and the bare_trait_objects warning could produce an invalid impl. For example, converting Trait<U> into T: Trait<U> leaves U unconstrained when it isn't used in the implemented trait, resulting in E0207.

This change only shows the suggestion when every type or const parameter in the trait object's generic arguments also appears in the implemented trait. Associated-type bindings are not counted, since they remain constrained by the new bound.

Updated the existing test that expected the broken suggestion, and added coverage for cases where the suggestion should be kept (GenericTraitTwo<T> and Iterator<Item = T>) or omitted when a const parameter is used only in the trait object.

Assisted-by: LLM

Avoid suggesting blanket impls when replacing the trait object would leave
generic parameters unconstrained, resulting in E0207.
@rustbot

rustbot commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

HIR ty lowering was modified

cc @fmease

@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 Nov 4, 2026
@rustbot

rustbot commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @jieyouxu (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions and our LLM policy for more information.

Why was this reviewer chosen?

The reviewer was selected based on:

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

@workingjubilee workingjubilee added the llm-assisted An LLM-assisted PR as defined by the LLM policy. Requires ahead-of-time consent by assignee. label Nov 4, 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

llm-assisted An LLM-assisted PR as defined by the LLM policy. Requires ahead-of-time consent by assignee. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rustc suggests invalid suggestion when attempting to implement invalid transitive trait impl

4 participants