Skip to content

Commit add3f90

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

File tree

8 files changed

+22
-4
lines changed

8 files changed

+22
-4
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/ui/force-inlining/deny-async.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ LL | pub fn callee_justified() {
2020
|
2121
= note: incompatible due to: #[rustc_no_mir_inline]
2222

23-
error: `callee` could not be inlined into `async_caller::{closure#0}` but is required to be inlined
23+
error: `callee` could not be inlined into `async_caller` but is required to be inlined
2424
--> $DIR/deny-async.rs:22:5
2525
|
2626
LL | callee();
2727
| ^^^^^^^^ ...`callee` called here
2828
|
2929
= note: could not be inlined due to: #[rustc_no_mir_inline]
3030

31-
error: `callee_justified` could not be inlined into `async_caller::{closure#0}` but is required to be inlined
31+
error: `callee_justified` could not be inlined into `async_caller` but is required to be inlined
3232
--> $DIR/deny-async.rs:24:5
3333
|
3434
LL | callee_justified();

0 commit comments

Comments
 (0)