-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generalize hr alias: avoid unconstrainable infer vars
- Loading branch information
Showing
7 changed files
with
175 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
tests/ui/traits/next-solver/generalize/hr-alias-non-hr-alias-self-ty-1.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//@ revisions: old next | ||
//@[next] compile-flags: -Znext-solver | ||
//@ ignore-compare-mode-next-solver (explicit revisions) | ||
//@ check-pass | ||
|
||
// Generalizing an alias referencing escaping bound variables | ||
// is hard. We previously didn't replace this alias with inference | ||
// variables but did replace nested alias which do not reference | ||
// any bound variables. This caused us to stall with the following | ||
// goal, which cannot make any progress: | ||
// | ||
// <<T as Id>::Refl as HigherRanked>::Output<'a> | ||
// alias-relate | ||
// <?unconstrained as HigherRanked>::Output<'a> | ||
// | ||
// | ||
// cc trait-system-refactor-initiative#110 | ||
|
||
#![allow(unused)] | ||
trait HigherRanked { | ||
type Output<'a>; | ||
} | ||
trait Id { | ||
type Refl: HigherRanked; | ||
} | ||
|
||
fn foo<T: Id>() -> for<'a> fn(<<T as Id>::Refl as HigherRanked>::Output<'a>) { | ||
todo!() | ||
} | ||
|
||
fn bar<T: Id>() { | ||
// we generalize here | ||
let x = foo::<T>(); | ||
} | ||
|
||
fn main() {} |
32 changes: 32 additions & 0 deletions
32
tests/ui/traits/next-solver/generalize/hr-alias-non-hr-alias-self-ty-2.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//@ revisions: old next | ||
//@[next] compile-flags: -Znext-solver | ||
//@ ignore-compare-mode-next-solver (explicit revisions) | ||
//@ check-pass | ||
|
||
// A minimization of an ambiguity error in `icu_provider`. | ||
// | ||
// cc trait-system-refactor-initiative#110 | ||
|
||
trait Yokeable<'a> { | ||
type Output; | ||
} | ||
trait Id { | ||
type Refl; | ||
} | ||
|
||
fn into_deserialized<M: Id>() -> M | ||
where | ||
M::Refl: for<'a> Yokeable<'a>, | ||
{ | ||
try_map_project::<M, _>(|_| todo!()) | ||
} | ||
|
||
fn try_map_project<M: Id, F>(_f: F) -> M | ||
where | ||
M::Refl: for<'a> Yokeable<'a>, | ||
F: for<'a> FnOnce(&'a ()) -> <<M as Id>::Refl as Yokeable<'a>>::Output, | ||
{ | ||
todo!() | ||
} | ||
|
||
fn main() {} |
51 changes: 51 additions & 0 deletions
51
tests/ui/traits/next-solver/generalize/hr-alias-universe-lowering-ambiguity.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//@ compile-flags: -Znext-solver | ||
//@ check-pass | ||
|
||
// A regression test for a fairly subtle issue with how we | ||
// generalize aliases referencing higher-ranked regions | ||
// which previously caused unexpected ambiguity errors. | ||
// | ||
// The explanations in the test may end up being out of date | ||
// in the future as we may refine our approach to generalization | ||
// going forward. | ||
// | ||
// cc trait-system-refactor-initiative#108 | ||
trait Trait<'a> { | ||
type Assoc; | ||
} | ||
|
||
impl<'a> Trait<'a> for () { | ||
type Assoc = (); | ||
} | ||
|
||
fn foo<T: for<'a> Trait<'a>>(x: T) -> for<'a> fn(<T as Trait<'a>>::Assoc) { | ||
|_| () | ||
} | ||
|
||
fn unconstrained<T>() -> T { | ||
todo!() | ||
} | ||
|
||
fn main() { | ||
// create `?x.0` in the root universe | ||
let mut x = unconstrained(); | ||
|
||
// bump the current universe of the inference context | ||
let bump: for<'a, 'b> fn(&'a (), &'b ()) = |_, _| (); | ||
let _: for<'a> fn(&'a (), &'a ()) = bump; | ||
|
||
// create `?y.1` in a higher universe | ||
let mut y = Default::default(); | ||
|
||
// relate `?x.0` with `for<'a> fn(<?y.1 as Trait<'a>>::Assoc)` | ||
// -> instantiate `?x.0` with `for<'a> fn(<?y_new.0 as Trait<'a>>::Assoc)` | ||
x = foo(y); | ||
|
||
// Constrain `?y.1` to `()` | ||
let _: () = y; | ||
|
||
// `AliasRelate(<?y_new.0 as Trait<'a>>::Assoc, <() as Trait<'a>>::Assoc)` | ||
// remains ambiguous unless we somehow constrain `?y_new.0` during | ||
// generalization to be equal to `?y.1`, which is exactly what we | ||
// did to fix this issue. | ||
} |
1 change: 1 addition & 0 deletions
1
tests/ui/traits/next-solver/generalize/occurs-check-nested-alias.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters