Skip to content
Open
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
13 changes: 12 additions & 1 deletion compiler/rustc_symbol_mangling/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,18 @@ fn compute_symbol_name<'tcx>(
mangled_name
}
}
SymbolManglingVersion::V0 => v0::mangle(tcx, instance, instantiating_crate, false),
SymbolManglingVersion::V0 => {
let mangled = v0::mangle(tcx, instance, instantiating_crate, false);
// v0 mangling can produce symbols that are too deeply nested for
// `rustc_demangle` to handle (e.g. pathologically nested generic
// type aliases exceed its recursion limit). Fall back to hashed
// mangling in that case so we always emit a demanglable symbol.
if rustc_demangle::try_demangle(&mangled).is_ok() {
mangled
} else {
hashed::mangle(tcx, instance, instantiating_crate, || mangled)
}
}
SymbolManglingVersion::Hashed => {
hashed::mangle(tcx, instance, instantiating_crate, || {
v0::mangle(tcx, instance, instantiating_crate, false)
Expand Down
24 changes: 24 additions & 0 deletions tests/ui/symbol-names/deeply-nested-generic-aliases.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//@ build-pass
//@ compile-flags: -C symbol-mangling-version=v0

struct D;

type O0<T> = Option<T>;
type O1<T> = O0<T>;
type O2<T> = O1<O1<T>>;
type O3<T> = O2<O2<T>>;
type O4<T> = O3<O3<T>>;
type O5<T> = O4<O4<T>>;
type O6<T> = O5<O5<T>>;
type O7<T> = O6<O6<T>>;
type O8<T> = O7<O7<T>>;
type Q510<T> = O8<O7<O6<O5<O4<O3<O2<T>>>>>>>;

fn f<T>() {}
fn describe<T>() {
f::<Q510<T>>()
}

fn main() {
describe::<D>();
}
Loading