about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorLzu Tao <taolzu@gmail.com>2019-08-26 17:51:52 +0000
committerLzu Tao <taolzu@gmail.com>2019-08-26 17:51:52 +0000
commitfa7ea104b232fbc2b72f7717393181e849d39dfe (patch)
tree5c5b85c77a0b5f17c60fbbfe18a0b2ac510b285a /src
parent9fa8f140233047fb0211dbaee531a290bcfeae7e (diff)
downloadrust-fa7ea104b232fbc2b72f7717393181e849d39dfe.tar.gz
rust-fa7ea104b232fbc2b72f7717393181e849d39dfe.zip
Error when generator trait is not found
Diffstat (limited to 'src')
-rw-r--r--src/librustc_typeck/check/closure.rs4
-rw-r--r--src/test/ui/lang-item-missing-generator.rs19
-rw-r--r--src/test/ui/lang-item-missing-generator.stderr4
3 files changed, 25 insertions, 2 deletions
diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs
index d2f2f89cf0b..06b1e7bfd4e 100644
--- a/src/librustc_typeck/check/closure.rs
+++ b/src/librustc_typeck/check/closure.rs
@@ -3,7 +3,7 @@
 use super::{check_fn, Expectation, FnCtxt, GeneratorTypes};
 
 use crate::astconv::AstConv;
-use crate::middle::region;
+use crate::middle::{lang_items, region};
 use rustc::hir::def_id::DefId;
 use rustc::infer::{InferOk, InferResult};
 use rustc::infer::LateBoundRegionConversionTime;
@@ -266,7 +266,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         let trait_ref = projection.to_poly_trait_ref(tcx);
 
         let is_fn = tcx.lang_items().fn_trait_kind(trait_ref.def_id()).is_some();
-        let gen_trait = tcx.lang_items().gen_trait().unwrap();
+        let gen_trait = tcx.require_lang_item(lang_items::GeneratorTraitLangItem);
         let is_gen = gen_trait == trait_ref.def_id();
         if !is_fn && !is_gen {
             debug!("deduce_sig_from_projection: not fn or generator");
diff --git a/src/test/ui/lang-item-missing-generator.rs b/src/test/ui/lang-item-missing-generator.rs
new file mode 100644
index 00000000000..0c329542928
--- /dev/null
+++ b/src/test/ui/lang-item-missing-generator.rs
@@ -0,0 +1,19 @@
+// error-pattern: requires `generator` lang_item
+#![feature(no_core, lang_items, unboxed_closures)]
+#![no_core]
+
+#[lang = "sized"] pub trait Sized { }
+
+#[lang = "fn_once"]
+#[rustc_paren_sugar]
+pub trait FnOnce<Args> {
+    type Output;
+
+    extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
+}
+
+pub fn abc() -> impl FnOnce(f32) {
+    |_| {}
+}
+
+fn main() {}
diff --git a/src/test/ui/lang-item-missing-generator.stderr b/src/test/ui/lang-item-missing-generator.stderr
new file mode 100644
index 00000000000..d0cc4b81be6
--- /dev/null
+++ b/src/test/ui/lang-item-missing-generator.stderr
@@ -0,0 +1,4 @@
+error: requires `generator` lang_item
+
+error: aborting due to previous error
+