-
Notifications
You must be signed in to change notification settings - Fork 13.4k
instantiate response: no unnecessary new universe #114934
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
73 changes: 73 additions & 0 deletions
73
tests/ui/traits/new-solver/generalize/generalize-proj-new-universe-index-1.rs
This file contains hidden or 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,73 @@ | ||
// compile-flags: -Ztrait-solver=next | ||
// check-pass | ||
|
||
// A minimization of an ambiguity when using typenum. See | ||
// https://github.com/rust-lang/trait-system-refactor-initiative/issues/55 | ||
// for more details. | ||
trait Id { | ||
type Assoc: ?Sized; | ||
} | ||
impl<T: ?Sized> Id for T { | ||
type Assoc = T; | ||
} | ||
|
||
trait WithAssoc<T: ?Sized> { | ||
type Assoc: ?Sized; | ||
} | ||
|
||
|
||
struct Leaf; | ||
struct Wrapper<U: ?Sized>(U); | ||
|
||
impl<U: ?Sized> WithAssoc<U> for Leaf { | ||
type Assoc = U; | ||
} | ||
|
||
impl<Ul: ?Sized, Ur: ?Sized> WithAssoc<Wrapper<Ur>> for Wrapper<Ul> | ||
where | ||
Ul: WithAssoc<Ur>, | ||
{ | ||
type Assoc = <<Ul as WithAssoc<Ur>>::Assoc as Id>::Assoc; | ||
} | ||
|
||
fn bound<T: ?Sized, U: ?Sized, V: ?Sized>() | ||
where | ||
T: WithAssoc<U, Assoc = V>, | ||
{ | ||
} | ||
|
||
// normalize self type to `Wrapper<Leaf>` | ||
// This succeeds, HOWEVER, instantiating the query response previously | ||
// incremented the universe index counter. | ||
// equate impl headers: | ||
// <Wrapper<Leaf> as WithAssoc<<Wrapper<Leaf> as Id>::Assoc>> | ||
// <Wrapper<?2t> as WithAssoc<Wrapper<?3t>>> | ||
// ~> AliasRelate(<Wrapper<Leaf> as Id>::Assoc, Equate, Wrapper<?3t>) | ||
// add where bounds: | ||
// ~> Leaf: WithAssoc<?3t> | ||
// equate with assoc type: | ||
// ?0t | ||
// <Leaf as WithAssoc<?3t>>::Assoc as Id>::Assoc | ||
// ~> AliasRelate( | ||
// <<Leaf as WithAssoc<?3t>>::Assoc as Id>::Assoc, | ||
// Equate, | ||
// <<Leaf as WithAssoc<?4t>>::Assoc as Id>::Assoc, | ||
// ) | ||
// | ||
// We do not reuse `?3t` during generalization because `?0t` cannot name `?4t` as we created | ||
// it after incrementing the universe index while normalizing the self type. | ||
// | ||
// evaluate_added_goals_and_make_query_response: | ||
// AliasRelate(<Wrapper<Leaf> as Id>::Assoc, Equate, Wrapper<?3t>) | ||
// YES, constrains ?3t to Leaf | ||
// AliasRelate( | ||
// <<Leaf as WithAssoc<Leaf>>::Assoc as Id>::Assoc, | ||
// Equate, | ||
// <<Leaf as WithAssoc<?4t>>::Assoc as Id>::Assoc, | ||
// ) | ||
// | ||
// Normalizing <<Leaf as WithAssoc<?4t>>::Assoc as Id>::Assoc then *correctly* | ||
// results in ambiguity. | ||
fn main() { | ||
bound::<<Wrapper<Leaf> as Id>::Assoc, <Wrapper<Leaf> as Id>::Assoc, _>() | ||
} |
75 changes: 75 additions & 0 deletions
75
tests/ui/traits/new-solver/generalize/generalize-proj-new-universe-index-2.rs
This file contains hidden or 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,75 @@ | ||
// compile-flags: -Ztrait-solver=next | ||
// known-bug: trait-system-refactor-initiative#60 | ||
|
||
// Generalizing a projection containing an inference variable | ||
// which cannot be named by the `root_vid` can result in ambiguity. | ||
// | ||
// Because we do not decrement the universe index when exiting a forall, | ||
// this can cause unexpected failures. | ||
// | ||
// See generalize-proj-new-universe-index-1.rs for more details. | ||
|
||
// For this reproduction we need: | ||
// - an inference variable with a lower universe | ||
// - enter a binder to increment the current universe | ||
// - create a new inference variable which is constrained by proving a goal | ||
// - equate a projection containing the new variable with the first variable | ||
// - generalization creates yet another inference variable which is then | ||
// part of an alias-relate, resulting this to fail with ambiguity. | ||
// | ||
// Because we need to enter the binder in-between the creation of the first | ||
// and second inference variable, this is easiest via | ||
// `assemble_candidates_after_normalizing_self_ty` because eagerly call | ||
// `try_evaluate_added_goals` there before creating the inference variables | ||
// for the impl parameters. | ||
trait Id { | ||
type Assoc: ?Sized; | ||
} | ||
impl<T: ?Sized> Id for T { | ||
type Assoc = T; | ||
} | ||
|
||
// By adding an higher ranked bound to the impl we currently | ||
// propagate this bound to the caller, forcing us to create a new | ||
// universe. | ||
trait IdHigherRankedBound { | ||
type Assoc: ?Sized; | ||
} | ||
|
||
impl<T: ?Sized> IdHigherRankedBound for T | ||
where | ||
for<'a> T: 'a, | ||
{ | ||
type Assoc = T; | ||
} | ||
|
||
trait WithAssoc<T: ?Sized> { | ||
type Assoc: ?Sized; | ||
} | ||
|
||
|
||
struct Leaf; | ||
struct Wrapper<U: ?Sized>(U); | ||
struct Rigid; | ||
|
||
impl<U: ?Sized> WithAssoc<U> for Leaf { | ||
type Assoc = U; | ||
} | ||
|
||
|
||
impl<Ur: ?Sized> WithAssoc<Wrapper<Ur>> for Rigid | ||
where | ||
Leaf: WithAssoc<Ur>, | ||
{ | ||
type Assoc = <<Leaf as WithAssoc<Ur>>::Assoc as Id>::Assoc; | ||
} | ||
|
||
fn bound<T: ?Sized, U: ?Sized, V: ?Sized>() | ||
where | ||
T: WithAssoc<U, Assoc = V>, | ||
{ | ||
} | ||
|
||
fn main() { | ||
bound::<<Rigid as IdHigherRankedBound>::Assoc, <Wrapper<Leaf> as Id>::Assoc, _>() | ||
} |
9 changes: 9 additions & 0 deletions
9
tests/ui/traits/new-solver/generalize/generalize-proj-new-universe-index-2.stderr
This file contains hidden or 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,9 @@ | ||
error[E0282]: type annotations needed | ||
--> $DIR/generalize-proj-new-universe-index-2.rs:74:5 | ||
| | ||
LL | bound::<<Rigid as IdHigherRankedBound>::Assoc, <Wrapper<Leaf> as Id>::Assoc, _>() | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `V` declared on the function `bound` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0282`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.