diff --git a/include/llvm/Demangle/RustDemangle.h b/include/llvm/Demangle/RustDemangle.h index 8797830cac6..7d575fbd6e2 100644 --- a/include/llvm/Demangle/RustDemangle.h +++ b/include/llvm/Demangle/RustDemangle.h @@ -63,6 +63,10 @@ class Demangler { // 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; @@ -76,6 +80,7 @@ public: private: void demanglePath(); + void demangleImplPath(); void demangleGenericArg(); void demangleType(); void demangleConst(); @@ -90,21 +95,21 @@ private: 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/lib/Demangle/RustDemangle.cpp b/lib/Demangle/RustDemangle.cpp index ebccafcae29..223d815aa4a 100644 --- a/lib/Demangle/RustDemangle.cpp +++ b/lib/Demangle/RustDemangle.cpp @@ -101,6 +101,7 @@ static inline bool isValid(const char C) { bool Demangler::demangle(StringView Mangled) { Position = 0; Error = false; + Print = true; RecursionLevel = 0; if (!Mangled.consumeFront("_R")) { @@ -145,6 +146,13 @@ void Demangler::demanglePath() { print(Ident.Name); break; } + case 'M': { + demangleImplPath(); + print("<"); + demangleType(); + print(">"); + break; + } case 'N': { char NS = consume(); if (!isLower(NS) && !isUpper(NS)) { @@ -199,6 +207,14 @@ void Demangler::demanglePath() { } } +// = [] +// = "s" +void Demangler::demangleImplPath() { + SwapAndRestore SavePrint(Print, false); + parseOptionalBase62Number('s'); + demanglePath(); +} + // = // | // | "K" diff --git a/test/Demangle/rust.test b/test/Demangle/rust.test index 89eda8ff1eb..c1ba4774faa 100644 --- a/test/Demangle/rust.test +++ b/test/Demangle/rust.test @@ -33,6 +33,14 @@ CHECK: crate::{shim:reify#0} CHECK: crate::{Z:ident#10} _RNZC5crates8_5ident +; Inherent impl + +CHECK: <_> + _RMC5cratep + +CHECK: <_> + _RMs_C5cratep + ; Generic type arguments CHECK: generic::<_>