]> git.lizzy.rs Git - rust.git/commitdiff
Report an error if resolution of closure call functions failed
authorFabian Wolff <fabian.wolff@alumni.ethz.ch>
Sat, 12 Jun 2021 16:32:25 +0000 (18:32 +0200)
committerFabian Wolff <fabian.wolff@alumni.ethz.ch>
Sat, 12 Jun 2021 16:32:25 +0000 (18:32 +0200)
compiler/rustc_typeck/src/check/callee.rs
src/test/ui/lang-items/issue-86238.rs [new file with mode: 0644]
src/test/ui/lang-items/issue-86238.stderr [new file with mode: 0644]

index cb8f336721ad6a4d06c1c175e493e4575e803b32..9362daa3c889e1218291f46d39c6627bd08ef26d 100644 (file)
@@ -588,10 +588,17 @@ pub fn resolve(self, fcx: &FnCtxt<'a, 'tcx>) {
                 fcx.write_method_call(self.call_expr.hir_id, method_callee);
             }
             None => {
-                span_bug!(
+                // This can happen if `#![no_core]` is used and the `fn/fn_mut/fn_once`
+                // lang items are not defined (issue #86238).
+                let mut err = fcx.inh.tcx.sess.struct_span_err(
                     self.call_expr.span,
-                    "failed to find an overloaded call trait for closure call"
+                    "failed to find an overloaded call trait for closure call",
                 );
+                err.help(
+                    "make sure the `fn`/`fn_mut`/`fn_once` lang items are defined \
+                     and have an associated `call`/`call_mut`/`call_once` function",
+                );
+                err.emit();
             }
         }
     }
diff --git a/src/test/ui/lang-items/issue-86238.rs b/src/test/ui/lang-items/issue-86238.rs
new file mode 100644 (file)
index 0000000..509f94f
--- /dev/null
@@ -0,0 +1,16 @@
+// Regression test for the ICE described in issue #86238.
+
+#![feature(lang_items)]
+#![feature(no_core)]
+
+#![no_core]
+fn main() {
+    let one = || {};
+    one()
+    //~^ ERROR: failed to find an overloaded call trait for closure call
+    //~| HELP: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined
+}
+#[lang = "sized"]
+trait Sized {}
+#[lang = "copy"]
+trait Copy {}
diff --git a/src/test/ui/lang-items/issue-86238.stderr b/src/test/ui/lang-items/issue-86238.stderr
new file mode 100644 (file)
index 0000000..070f276
--- /dev/null
@@ -0,0 +1,10 @@
+error: failed to find an overloaded call trait for closure call
+  --> $DIR/issue-86238.rs:9:5
+   |
+LL |     one()
+   |     ^^^^^
+   |
+   = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have an associated `call`/`call_mut`/`call_once` function
+
+error: aborting due to previous error
+