1
Fork 0

Error when generator trait is not found

This commit is contained in:
Lzu Tao 2019-08-26 17:51:52 +00:00
parent 9fa8f14023
commit fa7ea104b2
3 changed files with 25 additions and 2 deletions

View file

@ -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");

View file

@ -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() {}

View file

@ -0,0 +1,4 @@
error: requires `generator` lang_item
error: aborting due to previous error