mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
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
This commit is contained in:
commit
f9c2c1256b
@ -19,15 +19,15 @@ pub(super) fn mangle<'tcx>(
|
|||||||
let def_id = instance.def_id();
|
let def_id = instance.def_id();
|
||||||
|
|
||||||
// We want to compute the "type" of this item. Unfortunately, some
|
// We want to compute the "type" of this item. Unfortunately, some
|
||||||
// kinds of items (e.g., closures) don't have an entry in the
|
// kinds of items (e.g., synthetic static allocations from const eval)
|
||||||
// item-type array. So walk back up the find the closest parent
|
// don't have a proper implementation for the `type_of` query. So walk
|
||||||
// that DOES have an entry.
|
// back up the find the closest parent that DOES have a type.
|
||||||
let mut ty_def_id = def_id;
|
let mut ty_def_id = def_id;
|
||||||
let instance_ty;
|
let instance_ty;
|
||||||
loop {
|
loop {
|
||||||
let key = tcx.def_key(ty_def_id);
|
let key = tcx.def_key(ty_def_id);
|
||||||
match key.disambiguated_data.data {
|
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();
|
instance_ty = tcx.type_of(ty_def_id).instantiate_identity();
|
||||||
debug!(?instance_ty);
|
debug!(?instance_ty);
|
||||||
break;
|
break;
|
||||||
|
@ -10,3 +10,9 @@ pub async fn async_fn() {}
|
|||||||
pub fn closure() {
|
pub fn closure() {
|
||||||
let _ = || {};
|
let _ = || {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//~ MONO_ITEM fn A::{constant#0}::{closure#0} @@
|
||||||
|
trait A where
|
||||||
|
[(); (|| {}, 1).1]: Sized,
|
||||||
|
{
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user