]> git.lizzy.rs Git - rust.git/commitdiff
Make the `type_of` return a generic type for generators
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Tue, 14 Jan 2020 01:54:55 +0000 (02:54 +0100)
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Mon, 23 Mar 2020 16:57:47 +0000 (17:57 +0100)
src/librustc_mir_build/build/mod.rs
src/librustc_typeck/collect/type_of.rs

index d5daf465bb73da1dd9144635c094127a1d8230a3..a7ec4f501ae7672afc183eabd4af0fd6139f7c0a 100644 (file)
@@ -139,7 +139,8 @@ fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> BodyAndCache<'_> {
             let arguments = implicit_argument.into_iter().chain(explicit_arguments);
 
             let (yield_ty, return_ty) = if body.generator_kind.is_some() {
-                let gen_sig = match ty.kind {
+                let gen_ty = tcx.body_tables(body_id).node_type(id);
+                let gen_sig = match gen_ty.kind {
                     ty::Generator(_, gen_substs, ..) => gen_substs.as_generator().sig(),
                     _ => span_bug!(tcx.hir().span(id), "generator w/o generator type: {:?}", ty),
                 };
index 55642dfb4557b3f6c073180f0030809f86080861..675d003bff1f24b8889c3bc57634e4a3599b05c8 100644 (file)
@@ -188,12 +188,12 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
         Node::Field(field) => icx.to_ty(&field.ty),
 
         Node::Expr(&Expr { kind: ExprKind::Closure(.., gen), .. }) => {
-            if gen.is_some() {
-                return tcx.typeck_tables_of(def_id).node_type(hir_id);
-            }
-
             let substs = InternalSubsts::identity_for_item(tcx, def_id);
-            tcx.mk_closure(def_id, substs)
+            if let Some(movability) = gen {
+                tcx.mk_generator(def_id, substs, movability)
+            } else {
+                tcx.mk_closure(def_id, substs)
+            }
         }
 
         Node::AnonConst(_) => {