Skip to content

Conversation

@xonx4l
Copy link
Contributor

@xonx4l xonx4l commented Dec 27, 2025

This PR adds a diagnostics note when param-env shadows global impl as discussed in #149910

It adds a note explaining that the definition is hidden by the generic bound.

r?lcnr

@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 Dec 27, 2025
@rust-log-analyzer

This comment has been minimized.

Comment on lines 263 to 266
let all_impls =
impls.blanket_impls().iter().chain(impls.non_blanket_impls().values().flatten());

for &impl_def_id in all_impls {
Copy link
Contributor

Choose a reason for hiding this comment

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

use compute_applicable_impls_for_diagnostics instead of all_impls here

Copy link
Contributor

Choose a reason for hiding this comment

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

and specialization_graph::assoc_def to get the DefId of the assoc item

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay!

Comment on lines +293 to +294
"the associated type `{}` is defined as `{}` in the implementation, \
but the generic bound `{}` hides this definition",
Copy link
Contributor

Choose a reason for hiding this comment

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

cc @rust-lang/types unsure about this note. I think it's certainly useful. Ideally we'd link to some reference section or github issue explaining impl shadowing.

I think it's easiest to write a special github issue for this quickly explaining why this happens, what they can do about it, and how this may change in the future

Copy link
Member

Choose a reason for hiding this comment

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

Im not sure a github issue is the best place but also I don't know where would be better... If something reference-like was t-types controlled then certainly there 🤔 github issue is probably good enough :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should I open a issue then ?

Copy link
Contributor

Choose a reason for hiding this comment

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

going to do so myself as I have strong opinions on the way we frame this

@rust-log-analyzer

This comment has been minimized.

@xonx4l xonx4l force-pushed the suggest_param_env_shadowing branch from 22a4a6b to f616235 Compare January 14, 2026 04:45
@xonx4l
Copy link
Contributor Author

xonx4l commented Jan 14, 2026

@lcnr I made the suggested changes and CI is also green now .

Comment on lines +281 to +287
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).instantiate(tcx, impl_substs);

let expected_trait_ref = alias.trait_ref(tcx);

if !self.infcx.can_eq(param_env, expected_trait_ref, impl_trait_ref) {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

no need, handled by compute_applicable_impls_for_diagnostics

Suggested change
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).instantiate(tcx, impl_substs);
let expected_trait_ref = alias.trait_ref(tcx);
if !self.infcx.can_eq(param_env, expected_trait_ref, impl_trait_ref) {
return false;
}

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

Labels

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.

5 participants