Skip to content

Fix legacy symbol mangling of closures #135493

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

Merged
merged 1 commit into from
Jan 14, 2025
Merged
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
8 changes: 4 additions & 4 deletions compiler/rustc_symbol_mangling/src/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ pub(super) fn mangle<'tcx>(
let def_id = instance.def_id();

// We want to compute the "type" of this item. Unfortunately, some
// kinds of items (e.g., closures) don't have an entry in the
// item-type array. So walk back up the find the closest parent
// that DOES have an entry.
// kinds of items (e.g., synthetic static allocations from const eval)
// don't have a proper implementation for the `type_of` query. So walk
// back up the find the closest parent that DOES have a type.
let mut ty_def_id = def_id;
let instance_ty;
loop {
let key = tcx.def_key(ty_def_id);
match key.disambiguated_data.data {
DefPathData::TypeNs(_) | DefPathData::ValueNs(_) => {
DefPathData::TypeNs(_) | DefPathData::ValueNs(_) | DefPathData::Closure => {
instance_ty = tcx.type_of(ty_def_id).instantiate_identity();
debug!(?instance_ty);
break;
Expand Down
6 changes: 6 additions & 0 deletions tests/codegen-units/item-collection/closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ pub async fn async_fn() {}
pub fn closure() {
let _ = || {};
}

//~ MONO_ITEM fn A::{constant#0}::{closure#0} @@
trait A where
[(); (|| {}, 1).1]: Sized,
{
}
Loading