Skip to content

Commit f9c2c12

Browse files
authored
Rollup merge of #135493 - compiler-errors:legacy-mangle-closure, r=lqd
Fix legacy symbol mangling of closures When this code was written, there was no `type_of` implementation for closures. That has long since been changed. In the UI test: ``` trait A where [(); (|| {}, 1).1]: Sized, { } ``` We tried to walk up the def path tree for the closure, from closure -> anon const -> trait. When we reached the trait, we tried to call `type_of` on it which obviously doesn't do the right thing and ICEs. Fixes #135418
2 parents 7354f6e + faafa5c commit f9c2c12

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

compiler/rustc_symbol_mangling/src/legacy.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ pub(super) fn mangle<'tcx>(
1919
let def_id = instance.def_id();
2020

2121
// We want to compute the "type" of this item. Unfortunately, some
22-
// kinds of items (e.g., closures) don't have an entry in the
23-
// item-type array. So walk back up the find the closest parent
24-
// that DOES have an entry.
22+
// kinds of items (e.g., synthetic static allocations from const eval)
23+
// don't have a proper implementation for the `type_of` query. So walk
24+
// back up the find the closest parent that DOES have a type.
2525
let mut ty_def_id = def_id;
2626
let instance_ty;
2727
loop {
2828
let key = tcx.def_key(ty_def_id);
2929
match key.disambiguated_data.data {
30-
DefPathData::TypeNs(_) | DefPathData::ValueNs(_) => {
30+
DefPathData::TypeNs(_) | DefPathData::ValueNs(_) | DefPathData::Closure => {
3131
instance_ty = tcx.type_of(ty_def_id).instantiate_identity();
3232
debug!(?instance_ty);
3333
break;

tests/codegen-units/item-collection/closures.rs

+6
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ pub async fn async_fn() {}
1010
pub fn closure() {
1111
let _ = || {};
1212
}
13+
14+
//~ MONO_ITEM fn A::{constant#0}::{closure#0} @@
15+
trait A where
16+
[(); (|| {}, 1).1]: Sized,
17+
{
18+
}

0 commit comments

Comments
 (0)