Skip to content

Commit 58c2388

Browse files
committed
Make the type_of return a generic type for generators
1 parent 2602289 commit 58c2388

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

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

src/librustc_typeck/collect/type_of.rs

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

190190
Node::Expr(&Expr { kind: ExprKind::Closure(.., gen), .. }) => {
191-
if gen.is_some() {
192-
return tcx.typeck_tables_of(def_id).node_type(hir_id);
193-
}
194-
195191
let substs = InternalSubsts::identity_for_item(tcx, def_id);
196-
tcx.mk_closure(def_id, substs)
192+
if let Some(movability) = gen {
193+
tcx.mk_generator(def_id, substs, movability)
194+
} else {
195+
tcx.mk_closure(def_id, substs)
196+
}
197197
}
198198

199199
Node::AnonConst(_) => {

0 commit comments

Comments
 (0)