Skip to content

Commit 161ab95

Browse files
committed
fix
1 parent 64e9d13 commit 161ab95

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

‎cpp2rust/converter/converter.cpp‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,27 @@
2222
#include "converter/lex.h"
2323
#include "converter/mapper.h"
2424

25+
namespace cpp2rust {
26+
std::unordered_map<std::string, std::string> Converter::inner_structs_;
27+
std::unordered_set<std::string> Converter::decl_ids_;
28+
std::unordered_set<std::string> Converter::globals_;
29+
std::unordered_set<std::string> Converter::abstract_structs_;
30+
Converter::RecordIndex Converter::record_decls_;
31+
std::map<std::string, Converter::MethodsOnPtr> Converter::methods_on_ptr_;
32+
2533
// `static mut` globals cannot have a `&`/`&mut` reference formed directly to
2634
// them in Rust 2024 edition. Wrapping the variable in a `&raw mut` pointer
2735
// followed by a deref sidesteps the restriction.
2836
// Doesn't apply when a rule replaced the expression with custom Rust code.
2937
static std::string WrapMutableStaticPlace(const clang::Decl *decl, std::string str) {
30-
if (IsGlobalVar(decl) && !decl->getType()->isReferenceType() &&
38+
auto decl = clang::dyn_cast<clang::VarDecl>(decl);
39+
if (decl && IsGlobalVar(decl) && !decl->getType()->isReferenceType() &&
3140
str == GetNamedDeclAsString(decl)) {
3241
return std::format("(*&raw mut {})", str);
3342
}
3443
return str;
3544
}
3645

37-
namespace cpp2rust {
38-
std::unordered_map<std::string, std::string> Converter::inner_structs_;
39-
std::unordered_set<std::string> Converter::decl_ids_;
40-
std::unordered_set<std::string> Converter::globals_;
41-
std::unordered_set<std::string> Converter::abstract_structs_;
42-
Converter::RecordIndex Converter::record_decls_;
43-
std::map<std::string, Converter::MethodsOnPtr> Converter::methods_on_ptr_;
44-
4546
void Converter::ConvertUniquePtrDeref(clang::CXXOperatorCallExpr *expr) {
4647
bool is_star = expr->getOperator() == clang::OverloadedOperatorKind::OO_Star;
4748
PushParen paren(*this, is_star);

0 commit comments

Comments
 (0)