about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-09-23 01:21:25 +0000
committerbors <bors@rust-lang.org>2022-09-23 01:21:25 +0000
commit9279c547c79ac840d4dd9cc40cc4e0219aabf2d4 (patch)
tree97b5f0daf757112737481c53c6944ee4cf407a4f
parente7119a0300b87a3d670408ee8e847c6821b3ae80 (diff)
parent2db0492e6264d22629ed75b60f8c0dcebc451966 (diff)
downloadrust-9279c547c79ac840d4dd9cc40cc4e0219aabf2d4.tar.gz
rust-9279c547c79ac840d4dd9cc40cc4e0219aabf2d4.zip
Auto merge of #101708 - compiler-errors:issue-101696, r=jackh726
Normalize closure signature after construction

Astconv can't normalize inputs or outputs with escaping bound vars ([see this](https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_typeck/check/fn_ctxt/mod.rs.html#294)), so normalize them after we've wrapped them in a binder.

Fixes #101696
-rw-r--r--compiler/rustc_typeck/src/check/closure.rs3
-rw-r--r--src/test/ui/closures/issue-101696.rs36
2 files changed, 39 insertions, 0 deletions
diff --git a/compiler/rustc_typeck/src/check/closure.rs b/compiler/rustc_typeck/src/check/closure.rs
index a13d73c471b..84ea06a460b 100644
--- a/compiler/rustc_typeck/src/check/closure.rs
+++ b/compiler/rustc_typeck/src/check/closure.rs
@@ -641,6 +641,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
             ),
             bound_vars,
         );
+        // Astconv can't normalize inputs or outputs with escaping bound vars,
+        // so normalize them here, after we've wrapped them in a binder.
+        let result = self.normalize_associated_types_in(self.tcx.hir().span(hir_id), result);
 
         let c_result = self.inh.infcx.canonicalize_response(result);
         self.typeck_results.borrow_mut().user_provided_sigs.insert(expr_def_id, c_result);
diff --git a/src/test/ui/closures/issue-101696.rs b/src/test/ui/closures/issue-101696.rs
new file mode 100644
index 00000000000..0a358bd1643
--- /dev/null
+++ b/src/test/ui/closures/issue-101696.rs
@@ -0,0 +1,36 @@
+// check-pass
+
+use std::marker::PhantomData;
+
+#[derive(Default)]
+struct MyType<'a> {
+    field: usize,
+    _phantom: PhantomData<&'a ()>,
+}
+
+#[derive(Default)]
+struct MyTypeVariant<'a> {
+    field: usize,
+    _phantom: PhantomData<&'a ()>,
+}
+
+trait AsVariantTrait {
+    type Type;
+}
+
+impl<'a> AsVariantTrait for MyType<'a> {
+    type Type = MyTypeVariant<'a>;
+}
+
+type Variant<G> = <G as AsVariantTrait>::Type;
+
+fn foo<T: Default, F: FnOnce(T)>(f: F) {
+    let input = T::default();
+    f(input);
+}
+
+fn main() {
+    foo(|a: <MyType as AsVariantTrait>::Type| {
+        a.field;
+    });
+}