From 7c495d704fa9c849988e432a54b5ba94f2cedf85 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 21 Oct 2026 13:43:44 +0100 Subject: [PATCH 1/2] Fix order of adding keys --- cpp2rust/converter/rules/rules_loader.cpp | 1 + cpp2rust/rule_preprocessing/cpp_rule_indexer.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cpp2rust/converter/rules/rules_loader.cpp b/cpp2rust/converter/rules/rules_loader.cpp index a7dcd559ee..1ea5edec66 100644 --- a/cpp2rust/converter/rules/rules_loader.cpp +++ b/cpp2rust/converter/rules/rules_loader.cpp @@ -159,6 +159,7 @@ class RuleUsageCollector AddKey(TypeKey(type)); if (const auto *alias = llvm::dyn_cast(type.getTypePtr())) { + AddKey(DeclKey(alias->getDecl())); if (const auto *record = llvm::dyn_cast( alias->getDecl()->getDeclContext())) { AddKey(ClassKey(record)); diff --git a/cpp2rust/rule_preprocessing/cpp_rule_indexer.cpp b/cpp2rust/rule_preprocessing/cpp_rule_indexer.cpp index 7879881b79..d30ed39de2 100644 --- a/cpp2rust/rule_preprocessing/cpp_rule_indexer.cpp +++ b/cpp2rust/rule_preprocessing/cpp_rule_indexer.cpp @@ -215,12 +215,13 @@ std::string ExprKey(clang::ASTContext &ctx, const clang::Decl *rule) { std::string TypeKey(const clang::TypedefNameDecl *rule) { auto type = rule->getUnderlyingType(); + if (auto alias = type->getAs(); + alias && !type->isDependentType()) { + return RulesLoader::DeclKey(alias->getDecl()); + } if (auto key = RulesLoader::TypeKey(type); !key.empty()) { return key; } - if (!type->isDependentType() && type->getAs()) { - return RulesLoader::TypeKey(type); - } while (type->isPointerType() || type->isReferenceType()) { type = type->getPointeeType(); } From 1d8e42baa309993972a39ee4e0c35af585c44d38 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 21 Oct 2026 13:49:40 +0100 Subject: [PATCH 2/2] Peel pointers and references from typedef --- cpp2rust/rule_preprocessing/cpp_rule_indexer.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cpp2rust/rule_preprocessing/cpp_rule_indexer.cpp b/cpp2rust/rule_preprocessing/cpp_rule_indexer.cpp index d30ed39de2..16dbe5fb7e 100644 --- a/cpp2rust/rule_preprocessing/cpp_rule_indexer.cpp +++ b/cpp2rust/rule_preprocessing/cpp_rule_indexer.cpp @@ -215,9 +215,14 @@ std::string ExprKey(clang::ASTContext &ctx, const clang::Decl *rule) { std::string TypeKey(const clang::TypedefNameDecl *rule) { auto type = rule->getUnderlyingType(); - if (auto alias = type->getAs(); - alias && !type->isDependentType()) { - return RulesLoader::DeclKey(alias->getDecl()); + for (auto pointee = type;; pointee = pointee->getPointeeType()) { + if (auto alias = pointee->getAs(); + alias && !pointee->isDependentType()) { + return RulesLoader::DeclKey(alias->getDecl()); + } + if (!pointee->isPointerType() && !pointee->isReferenceType()) { + break; + } } if (auto key = RulesLoader::TypeKey(type); !key.empty()) { return key;