Skip to content

permit inference variables to be unified with unnormalized projections #305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions chalk-solve/src/infer/unify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,13 @@ impl<'t, TF: TypeFamily> Unifier<'t, TF> {
(&TyData::InferenceVar(var), &TyData::Apply(_))
| (&TyData::InferenceVar(var), &TyData::Opaque(_))
| (&TyData::InferenceVar(var), &TyData::Dyn(_))
| (&TyData::InferenceVar(var), &TyData::Projection(_))
| (&TyData::InferenceVar(var), &TyData::ForAll(_)) => self.unify_var_ty(var, b),

(&TyData::Apply(_), &TyData::InferenceVar(var))
| (TyData::Opaque(_), &TyData::InferenceVar(var))
| (&TyData::Dyn(_), &TyData::InferenceVar(var))
| (&TyData::Projection(_), &TyData::InferenceVar(var))
| (&TyData::ForAll(_), &TyData::InferenceVar(var)) => self.unify_var_ty(var, a),

// Unifying `forall<X> { T }` with some other forall type `forall<X> { U }`
Expand Down Expand Up @@ -179,7 +181,6 @@ impl<'t, TF: TypeFamily> Unifier<'t, TF> {
// Trait>::Item` with some other type `U`.
(&TyData::Apply(_), &TyData::Projection(ref proj))
| (&TyData::ForAll(_), &TyData::Projection(ref proj))
| (&TyData::InferenceVar(_), &TyData::Projection(ref proj))
| (&TyData::Dyn(_), &TyData::Projection(ref proj))
| (&TyData::Opaque(_), &TyData::Projection(ref proj)) => {
self.unify_projection_ty(proj, a)
Expand All @@ -188,7 +189,6 @@ impl<'t, TF: TypeFamily> Unifier<'t, TF> {
(&TyData::Projection(ref proj), &TyData::Projection(_))
| (&TyData::Projection(ref proj), &TyData::Apply(_))
| (&TyData::Projection(ref proj), &TyData::ForAll(_))
| (&TyData::Projection(ref proj), &TyData::InferenceVar(_))
| (&TyData::Projection(ref proj), &TyData::Dyn(_))
| (&TyData::Projection(ref proj), &TyData::Opaque(_)) => {
self.unify_projection_ty(proj, b)
Expand Down
2 changes: 1 addition & 1 deletion tests/test/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn futures_ambiguity() {
goal {
forall<T> { if (T: FutureResult) { exists<I, E> { T: Future<Output = Result<I, E>> } } }
} yields {
r"Unique; substitution [?0 := (FutureResult::Item)<!1_0>, ?1 := (FutureResult::Error)<!1_0>], lifetime constraints []"
r"Unique; substitution [?0 := <!1_0 as FutureResult>::Item, ?1 := <!1_0 as FutureResult>::Error], lifetime constraints []"
}
}
}
4 changes: 2 additions & 2 deletions tests/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ macro_rules! test {
]) => {
test!(@program[$program]
@parsed_goals[$($parsed_goals)*
$($((stringify!($goal), $C, $expected))+)+]
$($((stringify!($goal), $C, TestGoal::All(vec![$expected])))+)+]
@unparsed_goals[goal $($unparsed_goals)*])
};

Expand All @@ -125,7 +125,7 @@ macro_rules! test {
]) => {
test!(@program[$program]
@parsed_goals[$($parsed_goals)*
$($((stringify!($goal), $C, $expected))+)+]
$($((stringify!($goal), $C, TestGoal::All(vec![$expected])))+)+]
@unparsed_goals[])
};
}
Expand Down
49 changes: 49 additions & 0 deletions tests/test/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,3 +667,52 @@ fn gat_unify_with_implied_wc() {
}
}
}

#[test]
fn rust_analyzer_regression() {
test! {
program {
trait FnOnce<Args> {
type Output;
}

trait Try {
type Ok;
type Error;
}

struct Tuple<A, B> { }

trait ParallelIterator {
type Item;
}
}

//fn try_reduce_with<PI, R, T>(pi: PI, reduce_op: R) -> Option<T>
// where
// PI: ParallelIterator<Item = T>,
// R: FnOnce(T::Ok) -> T,
// T: Try,
// {
// pi.drive_unindexed()
// }
//
// where `drive_unindexed` is a method in `ParallelIterator`:
//
// fn drive_unindexed(self) -> ();

goal {
forall<PI, R, T> {
if (
PI: ParallelIterator<Item = T>;
R: FnOnce<Tuple< <T as Try>::Ok, <T as Try>::Ok >>;
T: Try
) {
PI: ParallelIterator
}
}
} yields[SolverChoice::SLG { max_size: 4 }] {
"substitution [], lifetime constraints []"
}
}
}