Skip to content

Commit 1a39580

Browse files
committed
Trim return type
1 parent 1618257 commit 1a39580

4 files changed

Lines changed: 6 additions & 6 deletions

File tree

‎cpp2rust/converter/converter.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2465,8 +2465,8 @@ void Converter::ConvertIntegralToBooleanCast(clang::ImplicitCastExpr *expr) {
24652465
bool Converter::IsCastRedundantInRust(clang::Expr *expr,
24662466
clang::QualType target_type) {
24672467
auto target = GetUnsafeTypeAsString(target_type);
2468-
if (const auto *rule = RuleRegistry::GetExprRule(ctx_, expr)) {
2469-
return rule->return_type.type == target;
2468+
if (RuleRegistry::GetExprRule(ctx_, expr)) {
2469+
return Trim(Mapper::GetReturnType(*this, expr)) == target;
24702470
}
24712471
return GetUnsafeTypeAsString(expr->getType()) == target;
24722472
}

‎cpp2rust/converter/rules/expr_matcher.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ bool constructsReturnType(const clang::Expr *returned, clang::QualType ret,
355355
}
356356
if (auto decl = std::get_if<const clang::Decl *>(&usage_decl)) {
357357
auto ctor = llvm::dyn_cast<clang::CXXConstructorDecl>(*decl);
358-
return ctor && ctor->getParent()->getCanonicalDecl() ==
359-
record->getCanonicalDecl();
358+
return ctor &&
359+
ctor->getParent()->getCanonicalDecl() == record->getCanonicalDecl();
360360
}
361361
if (auto aggregate = std::get_if<AggregateUsage>(&usage_decl)) {
362362
return RuleKeys::GetTypeKey(ret) == aggregate->type;

‎tests/unit/out/refcount/atomic.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn main() {
1818
}
1919
fn main_0() -> i32 {
2020
let a: Value<Counter> = Rc::new(RefCell::new(Counter::default()));
21-
let mut v: Counter = ((*a.borrow()) as Counter);
21+
let mut v: Counter = (*a.borrow()).clone();
2222
assert!((v.n == 0));
2323
return 0;
2424
}

‎tests/unit/out/unsafe/atomic.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub fn main() {
1919
}
2020
unsafe fn main_0() -> i32 {
2121
let mut a: Counter = Counter::default();
22-
let mut v: Counter = (a as Counter);
22+
let mut v: Counter = a;
2323
assert!(((v.n) == (0)));
2424
return 0;
2525
}

0 commit comments

Comments
 (0)