Commit a2625a64 by Chris Mihelich Committed by Copybara-Service

Recognize inherent-impl and trait-impl in Rust demangling.

PiperOrigin-RevId: 635955480
Change-Id: I9322b4e7732e252007f6ca6c9b0cefc25974c9f8
parent 7a730c1b
...@@ -151,8 +151,8 @@ class RustSymbolParser { ...@@ -151,8 +151,8 @@ class RustSymbolParser {
path: path:
switch (Take()) { switch (Take()) {
case 'C': goto crate_root; case 'C': goto crate_root;
case 'M': return false; // inherent-impl not yet implemented case 'M': goto inherent_impl;
case 'X': return false; // trait-impl not yet implemented case 'X': goto trait_impl;
case 'Y': goto trait_definition; case 'Y': goto trait_definition;
case 'N': goto nested_path; case 'N': goto nested_path;
case 'I': goto generic_args; case 'I': goto generic_args;
...@@ -165,6 +165,35 @@ class RustSymbolParser { ...@@ -165,6 +165,35 @@ class RustSymbolParser {
if (!ParseIdentifier()) return false; if (!ParseIdentifier()) return false;
continue; continue;
// inherent-impl -> M impl-path type (M already consumed)
inherent_impl:
if (!Emit("<")) return false;
ABSL_DEMANGLER_RECURSE(impl_path, kInherentImplType);
ABSL_DEMANGLER_RECURSE(type, kInherentImplEnding);
if (!Emit(">")) return false;
continue;
// trait-impl -> X impl-path type path (X already consumed)
trait_impl:
if (!Emit("<")) return false;
ABSL_DEMANGLER_RECURSE(impl_path, kTraitImplType);
ABSL_DEMANGLER_RECURSE(type, kTraitImplInfix);
if (!Emit(" as ")) return false;
ABSL_DEMANGLER_RECURSE(path, kTraitImplEnding);
if (!Emit(">")) return false;
continue;
// impl-path -> disambiguator? path (but never print it!)
impl_path:
++silence_depth_;
{
int ignored_disambiguator;
if (!ParseDisambiguator(ignored_disambiguator)) return false;
}
ABSL_DEMANGLER_RECURSE(path, kImplPathEnding);
--silence_depth_;
continue;
// trait-definition -> Y type path (Y already consumed) // trait-definition -> Y type path (Y already consumed)
trait_definition: trait_definition:
if (!Emit("<")) return false; if (!Emit("<")) return false;
...@@ -407,6 +436,12 @@ class RustSymbolParser { ...@@ -407,6 +436,12 @@ class RustSymbolParser {
kVendorSpecificSuffix, kVendorSpecificSuffix,
kIdentifierInUppercaseNamespace, kIdentifierInUppercaseNamespace,
kIdentifierInLowercaseNamespace, kIdentifierInLowercaseNamespace,
kInherentImplType,
kInherentImplEnding,
kTraitImplType,
kTraitImplInfix,
kTraitImplEnding,
kImplPathEnding,
kTraitDefinitionInfix, kTraitDefinitionInfix,
kTraitDefinitionEnding, kTraitDefinitionEnding,
kArraySize, kArraySize,
......
...@@ -453,6 +453,31 @@ TEST(DemangleRust, NumberPlaceholder) { ...@@ -453,6 +453,31 @@ TEST(DemangleRust, NumberPlaceholder) {
"c::f::<>::g"); "c::f::<>::g");
} }
TEST(DemangleRust, InherentImplWithoutDisambiguator) {
EXPECT_DEMANGLING("_RNvMNtC8my_crate6my_modNtB2_9my_struct7my_func",
"<my_crate::my_mod::my_struct>::my_func");
}
TEST(DemangleRust, InherentImplWithDisambiguator) {
EXPECT_DEMANGLING("_RNvMs_NtC8my_crate6my_modNtB4_9my_struct7my_func",
"<my_crate::my_mod::my_struct>::my_func");
}
TEST(DemangleRust, TraitImplWithoutDisambiguator) {
EXPECT_DEMANGLING("_RNvXC8my_crateNtB2_9my_structNtB2_8my_trait7my_func",
"<my_crate::my_struct as my_crate::my_trait>::my_func");
}
TEST(DemangleRust, TraitImplWithDisambiguator) {
EXPECT_DEMANGLING("_RNvXs_C8my_crateNtB4_9my_structNtB4_8my_trait7my_func",
"<my_crate::my_struct as my_crate::my_trait>::my_func");
}
TEST(DemangleRust, TraitImplWithNonpathSelfType) {
EXPECT_DEMANGLING("_RNvXC8my_crateRlNtB2_8my_trait7my_func",
"<&i32 as my_crate::my_trait>::my_func");
}
} // namespace } // namespace
} // namespace debugging_internal } // namespace debugging_internal
ABSL_NAMESPACE_END ABSL_NAMESPACE_END
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment