Skip to content

Commit 7892cc3

Browse files
Do not depend on Generator trait when deducing closure signature
1 parent 001a77f commit 7892cc3

File tree

3 files changed

+10
-46
lines changed

3 files changed

+10
-46
lines changed

compiler/rustc_hir_typeck/src/closure.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_middle::ty::visit::TypeVisitable;
1515
use rustc_middle::ty::{self, Ty, TypeSuperVisitable, TypeVisitor};
1616
use rustc_span::def_id::LocalDefId;
1717
use rustc_span::source_map::Span;
18+
use rustc_span::sym;
1819
use rustc_target::spec::abi::Abi;
1920
use rustc_trait_selection::traits;
2021
use rustc_trait_selection::traits::error_reporting::ArgKind;
@@ -288,21 +289,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
288289
let trait_def_id = projection.trait_def_id(tcx);
289290

290291
let is_fn = tcx.is_fn_trait(trait_def_id);
291-
let gen_trait = tcx.require_lang_item(LangItem::Generator, cause_span);
292-
let is_gen = gen_trait == trait_def_id;
292+
293+
let gen_trait = tcx.lang_items().gen_trait();
294+
let is_gen = gen_trait == Some(trait_def_id);
295+
293296
if !is_fn && !is_gen {
294297
debug!("not fn or generator");
295298
return None;
296299
}
297300

298-
if is_gen {
299-
// Check that we deduce the signature from the `<_ as std::ops::Generator>::Return`
300-
// associated item and not yield.
301-
let return_assoc_item = self.tcx.associated_item_def_ids(gen_trait)[1];
302-
if return_assoc_item != projection.projection_def_id() {
303-
debug!("not return assoc item of generator");
304-
return None;
305-
}
301+
// Check that we deduce the signature from the `<_ as std::ops::Generator>::Return`
302+
// associated item and not yield.
303+
if is_gen && self.tcx.associated_item(projection.projection_def_id()).name != sym::Return {
304+
debug!("not `Return` assoc item of `Generator`");
305+
return None;
306306
}
307307

308308
let input_tys = if is_fn {

tests/ui/lang-items/lang-item-missing-generator.rs

-21
This file was deleted.

tests/ui/lang-items/lang-item-missing-generator.stderr

-15
This file was deleted.

0 commit comments

Comments
 (0)