Skip to content

Commit 0181b75

Browse files
Copilotlucic71
authored andcommitted
Convert single-character StrCat string args to char literals (Cpp2Rust#178)
`StrCat` calls were using single-character string literals in many places (e.g. `"&gt;"`-style delimiters and punctuation), which is inconsistent with the intended char-based usage for single codepoints. This updates those call sites to pass character literals instead. Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent a6d0d48 commit 0181b75

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

cpp2rust/converter/converter.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ bool Converter::VisitRecordType(clang::RecordType *type) {
165165
->getAs<clang::FunctionProtoType>(),
166166
FnProtoType::LambdaCallOperator));
167167
} else {
168-
StrCat("_");
168+
StrCat('_');
169169
}
170170
return false;
171171
}
@@ -3061,7 +3061,7 @@ bool Converter::VisitEnumDecl(clang::EnumDecl *decl) {
30613061
Mapper::AddRuleForUserDefinedType(decl);
30623062
StrCat("#[derive(Clone, Copy, PartialEq, Debug, Default)]");
30633063
StrCat(std::format("enum {}", GetRecordName(decl)));
3064-
StrCat("{");
3064+
StrCat('{');
30653065
bool first_enumerator = true;
30663066
for (auto e : decl->enumerators()) {
30673067
llvm::SmallVector<char, 32> init;
@@ -3073,7 +3073,7 @@ bool Converter::VisitEnumDecl(clang::EnumDecl *decl) {
30733073
StrCat(std::format("{} = {},", std::string_view(e->getName()),
30743074
std::string_view(init.data(), init.size())));
30753075
}
3076-
StrCat("}");
3076+
StrCat('}');
30773077

30783078
AddFromImpl(decl);
30793079
AddIncDecImpls(decl);
@@ -3114,7 +3114,7 @@ bool Converter::VisitLambdaExpr(clang::LambdaExpr *expr) {
31143114
StrCat("Some");
31153115
}
31163116
PushParen paren(*this);
3117-
StrCat("|");
3117+
StrCat('|');
31183118
for (auto p : expr->getLambdaClass()->getLambdaCallOperator()->parameters()) {
31193119
StrCat(GetNamedDeclAsString(p), token::kColon, ToString(p->getType()),
31203120
token::kComma);
@@ -3126,7 +3126,7 @@ bool Converter::VisitLambdaExpr(clang::LambdaExpr *expr) {
31263126
curr_function_ = expr->getLambdaClass()->getLambdaCallOperator();
31273127
ConvertFunctionBody(curr_function_);
31283128
curr_function_ = old_function;
3129-
StrCat("}");
3129+
StrCat('}');
31303130
return false;
31313131
}
31323132

@@ -3702,21 +3702,21 @@ void Converter::ConvertOrdAndPartialOrdTraitsBase(
37023702
std::string_view first_branch, std::string_view second_branch,
37033703
std::string_view first_return, std::string_view second_return,
37043704
std::string_view record_name) {
3705-
StrCat(keyword::kImpl, "Ord for ", record_name, "{");
3705+
StrCat(keyword::kImpl, "Ord for ", record_name, '{');
37063706
StrCat("fn cmp(&self, other: &Self) -> std::cmp::Ordering {");
37073707
StrCat(std::format("{} {{", keyword_unsafe_));
3708-
StrCat("if", first_branch, "{", first_return, "} else if", second_branch, "{",
3708+
StrCat("if", first_branch, '{', first_return, "} else if", second_branch, '{',
37093709
second_return, "} else { std::cmp::Ordering::Equal }");
37103710
StrCat("}}}");
37113711

3712-
StrCat(keyword::kImpl, "PartialOrd for", record_name, "{");
3712+
StrCat(keyword::kImpl, "PartialOrd for", record_name, '{');
37133713
StrCat(R"(
37143714
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
37153715
Some(self.cmp(other))
37163716
}
37173717
})");
37183718

3719-
StrCat(keyword::kImpl, "PartialEq for", record_name, "{");
3719+
StrCat(keyword::kImpl, "PartialEq for", record_name, '{');
37203720
StrCat("fn eq(&self, other: &Self) -> bool {");
37213721
StrCat(std::format("{} {{", keyword_unsafe_));
37223722
StrCat("!(", first_branch, ") && !(", second_branch, ')');

0 commit comments

Comments
 (0)