Skip to content

Commit b89376f

Browse files
committed
Do not include implicit desugared closure from async fn in closure type path
1 parent ee3a078 commit b89376f

File tree

14 files changed

+32
-14
lines changed

14 files changed

+32
-14
lines changed

compiler/rustc_const_eval/src/util/type_name.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt::Write;
22

33
use rustc_data_structures::intern::Interned;
4-
use rustc_hir::def_id::CrateNum;
4+
use rustc_hir::def_id::{CrateNum, DefId};
55
use rustc_hir::definitions::DisambiguatedDefPathData;
66
use rustc_middle::bug;
77
use rustc_middle::ty::print::{PrettyPrinter, Print, PrintError, Printer};
@@ -108,6 +108,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
108108

109109
fn path_append(
110110
&mut self,
111+
_def_id: DefId,
111112
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
112113
disambiguated_data: &DisambiguatedDefPathData,
113114
) -> Result<(), PrintError> {

compiler/rustc_lint/src/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,7 @@ impl<'tcx> LateContext<'tcx> {
828828

829829
fn path_append(
830830
&mut self,
831+
_def_id: DefId,
831832
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
832833
disambiguated_data: &DisambiguatedDefPathData,
833834
) -> Result<(), PrintError> {

compiler/rustc_middle/src/ty/print/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ pub trait Printer<'tcx>: Sized {
9595

9696
fn path_append(
9797
&mut self,
98+
def_id: DefId,
9899
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
99100
disambiguated_data: &DisambiguatedDefPathData,
100101
) -> Result<(), PrintError>;
@@ -186,6 +187,7 @@ pub trait Printer<'tcx>: Sized {
186187
}
187188

188189
self.path_append(
190+
def_id,
189191
|cx: &mut Self| {
190192
if trait_qualify_parent {
191193
let trait_ref = ty::TraitRef::new(

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
660660
true => {}
661661
}
662662
callers.pop();
663-
self.path_append(|_| Ok(()), &DisambiguatedDefPathData { data, disambiguator: 0 })?;
663+
self.path_append(def_id, |_| Ok(()), &DisambiguatedDefPathData { data, disambiguator: 0 })?;
664664
Ok(true)
665665
}
666666

@@ -1352,6 +1352,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
13521352
self.path_generic_args(
13531353
|cx| {
13541354
cx.path_append(
1355+
alias_ty.def_id,
13551356
|cx| cx.path_qualified(alias_ty.self_ty(), None),
13561357
&def_key.disambiguated_data,
13571358
)
@@ -2408,6 +2409,7 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
24082409

24092410
fn path_append(
24102411
&mut self,
2412+
def_id: DefId,
24112413
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
24122414
disambiguated_data: &DisambiguatedDefPathData,
24132415
) -> Result<(), PrintError> {
@@ -2417,6 +2419,15 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
24172419
if let DefPathData::ForeignMod | DefPathData::Ctor = disambiguated_data.data {
24182420
return Ok(());
24192421
}
2422+
if let DefPathData::Closure = disambiguated_data.data
2423+
&& let Some(hir::CoroutineKind::Desugared(
2424+
hir::CoroutineDesugaring::Async,
2425+
hir::CoroutineSource::Fn,
2426+
)) = self.tcx.coroutine_kind(def_id)
2427+
{
2428+
// Skip the implicit closure in `async_function::{closure#0}`.
2429+
return Ok(());
2430+
}
24202431

24212432
let name = disambiguated_data.data.name();
24222433
if !self.empty_path {

compiler/rustc_symbol_mangling/src/legacy.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ impl<'tcx> Printer<'tcx> for SymbolPrinter<'tcx> {
357357
}
358358
fn path_append(
359359
&mut self,
360+
_def_id: DefId,
360361
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
361362
disambiguated_data: &DisambiguatedDefPathData,
362363
) -> Result<(), PrintError> {

compiler/rustc_symbol_mangling/src/v0.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,7 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
859859

860860
fn path_append(
861861
&mut self,
862+
_def_id: DefId,
862863
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
863864
disambiguated_data: &DisambiguatedDefPathData,
864865
) -> Result<(), PrintError> {

compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
276276
}
277277
fn path_append(
278278
&mut self,
279+
_def_id: DefId,
279280
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
280281
disambiguated_data: &DisambiguatedDefPathData,
281282
) -> Result<(), PrintError> {

tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-abort.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// MIR for `a::{closure#0}` 0 coroutine_drop_async
1+
// MIR for `a` 0 coroutine_drop_async
22

3-
fn a::{closure#0}(_1: Pin<&mut {async fn body of a<T>()}>, _2: &mut Context<'_>) -> Poll<()> {
3+
fn a(_1: Pin<&mut {async fn body of a<T>()}>, _2: &mut Context<'_>) -> Poll<()> {
44
debug _task_context => _19;
55
debug x => ((*(_1.0: &mut {async fn body of a<T>()})).0: T);
66
let mut _0: std::task::Poll<()>;

tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-unwind.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// MIR for `a::{closure#0}` 0 coroutine_drop_async
1+
// MIR for `a` 0 coroutine_drop_async
22

3-
fn a::{closure#0}(_1: Pin<&mut {async fn body of a<T>()}>, _2: &mut Context<'_>) -> Poll<()> {
3+
fn a(_1: Pin<&mut {async fn body of a<T>()}>, _2: &mut Context<'_>) -> Poll<()> {
44
debug _task_context => _19;
55
debug x => ((*(_1.0: &mut {async fn body of a<T>()})).0: T);
66
let mut _0: std::task::Poll<()>;

tests/mir-opt/building/async_await.a-{closure#0}.coroutine_resume.0.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// MIR for `a::{closure#0}` 0 coroutine_resume
1+
// MIR for `a` 0 coroutine_resume
22
/* coroutine_layout = CoroutineLayout {
33
field_tys: {},
44
variant_fields: {
@@ -9,7 +9,7 @@
99
storage_conflicts: BitMatrix(0x0) {},
1010
} */
1111

12-
fn a::{closure#0}(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) -> Poll<()> {
12+
fn a(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) -> Poll<()> {
1313
debug _task_context => _4;
1414
let mut _0: std::task::Poll<()>;
1515
let mut _3: ();

0 commit comments

Comments
 (0)