Skip to content

Commit e8f0a64

Browse files
committed
Make the type_of return a generic type for generators
1 parent 8549cfe commit e8f0a64

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

141141
let (yield_ty, return_ty) = if body.generator_kind.is_some() {
142-
let gen_sig = match ty.kind {
142+
let gen_ty = tcx.body_tables(body_id).node_type(id);
143+
let gen_sig = match gen_ty.kind {
143144
ty::Generator(_, gen_substs, ..) => gen_substs.as_generator().sig(),
144145
_ => span_bug!(tcx.hir().span(id), "generator w/o generator type: {:?}", ty),
145146
};

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)