diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2025-08-20 00:46:00 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-20 00:46:00 -0400 |
| commit | ef22202db230a47bd82b168684d3580c40531d28 (patch) | |
| tree | f5d7d90c247244920ac81efb57598ee33d94d8bb /compiler/rustc_const_eval | |
| parent | 6e6522980a88f117152dafdaba7f8e21d1bdd3fd (diff) | |
| parent | ab6f4d62c0aab0f64b663bb572de8a896411b46a (diff) | |
| download | rust-ef22202db230a47bd82b168684d3580c40531d28.tar.gz rust-ef22202db230a47bd82b168684d3580c40531d28.zip | |
Rollup merge of #145623 - compiler-errors:pretty-async-name, r=wesleywiser
Pretty print the name of an future from calling async closure Fixes https://github.com/rust-lang/rust/issues/145606 by introducing a way to customize the path rendering of async closures' futures in the pretty printer API.
Diffstat (limited to 'compiler/rustc_const_eval')
| -rw-r--r-- | compiler/rustc_const_eval/src/util/type_name.rs | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/compiler/rustc_const_eval/src/util/type_name.rs b/compiler/rustc_const_eval/src/util/type_name.rs index 13cc607135a..92096958f2b 100644 --- a/compiler/rustc_const_eval/src/util/type_name.rs +++ b/compiler/rustc_const_eval/src/util/type_name.rs @@ -1,7 +1,7 @@ use std::fmt::Write; use rustc_data_structures::intern::Interned; -use rustc_hir::def_id::CrateNum; +use rustc_hir::def_id::{CrateNum, DefId}; use rustc_hir::definitions::DisambiguatedDefPathData; use rustc_middle::bug; use rustc_middle::ty::print::{PrettyPrinter, PrintError, Printer}; @@ -132,6 +132,35 @@ impl<'tcx> Printer<'tcx> for TypeNamePrinter<'tcx> { Ok(()) } } + + fn print_coroutine_with_kind( + &mut self, + def_id: DefId, + parent_args: &'tcx [GenericArg<'tcx>], + kind: Ty<'tcx>, + ) -> Result<(), PrintError> { + self.print_def_path(def_id, parent_args)?; + + let ty::Coroutine(_, args) = self.tcx.type_of(def_id).instantiate_identity().kind() else { + // Could be `ty::Error`. + return Ok(()); + }; + + let default_kind = args.as_coroutine().kind_ty(); + + match kind.to_opt_closure_kind() { + _ if kind == default_kind => { + // No need to mark the closure if it's the deduced coroutine kind. + } + Some(ty::ClosureKind::Fn) | None => { + // Should never happen. Just don't mark anything rather than panicking. + } + Some(ty::ClosureKind::FnMut) => self.path.push_str("::{{call_mut}}"), + Some(ty::ClosureKind::FnOnce) => self.path.push_str("::{{call_once}}"), + } + + Ok(()) + } } impl<'tcx> PrettyPrinter<'tcx> for TypeNamePrinter<'tcx> { |
