]> git.lizzy.rs Git - rust.git/commitdiff
Erase regions before uninhabited check
authorMichael Goulet <michael@errs.io>
Tue, 31 Jan 2023 20:43:18 +0000 (20:43 +0000)
committerMichael Goulet <michael@errs.io>
Wed, 1 Feb 2023 01:14:34 +0000 (01:14 +0000)
compiler/rustc_borrowck/src/type_check/mod.rs
tests/ui/uninhabited/issue-107505.rs [new file with mode: 0644]

index 06087b0c579d8c293349d82e0e847fb5a2b50da5..0a78bc0030be4ce26d758722e62eba65d3ac3315 100644 (file)
@@ -1484,7 +1484,10 @@ fn check_call_dest(
                 }
             }
             None => {
-                if !sig.output().is_privately_uninhabited(self.tcx(), self.param_env) {
+                // The signature in this call can reference region variables,
+                // so erase them before calling a query.
+                let output_ty = self.tcx().erase_regions(sig.output());
+                if !output_ty.is_privately_uninhabited(self.tcx(), self.param_env) {
                     span_mirbug!(self, term, "call to converging function {:?} w/o dest", sig);
                 }
             }
diff --git a/tests/ui/uninhabited/issue-107505.rs b/tests/ui/uninhabited/issue-107505.rs
new file mode 100644 (file)
index 0000000..6159854
--- /dev/null
@@ -0,0 +1,18 @@
+// compile-flags: --crate-type=lib
+// check-pass
+
+// Make sure we don't pass inference variables to uninhabitedness checks in borrowck
+
+struct Command<'s> {
+    session: &'s (),
+    imp: std::convert::Infallible,
+}
+
+fn command(_: &()) -> Command<'_> {
+    unreachable!()
+}
+
+fn with_session<'s>(a: &std::process::Command, b: &'s ()) -> Command<'s> {
+    a.get_program();
+    command(b)
+}