Skip to content

Do not include implicit desugared closure from async fn in closure type path #144372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/rustc_const_eval/src/util/type_name.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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> {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_middle/src/ty/print/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down Expand Up @@ -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(
Expand Down
13 changes: 12 additions & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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> {
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_symbol_mangling/src/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_symbol_mangling/src/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<T>()}>, _2: &mut Context<'_>) -> Poll<()> {
fn a(_1: Pin<&mut {async fn body of a<T>()}>, _2: &mut Context<'_>) -> Poll<()> {
debug _task_context => _19;
debug x => ((*(_1.0: &mut {async fn body of a<T>()})).0: T);
let mut _0: std::task::Poll<()>;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<T>()}>, _2: &mut Context<'_>) -> Poll<()> {
fn a(_1: Pin<&mut {async fn body of a<T>()}>, _2: &mut Context<'_>) -> Poll<()> {
debug _task_context => _19;
debug x => ((*(_1.0: &mut {async fn body of a<T>()})).0: T);
let mut _0: std::task::Poll<()>;
Expand Down
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -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: ();
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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: ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<()>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<()>;
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/force-inlining/deny-async.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ 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();
| ^^^^^^^^ ...`callee` called here
|
= 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();
Expand Down
Loading