diff --git a/llvm/include/llvm/Demangle/RustDemangle.h b/llvm/include/llvm/Demangle/RustDemangle.h --- a/llvm/include/llvm/Demangle/RustDemangle.h +++ b/llvm/include/llvm/Demangle/RustDemangle.h @@ -63,9 +63,12 @@ // Position in the input string. size_t Position; + // When true, print methods append the output to the stream. + // When false, the output is suppressed. + bool Print; + // True if an error occurred. bool Error; - public: // Demangled output. OutputStream Output; @@ -76,6 +79,7 @@ private: void demanglePath(); + void demangleImplPath(); void demangleGenericArg(); void demangleType(); void demangleConst(); @@ -90,21 +94,21 @@ uint64_t parseHexNumber(StringView &HexDigits); void print(char C) { - if (Error) + if (Error || !Print) return; Output += C; } void print(StringView S) { - if (Error) + if (Error || !Print) return; Output += S; } void printDecimalNumber(uint64_t N) { - if (Error) + if (Error || !Print) return; Output << N; diff --git a/llvm/lib/Demangle/RustDemangle.cpp b/llvm/lib/Demangle/RustDemangle.cpp --- a/llvm/lib/Demangle/RustDemangle.cpp +++ b/llvm/lib/Demangle/RustDemangle.cpp @@ -101,6 +101,7 @@ bool Demangler::demangle(StringView Mangled) { Position = 0; Error = false; + Print = true; RecursionLevel = 0; if (!Mangled.consumeFront("_R")) { @@ -145,6 +146,30 @@ print(Ident.Name); break; } + case 'M': { + demangleImplPath(); + print("<"); + demangleType(); + print(">"); + break; + } + case 'X': { + demangleImplPath(); + print("<"); + demangleType(); + print(" as "); + demanglePath(); + print(">"); + break; + } + case 'Y': { + print("<"); + demangleType(); + print(" as "); + demanglePath(); + print(">"); + break; + } case 'N': { char NS = consume(); if (!isLower(NS) && !isUpper(NS)) { @@ -199,6 +224,14 @@ } } +// = [] +// = "s" +void Demangler::demangleImplPath() { + SwapAndRestore SavePrint(Print, false); + parseOptionalBase62Number('s'); + demanglePath(); +} + // = // | // | "K" diff --git a/llvm/test/Demangle/rust.test b/llvm/test/Demangle/rust.test --- a/llvm/test/Demangle/rust.test +++ b/llvm/test/Demangle/rust.test @@ -33,6 +33,27 @@ CHECK: crate::{Z:ident#10} _RNZC5crates8_5ident +; Inherent impl + +CHECK: <_> + _RMC5cratep + +CHECK: <_> + _RMs_C5cratep + +; Trait impl + +CHECK: <_ as Clone> + _RXC5cratepC5Clone + +CHECK: <_ as Clone> + _RXs_C5cratepC5Clone + +; Trait definition + +CHECK: <_ as Ord> + _RYpC3Ord + ; Generic type arguments CHECK: generic::<_>