From 850bcbdc2e18b3e80d7c12cfcc72a5a219ad3872 Mon Sep 17 00:00:00 2001
From: Michael Goulet <michael@errs.io>
Date: Tue, 13 Aug 2024 14:17:04 -0400
Subject: [PATCH] Test showing previous behavior

---
 .../build_correct_coerce.main.built.after.mir  | 18 ++++++++++++++++++
 tests/mir-opt/build_correct_coerce.rs          | 12 ++++++++++++
 2 files changed, 30 insertions(+)
 create mode 100644 tests/mir-opt/build_correct_coerce.main.built.after.mir
 create mode 100644 tests/mir-opt/build_correct_coerce.rs

diff --git a/tests/mir-opt/build_correct_coerce.main.built.after.mir b/tests/mir-opt/build_correct_coerce.main.built.after.mir
new file mode 100644
index 00000000000..10778bb605e
--- /dev/null
+++ b/tests/mir-opt/build_correct_coerce.main.built.after.mir
@@ -0,0 +1,18 @@
+// MIR for `main` after built
+
+fn main() -> () {
+    let mut _0: ();
+    let _1: for<'a> fn(&'a (), &'a ());
+    scope 1 {
+        debug x => _1;
+    }
+
+    bb0: {
+        StorageLive(_1);
+        _1 = foo as for<'a, 'b> fn(&'a (), &'b ()) (PointerCoercion(ReifyFnPointer));
+        FakeRead(ForLet(None), _1);
+        _0 = const ();
+        StorageDead(_1);
+        return;
+    }
+}
diff --git a/tests/mir-opt/build_correct_coerce.rs b/tests/mir-opt/build_correct_coerce.rs
new file mode 100644
index 00000000000..b6c861636dc
--- /dev/null
+++ b/tests/mir-opt/build_correct_coerce.rs
@@ -0,0 +1,12 @@
+// skip-filecheck
+
+// Validate that we record the target for the `as` coercion as `for<'a> fn(&'a (), &'a ())`,
+// and not `for<'a, 'b>(&'a (), &'b ())`. We previously did the latter due to a bug in
+// the code that records adjustments in HIR typeck.
+
+fn foo<'a, 'b>(_: &'a (), _: &'b ()) {}
+
+// EMIT_MIR build_correct_coerce.main.built.after.mir
+fn main() {
+    let x = foo as for<'a> fn(&'a (), &'a ());
+}