Skip to content

Commit 0df21b2

Browse files
committed
Make the type_of return a generic type for generators
1 parent 8498c5f commit 0df21b2

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/librustc_mir_build/build/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> BodyAndCache<'_> {
143143
let arguments = implicit_argument.into_iter().chain(explicit_arguments);
144144

145145
let (yield_ty, return_ty) = if body.generator_kind.is_some() {
146-
let gen_sig = match ty.kind {
146+
let gen_ty = tcx.body_tables(body_id).node_type(id);
147+
let gen_sig = match gen_ty.kind {
147148
ty::Generator(gen_def_id, gen_substs, ..) => {
148149
gen_substs.as_generator().sig(gen_def_id, tcx)
149150
}

src/librustc_typeck/collect.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1428,12 +1428,12 @@ fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
14281428
Node::Field(field) => icx.to_ty(&field.ty),
14291429

14301430
Node::Expr(&hir::Expr { kind: hir::ExprKind::Closure(.., gen), .. }) => {
1431-
if gen.is_some() {
1432-
return tcx.typeck_tables_of(def_id).node_type(hir_id);
1433-
}
1434-
14351431
let substs = InternalSubsts::identity_for_item(tcx, def_id);
1436-
tcx.mk_closure(def_id, substs)
1432+
if let Some(movability) = gen {
1433+
tcx.mk_generator(def_id, substs, movability)
1434+
} else {
1435+
tcx.mk_closure(def_id, substs)
1436+
}
14371437
}
14381438

14391439
Node::AnonConst(_) => {

0 commit comments

Comments
 (0)