Skip to content

Commit 376aced

Browse files
committed
Make the type_of return a generic type for generators
1 parent 333c32a commit 376aced

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
@@ -133,7 +133,8 @@ fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> BodyAndCache<'_> {
133133
let arguments = implicit_argument.into_iter().chain(explicit_arguments);
134134

135135
let (yield_ty, return_ty) = if body.generator_kind.is_some() {
136-
let gen_sig = match ty.kind {
136+
let gen_ty = tcx.body_tables(body_id).node_type(id);
137+
let gen_sig = match gen_ty.kind {
137138
ty::Generator(gen_def_id, gen_substs, ..) => {
138139
gen_substs.as_generator().sig(gen_def_id, tcx)
139140
}

src/librustc_typeck/collect.rs

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

14281428
Node::Expr(&hir::Expr { kind: hir::ExprKind::Closure(.., gen), .. }) => {
1429-
if gen.is_some() {
1430-
return tcx.typeck_tables_of(def_id).node_type(hir_id);
1431-
}
1432-
14331429
let substs = InternalSubsts::identity_for_item(tcx, def_id);
1434-
tcx.mk_closure(def_id, substs)
1430+
if let Some(movability) = gen {
1431+
tcx.mk_generator(def_id, substs, movability)
1432+
} else {
1433+
tcx.mk_closure(def_id, substs)
1434+
}
14351435
}
14361436

14371437
Node::AnonConst(_) => {

0 commit comments

Comments
 (0)