Skip to content

Commit

Permalink
Rollup merge of rust-lang#63917 - lzutao:langitem_gen_63912, r=centri…
Browse files Browse the repository at this point in the history
…l,cramert

Error when generator trait is not found

Closes rust-lang#63912
  • Loading branch information
Centril committed Aug 27, 2019
2 parents 0da7098 + fa7ea10 commit 23116ba
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
19 changes: 19 additions & 0 deletions src/test/ui/lang-item-missing-generator.rs
Original file line number Diff line number Diff line change
@@ -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() {}
4 changes: 4 additions & 0 deletions src/test/ui/lang-item-missing-generator.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
error: requires `generator` lang_item

error: aborting due to previous error

0 comments on commit 23116ba

Please sign in to comment.