From 24c1f4aa802bc6b9c3710baa4464e691b5b13bb2 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 13 Jan 2024 22:57:44 +0000 Subject: [PATCH 1/2] Make sure to instantiate placeholders correctly in old solver --- .../src/infer/canonical/query_response.rs | 16 ++++++++--- ...ceholders-in-query-response.current.stderr | 11 ++++++++ ...placeholders-in-query-response.next.stderr | 11 ++++++++ ...unifying-placeholders-in-query-response.rs | 27 +++++++++++++++++++ 4 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 tests/ui/traits/non_lifetime_binders/unifying-placeholders-in-query-response.current.stderr create mode 100644 tests/ui/traits/non_lifetime_binders/unifying-placeholders-in-query-response.next.stderr create mode 100644 tests/ui/traits/non_lifetime_binders/unifying-placeholders-in-query-response.rs diff --git a/compiler/rustc_infer/src/infer/canonical/query_response.rs b/compiler/rustc_infer/src/infer/canonical/query_response.rs index 8cca4c6231fc2..1f071a9ff0bc3 100644 --- a/compiler/rustc_infer/src/infer/canonical/query_response.rs +++ b/compiler/rustc_infer/src/infer/canonical/query_response.rs @@ -483,7 +483,13 @@ impl<'tcx> InferCtxt<'tcx> { let result_subst = CanonicalVarValues { var_values: self.tcx.mk_args_from_iter( query_response.variables.iter().enumerate().map(|(index, info)| { - if info.is_existential() { + if info.universe() != ty::UniverseIndex::ROOT { + // A variable from inside a binder of the query. While ideally these shouldn't + // exist at all, we have to deal with them for now. + self.instantiate_canonical_var(cause.span, info, |u| { + universe_map[u.as_usize()] + }) + } else if info.is_existential() { match opt_values[BoundVar::new(index)] { Some(k) => k, None => self.instantiate_canonical_var(cause.span, info, |u| { @@ -491,9 +497,11 @@ impl<'tcx> InferCtxt<'tcx> { }), } } else { - self.instantiate_canonical_var(cause.span, info, |u| { - universe_map[u.as_usize()] - }) + // For placeholders which were already part of the input, we simply map this + // universal bound variable back the placeholder of the input. + opt_values[BoundVar::new(index)].expect( + "expected placeholder to be unified with itself during response", + ) } }), ), diff --git a/tests/ui/traits/non_lifetime_binders/unifying-placeholders-in-query-response.current.stderr b/tests/ui/traits/non_lifetime_binders/unifying-placeholders-in-query-response.current.stderr new file mode 100644 index 0000000000000..040009efbde2e --- /dev/null +++ b/tests/ui/traits/non_lifetime_binders/unifying-placeholders-in-query-response.current.stderr @@ -0,0 +1,11 @@ +warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/unifying-placeholders-in-query-response.rs:5:12 + | +LL | #![feature(non_lifetime_binders)] + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #108185 for more information + = note: `#[warn(incomplete_features)]` on by default + +warning: 1 warning emitted + diff --git a/tests/ui/traits/non_lifetime_binders/unifying-placeholders-in-query-response.next.stderr b/tests/ui/traits/non_lifetime_binders/unifying-placeholders-in-query-response.next.stderr new file mode 100644 index 0000000000000..040009efbde2e --- /dev/null +++ b/tests/ui/traits/non_lifetime_binders/unifying-placeholders-in-query-response.next.stderr @@ -0,0 +1,11 @@ +warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/unifying-placeholders-in-query-response.rs:5:12 + | +LL | #![feature(non_lifetime_binders)] + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #108185 for more information + = note: `#[warn(incomplete_features)]` on by default + +warning: 1 warning emitted + diff --git a/tests/ui/traits/non_lifetime_binders/unifying-placeholders-in-query-response.rs b/tests/ui/traits/non_lifetime_binders/unifying-placeholders-in-query-response.rs new file mode 100644 index 0000000000000..5e28a2ba8b9b8 --- /dev/null +++ b/tests/ui/traits/non_lifetime_binders/unifying-placeholders-in-query-response.rs @@ -0,0 +1,27 @@ +// revisions: current next +//[next] compile-flags: -Znext-solver +// check-pass + +#![feature(non_lifetime_binders)] +//~^ WARN the feature `non_lifetime_binders` is incomplete + +pub trait Foo { + type Bar: ?Sized; +} + +impl Foo for () { + type Bar = K; +} + +pub fn f(a: T1, b: T2) +where + T1: for Foo = T>, + T2: for Foo = >::Bar>, +{ +} + +fn it_works() { + f((), ()); +} + +fn main() {} From 985e1e031b0d9d7c54812931c2beb57b0d304a94 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 13 Jan 2024 23:08:22 +0000 Subject: [PATCH 2/2] Add a simpler test --- ...holders-in-query-response-2.current.stderr | 11 +++++++++ ...aceholders-in-query-response-2.next.stderr | 11 +++++++++ ...ifying-placeholders-in-query-response-2.rs | 23 +++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 tests/ui/traits/non_lifetime_binders/unifying-placeholders-in-query-response-2.current.stderr create mode 100644 tests/ui/traits/non_lifetime_binders/unifying-placeholders-in-query-response-2.next.stderr create mode 100644 tests/ui/traits/non_lifetime_binders/unifying-placeholders-in-query-response-2.rs diff --git a/tests/ui/traits/non_lifetime_binders/unifying-placeholders-in-query-response-2.current.stderr b/tests/ui/traits/non_lifetime_binders/unifying-placeholders-in-query-response-2.current.stderr new file mode 100644 index 0000000000000..4082d6d47e79a --- /dev/null +++ b/tests/ui/traits/non_lifetime_binders/unifying-placeholders-in-query-response-2.current.stderr @@ -0,0 +1,11 @@ +warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/unifying-placeholders-in-query-response-2.rs:5:12 + | +LL | #![feature(non_lifetime_binders)] + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #108185 for more information + = note: `#[warn(incomplete_features)]` on by default + +warning: 1 warning emitted + diff --git a/tests/ui/traits/non_lifetime_binders/unifying-placeholders-in-query-response-2.next.stderr b/tests/ui/traits/non_lifetime_binders/unifying-placeholders-in-query-response-2.next.stderr new file mode 100644 index 0000000000000..4082d6d47e79a --- /dev/null +++ b/tests/ui/traits/non_lifetime_binders/unifying-placeholders-in-query-response-2.next.stderr @@ -0,0 +1,11 @@ +warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/unifying-placeholders-in-query-response-2.rs:5:12 + | +LL | #![feature(non_lifetime_binders)] + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #108185 for more information + = note: `#[warn(incomplete_features)]` on by default + +warning: 1 warning emitted + diff --git a/tests/ui/traits/non_lifetime_binders/unifying-placeholders-in-query-response-2.rs b/tests/ui/traits/non_lifetime_binders/unifying-placeholders-in-query-response-2.rs new file mode 100644 index 0000000000000..bbf1a1f72db6c --- /dev/null +++ b/tests/ui/traits/non_lifetime_binders/unifying-placeholders-in-query-response-2.rs @@ -0,0 +1,23 @@ +// revisions: current next +//[next] compile-flags: -Znext-solver +// check-pass + +#![feature(non_lifetime_binders)] +//~^ WARN the feature `non_lifetime_binders` is incomplete + +trait Id { + type Output: ?Sized; +} + +impl Id for T { + type Output = T; +} + +trait Everyone {} +impl Everyone for T {} + +fn hello() where for ::Output: Everyone {} + +fn main() { + hello(); +}