Rollup merge of #104931 - Swatinem:async-pretty, r=eholk
Pretty-print generators with their `generator_kind` After removing `GenFuture`, I special-cased async generators to pretty-print as `impl Future<Output = X>` mainly to avoid too much diagnostics changes originally. This now reverses that change so that async fn/blocks are pretty-printed as `[$async-type@$source-position]` in various diagnostics, and updates the tests that this touches.
This commit is contained in:
commit
6e6c42c61c
20 changed files with 85 additions and 90 deletions
|
@ -376,7 +376,7 @@ impl<'tcx> NonConstOp<'tcx> for Generator {
|
|||
ccx: &ConstCx<'_, 'tcx>,
|
||||
span: Span,
|
||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||
let msg = format!("{}s are not allowed in {}s", self.0, ccx.const_kind());
|
||||
let msg = format!("{}s are not allowed in {}s", self.0.descr(), ccx.const_kind());
|
||||
if let hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Block) = self.0 {
|
||||
ccx.tcx.sess.create_feature_err(
|
||||
UnallowedOpInConstContext { span, msg },
|
||||
|
|
|
@ -1514,9 +1514,9 @@ pub enum AsyncGeneratorKind {
|
|||
impl fmt::Display for AsyncGeneratorKind {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.write_str(match self {
|
||||
AsyncGeneratorKind::Block => "`async` block",
|
||||
AsyncGeneratorKind::Closure => "`async` closure body",
|
||||
AsyncGeneratorKind::Fn => "`async fn` body",
|
||||
AsyncGeneratorKind::Block => "async block",
|
||||
AsyncGeneratorKind::Closure => "async closure body",
|
||||
AsyncGeneratorKind::Fn => "async fn body",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,7 +118,8 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
|
|||
} else {
|
||||
let note = format!(
|
||||
"the type is part of the {} because of this {}",
|
||||
self.kind, yield_data.source
|
||||
self.kind.descr(),
|
||||
yield_data.source
|
||||
);
|
||||
|
||||
self.fcx
|
||||
|
|
|
@ -681,25 +681,20 @@ pub trait PrettyPrinter<'tcx>:
|
|||
}
|
||||
ty::Str => p!("str"),
|
||||
ty::Generator(did, substs, movability) => {
|
||||
// FIXME(swatinem): async constructs used to be pretty printed
|
||||
// as `impl Future` previously due to the `from_generator` wrapping.
|
||||
// lets special case this here for now to avoid churn in diagnostics.
|
||||
let generator_kind = self.tcx().generator_kind(did);
|
||||
if matches!(generator_kind, Some(hir::GeneratorKind::Async(..))) {
|
||||
let return_ty = substs.as_generator().return_ty();
|
||||
p!(write("impl Future<Output = {}>", return_ty));
|
||||
|
||||
return Ok(self);
|
||||
}
|
||||
|
||||
p!(write("["));
|
||||
match movability {
|
||||
hir::Movability::Movable => {}
|
||||
hir::Movability::Static => p!("static "),
|
||||
let generator_kind = self.tcx().generator_kind(did).unwrap();
|
||||
let should_print_movability =
|
||||
self.should_print_verbose() || generator_kind == hir::GeneratorKind::Gen;
|
||||
|
||||
if should_print_movability {
|
||||
match movability {
|
||||
hir::Movability::Movable => {}
|
||||
hir::Movability::Static => p!("static "),
|
||||
}
|
||||
}
|
||||
|
||||
if !self.should_print_verbose() {
|
||||
p!("generator");
|
||||
p!(write("{}", generator_kind));
|
||||
// FIXME(eddyb) should use `def_span`.
|
||||
if let Some(did) = did.as_local() {
|
||||
let span = self.tcx().def_span(did);
|
||||
|
|
|
@ -2673,7 +2673,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
let sp = self.tcx.def_span(def_id);
|
||||
|
||||
// Special-case this to say "async block" instead of `[static generator]`.
|
||||
let kind = tcx.generator_kind(def_id).unwrap();
|
||||
let kind = tcx.generator_kind(def_id).unwrap().descr();
|
||||
err.span_note(
|
||||
sp,
|
||||
&format!("required because it's used within this {}", kind),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue