diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2022-03-31 04:57:25 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-31 04:57:25 +0200 |
| commit | 4ce6567daa7aab5618aa27f69ceff779cbe2bd7d (patch) | |
| tree | bd85364c5c0891416be494d2c0bdfa9b8e2f1a22 /compiler | |
| parent | 32c5a57a00c234d5bcbba6c3d5ab638d3dd54494 (diff) | |
| parent | 7b2eaa3d8fb73cd1863665bf4b8c24e3b34eb41b (diff) | |
| download | rust-4ce6567daa7aab5618aa27f69ceff779cbe2bd7d.tar.gz rust-4ce6567daa7aab5618aa27f69ceff779cbe2bd7d.zip | |
Rollup merge of #95263 - compiler-errors:async-block-pretty, r=jackh726
Restore `impl Future<Output = Type>` to async blocks I was sad when I undid some of the code I wrote in #91096 in the PR #95225, so I fixed it here to not print `[async output]`. This PR "manually" normalizes the associated type `<[generator] as Generator>::Return` type which appears very frequently in `impl Future` types that result from async block desugaring.
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_middle/src/ty/print/pretty.rs | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 826000dcecf..21650fbb75d 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -912,12 +912,25 @@ pub trait PrettyPrinter<'tcx>: } for (assoc_item_def_id, term) in assoc_items { - // Skip printing `<[generator@] as Generator<_>>::Return` from async blocks - if let Some(ty) = term.skip_binder().ty() && - let ty::Projection(ty::ProjectionTy { item_def_id, .. }) = ty.kind() && - Some(*item_def_id) == self.tcx().lang_items().generator_return() { - continue; - } + // Skip printing `<[generator@] as Generator<_>>::Return` from async blocks, + // unless we can find out what generator return type it comes from. + let term = if let Some(ty) = term.skip_binder().ty() + && let ty::Projection(ty::ProjectionTy { item_def_id, substs }) = ty.kind() + && Some(*item_def_id) == self.tcx().lang_items().generator_return() + { + if let ty::Generator(_, substs, _) = substs.type_at(0).kind() { + let return_ty = substs.as_generator().return_ty(); + if !return_ty.is_ty_infer() { + return_ty.into() + } else { + continue; + } + } else { + continue; + } + } else { + term.skip_binder() + }; if first { p!("<"); @@ -928,7 +941,7 @@ pub trait PrettyPrinter<'tcx>: p!(write("{} = ", self.tcx().associated_item(assoc_item_def_id).name)); - match term.skip_binder() { + match term { Term::Ty(ty) => { p!(print(ty)) } |
