normalizing impl headers before proving constraining projection where-clauses causes unnecessary errors due to `param_env` preference
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
trait Proj {
type Assoc;
}
struct IncorrectGuidance<T>(T);
impl<T> Proj for IncorrectGuidance<T> {
type Assoc = T;
}
trait BreakMe<T> {}
impl<T, U> BreakMe<<IncorrectGuidance<U> as Proj>::Assoc> for T
where
T: Proj<Assoc = U>,
{}
fn break_me<T: BreakMe<U>, U>() {}
fn check<T, U, V>()
where
T: Proj<Assoc = U>,
IncorrectGuidance<V>: Proj, // removing this line makes it compile
{
break_me::<T, U>();
}
when proving T: BreakMe<U> we try to use the impl impl<T, U> BreakMe<<IncorrectGuidance<U> as Proj>::Assoc> for T. Doing so goes through the following steps:
- instantiate the impl header with infer vars, giving us the
TraitRef?t: BreakMe<<IncorrectGuidance<?u> as Proj>::Assoc> - normalize the impl header to equate it with the goal. This normalizes
<IncorrectGuidance<?u> as Proj>::Assocvia theIncorrectGuidance<V>: Projwhere-clause, incorrectly constraining?utoV - only then would we prove the
?t: Proj<Assoc = ?u>where-bound which is what should constrain?u
The way this differs from e.g. https://github.com/rust-lang/rust/issues/24066 is that the goal we're proving doesn't actually reference any inference variables, so there is no way for the user to avoid this incorrect inference guidance
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling the reduced Rust example and read the candidate-preference section of the rustc-dev-guide. Trace how the impl header is normalized before its where-clause is proven, focusing on the param_env preference described in the issue. Done means the example no longer produces the unnecessary error without regressing the stated candidate-preference behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100