Skip to content

Commit 9871e16

Browse files
Normalize possibly unnormalized type in relate_type_and_user_type
1 parent 2a339ce commit 9871e16

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
482482
}
483483
trace!(?curr_projected_ty);
484484

485+
// Need to renormalize `a` as typecheck may have failed to normalize
486+
// higher-ranked aliases if normalization was ambiguous due to inference.
487+
let a = self.normalize(a, locations);
485488
let ty = self.normalize(curr_projected_ty.ty, locations);
486489
self.relate_types(ty, v.xform(ty::Contravariant), a, locations, category)?;
487490

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//@ check-pass
2+
//@ revisions: current next
3+
//@ ignore-compare-mode-next-solver (explicit revisions)
4+
//@[next] compile-flags: -Znext-solver
5+
6+
// Regression test for <https://github.com/rust-lang/rust/issues/141708>.
7+
8+
// See description in there; this has to do with fundamental limitations
9+
// to the old trait solver surrounding higher-ranked aliases with infer
10+
// vars. This always worked in the new trait solver, but I added a revision
11+
// just for good measure.
12+
13+
trait Foo<'a> {
14+
type Assoc;
15+
}
16+
17+
impl Foo<'_> for i32 {
18+
type Assoc = u32;
19+
}
20+
21+
impl Foo<'_> for u32 {
22+
type Assoc = u32;
23+
}
24+
25+
fn foo<'b: 'b, T: for<'a> Foo<'a>, F: for<'a> Fn(<T as Foo<'a>>::Assoc)>(_: F) -> (T, F) {
26+
todo!()
27+
}
28+
29+
fn main() {
30+
let (x, c): (i32, _) = foo::<'static, _, _>(|_| {});
31+
}

0 commit comments

Comments
 (0)