diff --git a/compiler/rustc_const_eval/src/util/type_name.rs b/compiler/rustc_const_eval/src/util/type_name.rs index e8f2728a7728f..a4e910c153805 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, Print, PrintError, Printer}; @@ -108,6 +108,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> { fn path_append( &mut self, + _def_id: DefId, print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>, disambiguated_data: &DisambiguatedDefPathData, ) -> Result<(), PrintError> { diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index b694d3dd49b79..f88452b3a66f7 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -828,6 +828,7 @@ impl<'tcx> LateContext<'tcx> { fn path_append( &mut self, + _def_id: DefId, print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>, disambiguated_data: &DisambiguatedDefPathData, ) -> Result<(), PrintError> { diff --git a/compiler/rustc_middle/src/ty/print/mod.rs b/compiler/rustc_middle/src/ty/print/mod.rs index 9172c5d3ab752..e13cac98f94d5 100644 --- a/compiler/rustc_middle/src/ty/print/mod.rs +++ b/compiler/rustc_middle/src/ty/print/mod.rs @@ -95,6 +95,7 @@ pub trait Printer<'tcx>: Sized { fn path_append( &mut self, + def_id: DefId, print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>, disambiguated_data: &DisambiguatedDefPathData, ) -> Result<(), PrintError>; @@ -186,6 +187,7 @@ pub trait Printer<'tcx>: Sized { } self.path_append( + def_id, |cx: &mut Self| { if trait_qualify_parent { let trait_ref = ty::TraitRef::new( diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 2eb530f328d39..cabccfd0b8bac 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -660,7 +660,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { true => {} } callers.pop(); - self.path_append(|_| Ok(()), &DisambiguatedDefPathData { data, disambiguator: 0 })?; + self.path_append(def_id, |_| Ok(()), &DisambiguatedDefPathData { data, disambiguator: 0 })?; Ok(true) } @@ -1352,6 +1352,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { self.path_generic_args( |cx| { cx.path_append( + alias_ty.def_id, |cx| cx.path_qualified(alias_ty.self_ty(), None), &def_key.disambiguated_data, ) @@ -2408,6 +2409,7 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> { fn path_append( &mut self, + def_id: DefId, print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>, disambiguated_data: &DisambiguatedDefPathData, ) -> Result<(), PrintError> { @@ -2417,6 +2419,15 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> { if let DefPathData::ForeignMod | DefPathData::Ctor = disambiguated_data.data { return Ok(()); } + if let DefPathData::Closure = disambiguated_data.data + && let Some(hir::CoroutineKind::Desugared( + hir::CoroutineDesugaring::Async, + hir::CoroutineSource::Fn, + )) = self.tcx.coroutine_kind(def_id) + { + // Skip the implicit closure in `async_function::{closure#0}`. + return Ok(()); + } let name = disambiguated_data.data.name(); if !self.empty_path { diff --git a/compiler/rustc_symbol_mangling/src/legacy.rs b/compiler/rustc_symbol_mangling/src/legacy.rs index 12d1de463136a..7df4c2ac83a1b 100644 --- a/compiler/rustc_symbol_mangling/src/legacy.rs +++ b/compiler/rustc_symbol_mangling/src/legacy.rs @@ -357,6 +357,7 @@ impl<'tcx> Printer<'tcx> for SymbolPrinter<'tcx> { } fn path_append( &mut self, + _def_id: DefId, print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>, disambiguated_data: &DisambiguatedDefPathData, ) -> Result<(), PrintError> { diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index fe0f8e6113ef7..e2d3e0f23d683 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -859,6 +859,7 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> { fn path_append( &mut self, + _def_id: DefId, print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>, disambiguated_data: &DisambiguatedDefPathData, ) -> Result<(), PrintError> { diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs index b9acadc406e9c..dc627dfaeb00c 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs @@ -276,6 +276,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } fn path_append( &mut self, + _def_id: DefId, print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>, disambiguated_data: &DisambiguatedDefPathData, ) -> Result<(), PrintError> { diff --git a/tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-abort.mir b/tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-abort.mir index 347e4119cd0e0..ade45bc469a8f 100644 --- a/tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-abort.mir +++ b/tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-abort.mir @@ -1,6 +1,6 @@ -// MIR for `a::{closure#0}` 0 coroutine_drop_async +// MIR for `a` 0 coroutine_drop_async -fn a::{closure#0}(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) -> Poll<()> { +fn a(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) -> Poll<()> { debug _task_context => _19; debug x => ((*(_1.0: &mut {async fn body of a()})).0: T); let mut _0: std::task::Poll<()>; diff --git a/tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-unwind.mir b/tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-unwind.mir index b1cf5373f9191..77db447aa82c3 100644 --- a/tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-unwind.mir +++ b/tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-unwind.mir @@ -1,6 +1,6 @@ -// MIR for `a::{closure#0}` 0 coroutine_drop_async +// MIR for `a` 0 coroutine_drop_async -fn a::{closure#0}(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) -> Poll<()> { +fn a(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) -> Poll<()> { debug _task_context => _19; debug x => ((*(_1.0: &mut {async fn body of a()})).0: T); let mut _0: std::task::Poll<()>; diff --git a/tests/mir-opt/building/async_await.a-{closure#0}.coroutine_resume.0.mir b/tests/mir-opt/building/async_await.a-{closure#0}.coroutine_resume.0.mir index 7480324b17791..83e3bf574ab1e 100644 --- a/tests/mir-opt/building/async_await.a-{closure#0}.coroutine_resume.0.mir +++ b/tests/mir-opt/building/async_await.a-{closure#0}.coroutine_resume.0.mir @@ -1,4 +1,4 @@ -// MIR for `a::{closure#0}` 0 coroutine_resume +// MIR for `a` 0 coroutine_resume /* coroutine_layout = CoroutineLayout { field_tys: {}, variant_fields: { @@ -9,7 +9,7 @@ storage_conflicts: BitMatrix(0x0) {}, } */ -fn a::{closure#0}(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) -> Poll<()> { +fn a(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) -> Poll<()> { debug _task_context => _4; let mut _0: std::task::Poll<()>; let mut _3: (); diff --git a/tests/mir-opt/building/async_await.b-{closure#0}.coroutine_resume.0.mir b/tests/mir-opt/building/async_await.b-{closure#0}.coroutine_resume.0.mir index 109a41d1ef907..c9ffee36c7d22 100644 --- a/tests/mir-opt/building/async_await.b-{closure#0}.coroutine_resume.0.mir +++ b/tests/mir-opt/building/async_await.b-{closure#0}.coroutine_resume.0.mir @@ -1,4 +1,4 @@ -// MIR for `b::{closure#0}` 0 coroutine_resume +// MIR for `b` 0 coroutine_resume /* coroutine_layout = CoroutineLayout { field_tys: { _0: CoroutineSavedTy { @@ -57,7 +57,7 @@ }, } */ -fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) -> Poll<()> { +fn b(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) -> Poll<()> { debug _task_context => _38; let mut _0: std::task::Poll<()>; let _3: (); diff --git a/tests/mir-opt/inline_coroutine_body.run2-{closure#0}.Inline.panic-abort.diff b/tests/mir-opt/inline_coroutine_body.run2-{closure#0}.Inline.panic-abort.diff index 1e9a6dd4f5c8f..296eeb0355e30 100644 --- a/tests/mir-opt/inline_coroutine_body.run2-{closure#0}.Inline.panic-abort.diff +++ b/tests/mir-opt/inline_coroutine_body.run2-{closure#0}.Inline.panic-abort.diff @@ -20,7 +20,7 @@ debug fut => _4; scope 3 { } -+ scope 6 (inlined ActionPermit::<'_, T>::perform::{closure#0}) { ++ scope 6 (inlined ActionPermit::<'_, T>::perform) { + let _11: ActionPermit<'_, T>; + let mut _12: std::future::Ready<()>; + let mut _13: std::future::Ready<()>; diff --git a/tests/mir-opt/inline_coroutine_body.run2-{closure#0}.Inline.panic-unwind.diff b/tests/mir-opt/inline_coroutine_body.run2-{closure#0}.Inline.panic-unwind.diff index 94b89a310baa8..d5ddd4dc9810f 100644 --- a/tests/mir-opt/inline_coroutine_body.run2-{closure#0}.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline_coroutine_body.run2-{closure#0}.Inline.panic-unwind.diff @@ -20,7 +20,7 @@ debug fut => _4; scope 3 { } -+ scope 6 (inlined ActionPermit::<'_, T>::perform::{closure#0}) { ++ scope 6 (inlined ActionPermit::<'_, T>::perform) { + let _11: ActionPermit<'_, T>; + let mut _12: std::future::Ready<()>; + let mut _13: std::future::Ready<()>; diff --git a/tests/ui/force-inlining/deny-async.stderr b/tests/ui/force-inlining/deny-async.stderr index d6516ed875c21..4619edb725ddc 100644 --- a/tests/ui/force-inlining/deny-async.stderr +++ b/tests/ui/force-inlining/deny-async.stderr @@ -20,7 +20,7 @@ LL | pub fn callee_justified() { | = note: incompatible due to: #[rustc_no_mir_inline] -error: `callee` could not be inlined into `async_caller::{closure#0}` but is required to be inlined +error: `callee` could not be inlined into `async_caller` but is required to be inlined --> $DIR/deny-async.rs:22:5 | LL | callee(); @@ -28,7 +28,7 @@ LL | callee(); | = note: could not be inlined due to: #[rustc_no_mir_inline] -error: `callee_justified` could not be inlined into `async_caller::{closure#0}` but is required to be inlined +error: `callee_justified` could not be inlined into `async_caller` but is required to be inlined --> $DIR/deny-async.rs:24:5 | LL | callee_justified();