Skip to content

Commit 24c1f4a

Browse files
Make sure to instantiate placeholders correctly in old solver
1 parent 1d8d7b1 commit 24c1f4a

File tree

4 files changed

+61
-4
lines changed

4 files changed

+61
-4
lines changed

compiler/rustc_infer/src/infer/canonical/query_response.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -483,17 +483,25 @@ impl<'tcx> InferCtxt<'tcx> {
483483
let result_subst = CanonicalVarValues {
484484
var_values: self.tcx.mk_args_from_iter(
485485
query_response.variables.iter().enumerate().map(|(index, info)| {
486-
if info.is_existential() {
486+
if info.universe() != ty::UniverseIndex::ROOT {
487+
// A variable from inside a binder of the query. While ideally these shouldn't
488+
// exist at all, we have to deal with them for now.
489+
self.instantiate_canonical_var(cause.span, info, |u| {
490+
universe_map[u.as_usize()]
491+
})
492+
} else if info.is_existential() {
487493
match opt_values[BoundVar::new(index)] {
488494
Some(k) => k,
489495
None => self.instantiate_canonical_var(cause.span, info, |u| {
490496
universe_map[u.as_usize()]
491497
}),
492498
}
493499
} else {
494-
self.instantiate_canonical_var(cause.span, info, |u| {
495-
universe_map[u.as_usize()]
496-
})
500+
// For placeholders which were already part of the input, we simply map this
501+
// universal bound variable back the placeholder of the input.
502+
opt_values[BoundVar::new(index)].expect(
503+
"expected placeholder to be unified with itself during response",
504+
)
497505
}
498506
}),
499507
),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/unifying-placeholders-in-query-response.rs:5:12
3+
|
4+
LL | #![feature(non_lifetime_binders)]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/unifying-placeholders-in-query-response.rs:5:12
3+
|
4+
LL | #![feature(non_lifetime_binders)]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// revisions: current next
2+
//[next] compile-flags: -Znext-solver
3+
// check-pass
4+
5+
#![feature(non_lifetime_binders)]
6+
//~^ WARN the feature `non_lifetime_binders` is incomplete
7+
8+
pub trait Foo<T: ?Sized> {
9+
type Bar<K: ?Sized>: ?Sized;
10+
}
11+
12+
impl Foo<usize> for () {
13+
type Bar<K: ?Sized> = K;
14+
}
15+
16+
pub fn f<T1, T2>(a: T1, b: T2)
17+
where
18+
T1: for<T> Foo<usize, Bar<T> = T>,
19+
T2: for<T> Foo<usize, Bar<T> = <T1 as Foo<usize>>::Bar<T>>,
20+
{
21+
}
22+
23+
fn it_works() {
24+
f((), ());
25+
}
26+
27+
fn main() {}

0 commit comments

Comments
 (0)