]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_middle/src/ty/print/pretty.rs
pretty.rs: Update Closure and Generator print
[rust.git] / compiler / rustc_middle / src / ty / print / pretty.rs
index cfc4b062885b8e864378397c8d05c005efff5c09..7b5cf681f38fb60efde2996f0eca594d81707319 100644 (file)
@@ -641,42 +641,35 @@ fn pretty_print_type(mut self, ty: Ty<'tcx>) -> Result<Self::Type, Self::Error>
             }
             ty::Str => p!(write("str")),
             ty::Generator(did, substs, movability) => {
+                p!(write("["));
                 match movability {
-                    hir::Movability::Movable => p!(write("[generator")),
-                    hir::Movability::Static => p!(write("[static generator")),
+                    hir::Movability::Movable => {}
+                    hir::Movability::Static => p!(write("static ")),
                 }
 
-                // FIXME(eddyb) should use `def_span`.
-                if let Some(did) = did.as_local() {
-                    let hir_id = self.tcx().hir().local_def_id_to_hir_id(did);
-                    let span = self.tcx().hir().span(hir_id);
-                    p!(write("@{}", self.tcx().sess.source_map().span_to_string(span)));
-
-                    if substs.as_generator().is_valid() {
-                        let upvar_tys = substs.as_generator().upvar_tys();
-                        let mut sep = " ";
-                        for (&var_id, upvar_ty) in self
-                            .tcx()
-                            .upvars_mentioned(did)
-                            .as_ref()
-                            .iter()
-                            .flat_map(|v| v.keys())
-                            .zip(upvar_tys)
-                        {
-                            p!(write("{}{}:", sep, self.tcx().hir().name(var_id)), print(upvar_ty));
-                            sep = ", ";
-                        }
+                if !self.tcx().sess.verbose() {
+                    p!(write("generator"));
+                    // FIXME(eddyb) should use `def_span`.
+                    if let Some(did) = did.as_local() {
+                        let hir_id = self.tcx().hir().local_def_id_to_hir_id(did);
+                        let span = self.tcx().hir().span(hir_id);
+                        p!(write("@{}", self.tcx().sess.source_map().span_to_string(span)));
+                    } else {
+                        p!(write("@{}", self.tcx().def_path_str(did)));
                     }
                 } else {
-                    p!(write("@{}", self.tcx().def_path_str(did)));
-
+                    p!(print_def_path(did, substs));
                     if substs.as_generator().is_valid() {
-                        let upvar_tys = substs.as_generator().upvar_tys();
-                        let mut sep = " ";
-                        for (index, upvar_ty) in upvar_tys.enumerate() {
-                            p!(write("{}{}:", sep, index), print(upvar_ty));
-                            sep = ", ";
+                        // Search for the first inference variable
+                        p!(write(" upvar_tys=("));
+                        let mut uninferred_ty =
+                            substs.as_generator().upvar_tys().filter(|ty| ty.is_ty_infer());
+                        if uninferred_ty.next().is_some() {
+                            p!(write("unavailable"));
+                        } else {
+                            self = self.comma_sep(substs.as_generator().upvar_tys())?;
                         }
+                        p!(write(")"));
                     }
                 }
 
@@ -684,61 +677,50 @@ fn pretty_print_type(mut self, ty: Ty<'tcx>) -> Result<Self::Type, Self::Error>
                     p!(write(" "), print(substs.as_generator().witness()));
                 }
 
-                p!(write("]"))
+                p!(write("]"));
             }
             ty::GeneratorWitness(types) => {
                 p!(in_binder(&types));
             }
             ty::Closure(did, substs) => {
-                p!(write("[closure"));
-
-                // FIXME(eddyb) should use `def_span`.
-                if let Some(did) = did.as_local() {
-                    let hir_id = self.tcx().hir().local_def_id_to_hir_id(did);
-                    if self.tcx().sess.opts.debugging_opts.span_free_formats {
-                        p!(write("@"), print_def_path(did.to_def_id(), substs));
-                    } else {
-                        let span = self.tcx().hir().span(hir_id);
-                        p!(write("@{}", self.tcx().sess.source_map().span_to_string(span)));
-                    }
-
-                    if substs.as_closure().is_valid() {
-                        let upvar_tys = substs.as_closure().upvar_tys();
-                        let mut sep = " ";
-                        for (&var_id, upvar_ty) in self
-                            .tcx()
-                            .upvars_mentioned(did)
-                            .as_ref()
-                            .iter()
-                            .flat_map(|v| v.keys())
-                            .zip(upvar_tys)
-                        {
-                            p!(write("{}{}:", sep, self.tcx().hir().name(var_id)), print(upvar_ty));
-                            sep = ", ";
+                p!(write("["));
+                if !self.tcx().sess.verbose() {
+                    p!(write("closure"));
+                    // FIXME(eddyb) should use `def_span`.
+                    if let Some(did) = did.as_local() {
+                        let hir_id = self.tcx().hir().local_def_id_to_hir_id(did);
+                        if self.tcx().sess.opts.debugging_opts.span_free_formats {
+                            p!(write("@"), print_def_path(did.to_def_id(), substs));
+                        } else {
+                            let span = self.tcx().hir().span(hir_id);
+                            p!(write("@{}", self.tcx().sess.source_map().span_to_string(span)));
                         }
+                    } else {
+                        p!(write("@{}", self.tcx().def_path_str(did)));
                     }
                 } else {
-                    p!(write("@{}", self.tcx().def_path_str(did)));
-
+                    p!(print_def_path(did, substs));
                     if substs.as_closure().is_valid() {
-                        let upvar_tys = substs.as_closure().upvar_tys();
-                        let mut sep = " ";
-                        for (index, upvar_ty) in upvar_tys.enumerate() {
-                            p!(write("{}{}:", sep, index), print(upvar_ty));
-                            sep = ", ";
+                        // Search for the first inference variable
+                        let mut uninferred_ty =
+                            substs.as_closure().upvar_tys().filter(|ty| ty.is_ty_infer());
+                        if uninferred_ty.next().is_some() {
+                            // If the upvar substs contain an inference variable we haven't
+                            // finished capture analysis.
+                            p!(write(" closure_substs=(unavailable)"));
+                        } else {
+                            p!(write(" closure_kind_ty="), print(substs.as_closure().kind_ty()));
+                            p!(
+                                write(" closure_sig_as_fn_ptr_ty="),
+                                print(substs.as_closure().sig_as_fn_ptr_ty())
+                            );
+                            p!(write(" upvar_tys=("));
+                            self = self.comma_sep(substs.as_closure().upvar_tys())?;
+                            p!(write(")"));
                         }
                     }
                 }
-
-                if self.tcx().sess.verbose() && substs.as_closure().is_valid() {
-                    p!(write(" closure_kind_ty="), print(substs.as_closure().kind_ty()));
-                    p!(
-                        write(" closure_sig_as_fn_ptr_ty="),
-                        print(substs.as_closure().sig_as_fn_ptr_ty())
-                    );
-                }
-
-                p!(write("]"))
+                p!(write("]"));
             }
             ty::Array(ty, sz) => {
                 p!(write("["), print(ty), write("; "));