From 9a7bb0ef249258aacf144d04f5d437ba70533128 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 18 Oct 2018 15:48:48 -0400 Subject: [PATCH] normalize the self-type that we extract from impl --- .../borrow_check/nll/type_check/mod.rs | 1 + .../nll/user-annotations/normalize-self-ty.rs | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/test/ui/nll/user-annotations/normalize-self-ty.rs diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index 6783083c9584..7737fcc765d8 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -1019,6 +1019,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { { let impl_self_ty = tcx.type_of(impl_def_id); let impl_self_ty = impl_self_ty.subst(tcx, &substs); + let impl_self_ty = self.normalize(impl_self_ty, locations); // There may be type variables in `substs` and hence // in `impl_self_ty`, but they should all have been diff --git a/src/test/ui/nll/user-annotations/normalize-self-ty.rs b/src/test/ui/nll/user-annotations/normalize-self-ty.rs new file mode 100644 index 000000000000..d97cc88dd9af --- /dev/null +++ b/src/test/ui/nll/user-annotations/normalize-self-ty.rs @@ -0,0 +1,25 @@ +// Regression test for #55183: check a case where the self type from +// the inherent impl requires normalization to be equal to the +// user-provided type. +// +// run-pass + +#![feature(nll)] + +trait Mirror { + type Me; +} + +impl Mirror for T { + type Me = T; +} + +struct Foo(A, B); + +impl Foo::Me> { + fn m(b: A) { } +} + +fn main() { + >::m(&22); +}