-
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.
Rollup merge of #108839 - compiler-errors:canonicalize-the-root-var, …
…r=lcnr Canonicalize root var when making response from new solver During trait solving, if we equate two inference variables `?0` and `?1` but don't equate them with any rigid types, then `InferCtxt::probe_ty_var` will return `Err` for both of these. The canonicalizer code will then canonicalize the variables independently(!), and the response will not reflect the fact that these two variables have been made equal. This hinders inference and I also don't think it's sound? I haven't thought too much about it past that, so let's talk about it. r? ``@lcnr``
- Loading branch information
Showing
6 changed files
with
104 additions
and
15 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
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
39 changes: 39 additions & 0 deletions
39
tests/ui/traits/new-solver/canonical-ty-var-eq-in-response.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,39 @@ | ||
// check-pass | ||
// compile-flags: -Ztrait-solver=next | ||
|
||
trait Mirror { | ||
type Item; | ||
} | ||
|
||
struct Wrapper<T>(T); | ||
impl<T> Mirror for Wrapper<T> { | ||
type Item = T; | ||
} | ||
|
||
fn mirror<T>() | ||
where | ||
Wrapper<T>: Mirror<Item = i32>, | ||
{ | ||
} | ||
|
||
fn main() { | ||
mirror::<_ /* ?0 */>(); | ||
|
||
// Solving `<Wrapper<?0> as Mirror>::Item = i32` | ||
|
||
// First, we replace the term with a fresh infer var: | ||
// `<Wrapper<?0> as Mirror>::Item = ?1` | ||
|
||
// We select the impl candidate on line #6, which leads us to learn that | ||
// `?0 == ?1`. | ||
|
||
// That should be reflected in our canonical response, which should have | ||
// `^0 = ^0, ^1 = ^0` | ||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
// !! We used to return a totally unconstrained response here :< !! | ||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
||
// Then, during the "equate term" part of the projection solving, we | ||
// instantiate the response from the unconstrained projection predicate, | ||
// and equate `?0 == i32`. | ||
} |
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,6 @@ | ||
// check-pass | ||
// compile-flags: -Ztrait-solver=next | ||
|
||
fn main() { | ||
let x: Box<dyn Iterator<Item = ()>> = Box::new(std::iter::empty()); | ||
} |