From 0c754d434977f610dc871044562f2c81ef90be9a Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 18 Nov 2026 16:05:01 +0000 Subject: [PATCH 1/3] Parenthesize struct literal arguments in rule conditions --- cpp2rust/converter/converter.cpp | 9 ++++-- cpp2rust/converter/translation_rule.cpp | 6 ++-- cpp2rust/converter/translation_rule.h | 2 ++ rule-preprocessor/src/ir.rs | 4 +++ rule-preprocessor/src/syntactic.rs | 37 +++++++++++++++++++++++ tests/unit/find.cpp | 7 +++++ tests/unit/out/refcount/find.rs | 40 +++++++++++++++++++++++++ tests/unit/out/unsafe/find.rs | 30 +++++++++++++++++++ 8 files changed, 131 insertions(+), 4 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 9dc1c8932b..ccf3968900 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -5819,15 +5819,20 @@ std::string Converter::ConvertIRFragment( if (borrows_ && isFresh() && !CreatesTemporary(arg)) { value = std::format("({{ {} }})", value); borrows_ = false; + } else if (ph->no_struct_literal && arg->getType()->isRecordType() && + !AsLambdaClass(arg->getType()) && + arg->IgnoreImplicit()->isPRValue()) { + value = std::format("({})", value); } borrows_ |= outer_borrows; result += value; } else if (std::get_if(&frag)) { assert(expr && "variadic arguments outside an expression rule"); result += ConvertVariadicTail(expr, all_args); - } else if (std::get_if(&frag)) { + } else if (auto *init = std::get_if(&frag)) { assert(expr && "init outside an expression rule"); - result += ConvertInitFragment(expr, all_args); + auto value = ConvertInitFragment(expr, all_args); + result += init->no_struct_literal ? std::format("({})", value) : value; } else if (auto *mc = std::get_if>(&frag)) { result += ConvertMappedMethodCall(expr, **mc, bindings, all_args, ctx); diff --git a/cpp2rust/converter/translation_rule.cpp b/cpp2rust/converter/translation_rule.cpp index 1caa19ebf8..f923d8a084 100644 --- a/cpp2rust/converter/translation_rule.cpp +++ b/cpp2rust/converter/translation_rule.cpp @@ -72,6 +72,7 @@ ParsePlaceholderFragmentJSON(const llvm::json::Object &obj) { ParseAccessJSON(*access), obj.getBoolean("is_index_base").value_or(false), obj.getBoolean("conditional").value_or(false), + obj.getBoolean("no_struct_literal").value_or(false), }; } @@ -136,8 +137,9 @@ std::vector ParseBodyFragmentsJSON(const llvm::json::Array &arr) { } else if (frag_obj->get("va_args")) { result.push_back(VaArgsFragment{}); } else if (frag_obj->get("init")) { - result.push_back( - InitFragment{frag_obj->getBoolean("conditional").value_or(false)}); + result.push_back(InitFragment{ + frag_obj->getBoolean("conditional").value_or(false), + frag_obj->getBoolean("no_struct_literal").value_or(false)}); } } return result; diff --git a/cpp2rust/converter/translation_rule.h b/cpp2rust/converter/translation_rule.h index efc882ad8f..b6120a4c38 100644 --- a/cpp2rust/converter/translation_rule.h +++ b/cpp2rust/converter/translation_rule.h @@ -35,6 +35,7 @@ struct PlaceholderFragment { // Whether it is in a loop, a closure or a branch, which may evaluate it other // than once. bool conditional = false; + bool no_struct_literal = false; void dump() const; }; @@ -51,6 +52,7 @@ struct VaArgsFragment { struct InitFragment { bool conditional = false; + bool no_struct_literal = false; void dump() const; }; diff --git a/rule-preprocessor/src/ir.rs b/rule-preprocessor/src/ir.rs index 9d40f2fe3d..2a7b926197 100644 --- a/rule-preprocessor/src/ir.rs +++ b/rule-preprocessor/src/ir.rs @@ -202,6 +202,8 @@ pub enum BodyFragment { init: std::marker::PhantomData<()>, #[serde(default, skip_serializing_if = "std::ops::Not::not")] conditional: bool, + #[serde(default, skip_serializing_if = "std::ops::Not::not")] + no_struct_literal: bool, }, GenericCall { generic_call: GenericCallInner, @@ -228,6 +230,8 @@ pub struct PlaceholderInner { /// evaluate it other than once. #[serde(default, skip_serializing_if = "std::ops::Not::not")] pub conditional: bool, + #[serde(default, skip_serializing_if = "std::ops::Not::not")] + pub no_struct_literal: bool, } #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/rule-preprocessor/src/syntactic.rs b/rule-preprocessor/src/syntactic.rs index 3f481d625b..05aca514a8 100644 --- a/rule-preprocessor/src/syntactic.rs +++ b/rule-preprocessor/src/syntactic.rs @@ -278,6 +278,7 @@ impl<'a> FragmentCtx<'a> { self.fragments.push(BodyFragment::Init { init: std::marker::PhantomData, conditional: Self::is_conditional(token), + no_struct_literal: Self::excludes_struct_literal(token), }); return; } @@ -300,6 +301,7 @@ impl<'a> FragmentCtx<'a> { access, is_index_base: false, conditional: Self::is_conditional(token), + no_struct_literal: Self::excludes_struct_literal(token), }, }); return; @@ -345,6 +347,41 @@ impl<'a> FragmentCtx<'a> { }) } + fn excludes_struct_literal(token: &ra_ap_syntax::SyntaxToken) -> bool { + fn contains(node: Option, token: &ra_ap_syntax::SyntaxToken) -> bool { + node.is_some_and(|node| { + node.syntax() + .text_range() + .contains_range(token.text_range()) + }) + } + for node in token.parent_ancestors() { + let excludes = match_ast! { + match node { + ast::ParenExpr(_) => Some(false), + ast::ArgList(_) => Some(false), + ast::ArrayExpr(_) => Some(false), + ast::TupleExpr(_) => Some(false), + ast::StmtList(_) => Some(false), + ast::TokenTree(_) => Some(false), + ast::IndexExpr(it) => contains(it.index(), token).then_some(false), + ast::WhileExpr(it) => Some(contains(it.condition(), token)), + ast::IfExpr(it) => Some(contains(it.condition(), token)), + ast::MatchExpr(it) => Some(contains(it.expr(), token)), + ast::ForExpr(it) => Some(contains(it.iterable(), token)), + ast::LetStmt(it) => Some( + it.let_else().is_some() && contains(it.initializer(), token), + ), + _ => None, + } + }; + if let Some(excludes) = excludes { + return excludes; + } + } + false + } + fn generic_of_path(&self, path: &ast::Path) -> Option { if path.qualifier().is_some() { return None; diff --git a/tests/unit/find.cpp b/tests/unit/find.cpp index dcded2e88b..c5d8cc4f43 100644 --- a/tests/unit/find.cpp +++ b/tests/unit/find.cpp @@ -3,6 +3,11 @@ #include #include +struct P { + int x; + bool operator==(const P &o) const { return x == o.x; } +}; + int main() { std::vector v; v.push_back(1); @@ -25,5 +30,7 @@ int main() { assert(std::find(w.begin() + 2, w.end(), 4) == w.begin() + 3); assert(std::find(w.begin() + 2, w.end(), 1) == w.end()); assert(std::find(w.begin() + 2, w.begin() + 4, 5) == w.begin() + 4); + std::vector

p = {P{0}, P{1}, P{2}}; + assert(std::find(p.begin(), p.end(), P{1}) == p.begin() + 1); return 0; } diff --git a/tests/unit/out/refcount/find.rs b/tests/unit/out/refcount/find.rs index 906c037675..e1384d70e3 100644 --- a/tests/unit/out/refcount/find.rs +++ b/tests/unit/out/refcount/find.rs @@ -6,6 +6,17 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; +#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(4)] +pub struct P { + #[offset(0)] + pub x: i32, +} +impl CppEq for P { + fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + PImpl::operator_eq(__lhs, __rhs.clone()) + } +} pub fn main() { __cpp2rust_init_globals(); std::process::exit(main_0()); @@ -139,6 +150,35 @@ fn main_0() -> i32 { } }) == w.decay().begin().iter_add(4_isize) ); + let p: Value> = Rc::new(RefCell::new(Vec::from([ + P { x: 0 }, + P { x: 1 }, + P { x: 2 }, + ]))); + assert!( + ({ + let __tmp_16: Value

= Rc::new(RefCell::new(P { x: 1 })); + match ({ p.decay().begin() }, { p.decay().end() }) { + (mut __tmp_14, mut __tmp_15) => { + let mut __it = (__tmp_14).clone(); + while __it != __tmp_15 + && !CppEq::equal(&__it.iter_deref(), &__tmp_16.as_pointer()) + { + __it.iter_inc(); + } + __it + } + } + }) == p.decay().begin().iter_add(1_isize) + ); return 0; } +pub trait PImpl { + fn operator_eq(&self, o: Ptr

) -> bool; +} +impl PImpl for Ptr

{ + fn operator_eq(&self, o: Ptr

) -> bool { + return ({ (*self).with(|__s| __s.x) } == { o.with(|__s| __s.x) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/find.rs b/tests/unit/out/unsafe/find.rs index 5bcc12668f..34edc56fa6 100644 --- a/tests/unit/out/unsafe/find.rs +++ b/tests/unit/out/unsafe/find.rs @@ -6,6 +6,22 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct P { + pub x: i32, +} +impl P { + pub unsafe fn operator_eq(&self, o: *const P) -> bool { + return ((self.x) == ((*o).x)); + } +} +impl std::cmp::PartialEq for P { + fn eq(&self, other: &Self) -> bool { + unsafe { P::operator_eq(self, other as *const P) } + } +} +impl std::cmp::Eq for P {} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -102,6 +118,20 @@ unsafe fn main_0() -> i32 { } } == w.begin().iter_add(4_isize) ); + let mut p: Vec

= Vec::from([P { x: 0 }, P { x: 1 }, P { x: 2 }]); + assert!( + match ({ p.begin() }, { p.end() },) { + (mut __tmp_9, mut __tmp_10) => { + { + let mut __it = (__tmp_9).clone(); + while __it != __tmp_10 && *__it.iter_deref() != (P { x: 1 }) { + __it.iter_inc(); + } + __it + } + } + } == p.begin().iter_add(1_isize) + ); return 0; } pub unsafe fn __cpp2rust_init_globals() {} From 8fd1aebebb6b64e32ef05c18419af7e8951ab3f5 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 18 Nov 2026 16:51:52 +0000 Subject: [PATCH 2/3] Always parenthesize struct literal rule arguments --- cpp2rust/converter/converter.cpp | 26 ++++++------- cpp2rust/converter/converter.h | 6 +-- cpp2rust/converter/converter_lib.cpp | 18 +++++++++ cpp2rust/converter/converter_lib.h | 2 + cpp2rust/converter/translation_rule.cpp | 6 +-- cpp2rust/converter/translation_rule.h | 2 - rule-preprocessor/src/ir.rs | 4 -- rule-preprocessor/src/syntactic.rs | 37 ------------------- tests/unit/out/refcount/find.rs | 2 +- tests/unit/out/refcount/fn_ptr_stable_sort.rs | 6 +-- .../refcount/pair_converting_construction.rs | 4 +- .../out/refcount/vector_subscript_direct.rs | 2 +- tests/unit/out/unsafe/fn_ptr_stable_sort.rs | 6 +-- .../unsafe/pair_converting_construction.rs | 2 +- .../out/unsafe/vector_subscript_direct.rs | 2 +- 15 files changed, 50 insertions(+), 75 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index cd8519b199..b8d281472a 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -5760,9 +5760,7 @@ std::string Converter::ConvertIRFragment( if (borrows_ && isFresh() && !CreatesTemporary(arg)) { value = std::format("({{ {} }})", value); borrows_ = false; - } else if (ph->no_struct_literal && arg->getType()->isRecordType() && - !AsLambdaClass(arg->getType()) && - arg->IgnoreImplicit()->isPRValue()) { + } else if (IsStructLiteral(arg)) { value = std::format("({})", value); } borrows_ |= outer_borrows; @@ -5770,10 +5768,9 @@ std::string Converter::ConvertIRFragment( } else if (std::get_if(&frag)) { assert(expr && "variadic arguments outside an expression rule"); result += ConvertVariadicTail(expr, all_args); - } else if (auto *init = std::get_if(&frag)) { + } else if (std::get_if(&frag)) { assert(expr && "init outside an expression rule"); - auto value = ConvertInitFragment(expr, all_args); - result += init->no_struct_literal ? std::format("({})", value) : value; + result += ConvertInitFragment(expr, all_args); } else if (auto *mc = std::get_if>(&frag)) { result += ConvertMappedMethodCall(expr, **mc, bindings, all_args, ctx); @@ -5942,22 +5939,25 @@ Converter::ConvertInitFragment(clang::Expr *expr, Buffer buf(*this); PushExprKind push(*this, ExprKind::RValue); - ConvertConstructFromArgs(type, all_args.drop_front(tgt_ir->params.size()), - expr->getExprLoc()); - return std::move(buf).str(); + auto *init = ConvertConstructFromArgs( + type, all_args.drop_front(tgt_ir->params.size()), expr->getExprLoc()); + auto value = std::move(buf).str(); + return IsStructLiteral(init) ? std::format("({})", value) : value; } -void Converter::ConvertConstructFromArgs(clang::QualType type, - llvm::ArrayRef args, - clang::SourceLocation loc) { +clang::Expr * +Converter::ConvertConstructFromArgs(clang::QualType type, + llvm::ArrayRef args, + clang::SourceLocation loc) { auto *init = BuildInitExpr(GetSema(), type, args, loc); assert(init && "type cannot be initialized from the arguments"); if (args.empty() && !clang::isa(init->IgnoreImplicit())) { StrCat(GetDefaultAsString(type)); - return; + return init; } ConvertInit(type, init); + return init; } void Converter::ConvertInit(clang::QualType type, clang::Expr *init) { diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index fe87a81f96..c0fa26b3b0 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -944,9 +944,9 @@ class Converter : public clang::RecursiveASTVisitor { std::string ConvertInitFragment(clang::Expr *expr, llvm::ArrayRef all_args); - void ConvertConstructFromArgs(clang::QualType type, - llvm::ArrayRef args, - clang::SourceLocation loc); + clang::Expr *ConvertConstructFromArgs(clang::QualType type, + llvm::ArrayRef args, + clang::SourceLocation loc); void ConvertInit(clang::QualType type, clang::Expr *init); diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index f503959168..b0949d9e3a 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -359,6 +359,24 @@ bool IsLibraryOnlySpecialization(const clang::FunctionDecl *decl) { HasLibraryInternalArgument(ctx, args->asArray()); } +bool IsStructLiteral(const clang::Expr *expr) { + expr = expr->IgnoreImplicit(); + if (auto *cast = clang::dyn_cast(expr)) { + expr = cast->getSubExpr()->IgnoreImplicit(); + } + auto *list = clang::dyn_cast(expr); + if (!list) { + return false; + } + auto *syntactic = list->isSyntacticForm() ? list : list->getSyntacticForm(); + if (auto *form = list->getSemanticForm()) { + list = form; + } + auto *record = list->getType()->getAsRecordDecl(); + return record && IsUserDefinedDecl(record) && !list->isTransparent() && + syntactic->getNumInits() != 0; +} + bool IsAbstractUserClass(const clang::RecordDecl *decl) { auto cxx = llvm::dyn_cast(decl); auto definition = cxx ? cxx->getDefinition() : nullptr; diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index 944316271a..d8c929f0ed 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -56,6 +56,8 @@ bool IsCodeUnitStringLiteral(const clang::StringLiteral *expr); bool IsUserDefinedDecl(const clang::Decl *decl); +bool IsStructLiteral(const clang::Expr *expr); + bool IsAbstractUserClass(const clang::RecordDecl *decl); bool IsLibraryOnlySpecialization( diff --git a/cpp2rust/converter/translation_rule.cpp b/cpp2rust/converter/translation_rule.cpp index f4c7a89977..daa012b372 100644 --- a/cpp2rust/converter/translation_rule.cpp +++ b/cpp2rust/converter/translation_rule.cpp @@ -74,7 +74,6 @@ ParsePlaceholderFragmentJSON(const llvm::json::Object &obj) { ParseAccessJSON(*access), obj.getBoolean("is_index_base").value_or(false), obj.getBoolean("conditional").value_or(false), - obj.getBoolean("no_struct_literal").value_or(false), }; } @@ -139,9 +138,8 @@ std::vector ParseBodyFragmentsJSON(const llvm::json::Array &arr) { } else if (frag_obj->get("va_args")) { result.push_back(VaArgsFragment{}); } else if (frag_obj->get("init")) { - result.push_back(InitFragment{ - frag_obj->getBoolean("conditional").value_or(false), - frag_obj->getBoolean("no_struct_literal").value_or(false)}); + result.push_back( + InitFragment{frag_obj->getBoolean("conditional").value_or(false)}); } } return result; diff --git a/cpp2rust/converter/translation_rule.h b/cpp2rust/converter/translation_rule.h index 68fed50ad9..94e020a837 100644 --- a/cpp2rust/converter/translation_rule.h +++ b/cpp2rust/converter/translation_rule.h @@ -35,7 +35,6 @@ struct PlaceholderFragment { // Whether it is in a loop, a closure or a branch, which may evaluate it other // than once. bool conditional = false; - bool no_struct_literal = false; void dump() const; }; @@ -52,7 +51,6 @@ struct VaArgsFragment { struct InitFragment { bool conditional = false; - bool no_struct_literal = false; void dump() const; }; diff --git a/rule-preprocessor/src/ir.rs b/rule-preprocessor/src/ir.rs index 43039cf82d..728a4b4b4d 100644 --- a/rule-preprocessor/src/ir.rs +++ b/rule-preprocessor/src/ir.rs @@ -206,8 +206,6 @@ pub enum BodyFragment { init: std::marker::PhantomData<()>, #[serde(default, skip_serializing_if = "std::ops::Not::not")] conditional: bool, - #[serde(default, skip_serializing_if = "std::ops::Not::not")] - no_struct_literal: bool, }, GenericCall { generic_call: GenericCallInner, @@ -234,8 +232,6 @@ pub struct PlaceholderInner { /// evaluate it other than once. #[serde(default, skip_serializing_if = "std::ops::Not::not")] pub conditional: bool, - #[serde(default, skip_serializing_if = "std::ops::Not::not")] - pub no_struct_literal: bool, } #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/rule-preprocessor/src/syntactic.rs b/rule-preprocessor/src/syntactic.rs index 6f2d54f6b8..323944b918 100644 --- a/rule-preprocessor/src/syntactic.rs +++ b/rule-preprocessor/src/syntactic.rs @@ -278,7 +278,6 @@ impl<'a> FragmentCtx<'a> { self.fragments.push(BodyFragment::Init { init: std::marker::PhantomData, conditional: Self::is_conditional(token), - no_struct_literal: Self::excludes_struct_literal(token), }); return; } @@ -301,7 +300,6 @@ impl<'a> FragmentCtx<'a> { access, is_index_base: false, conditional: Self::is_conditional(token), - no_struct_literal: Self::excludes_struct_literal(token), }, }); return; @@ -347,41 +345,6 @@ impl<'a> FragmentCtx<'a> { }) } - fn excludes_struct_literal(token: &ra_ap_syntax::SyntaxToken) -> bool { - fn contains(node: Option, token: &ra_ap_syntax::SyntaxToken) -> bool { - node.is_some_and(|node| { - node.syntax() - .text_range() - .contains_range(token.text_range()) - }) - } - for node in token.parent_ancestors() { - let excludes = match_ast! { - match node { - ast::ParenExpr(_) => Some(false), - ast::ArgList(_) => Some(false), - ast::ArrayExpr(_) => Some(false), - ast::TupleExpr(_) => Some(false), - ast::StmtList(_) => Some(false), - ast::TokenTree(_) => Some(false), - ast::IndexExpr(it) => contains(it.index(), token).then_some(false), - ast::WhileExpr(it) => Some(contains(it.condition(), token)), - ast::IfExpr(it) => Some(contains(it.condition(), token)), - ast::MatchExpr(it) => Some(contains(it.expr(), token)), - ast::ForExpr(it) => Some(contains(it.iterable(), token)), - ast::LetStmt(it) => Some( - it.let_else().is_some() && contains(it.initializer(), token), - ), - _ => None, - } - }; - if let Some(excludes) = excludes { - return excludes; - } - } - false - } - fn generic_of_path(&self, path: &ast::Path) -> Option { if path.qualifier().is_some() { return None; diff --git a/tests/unit/out/refcount/find.rs b/tests/unit/out/refcount/find.rs index e1384d70e3..f54db9dd67 100644 --- a/tests/unit/out/refcount/find.rs +++ b/tests/unit/out/refcount/find.rs @@ -162,7 +162,7 @@ fn main_0() -> i32 { (mut __tmp_14, mut __tmp_15) => { let mut __it = (__tmp_14).clone(); while __it != __tmp_15 - && !CppEq::equal(&__it.iter_deref(), &__tmp_16.as_pointer()) + && !CppEq::equal(&__it.iter_deref(), &(__tmp_16.as_pointer())) { __it.iter_inc(); } diff --git a/tests/unit/out/refcount/fn_ptr_stable_sort.rs b/tests/unit/out/refcount/fn_ptr_stable_sort.rs index eab77e2913..996cf03755 100644 --- a/tests/unit/out/refcount/fn_ptr_stable_sort.rs +++ b/tests/unit/out/refcount/fn_ptr_stable_sort.rs @@ -24,15 +24,15 @@ pub fn main() { fn main_0() -> i32 { let v: Value> = Rc::new(RefCell::new(Vec::new())); { - let __a1 = Item { key: 3, value: 30 }; + let __a1 = (Item { key: 3, value: 30 }); (*v.borrow_mut()).push(__a1) }; { - let __a1 = Item { key: 1, value: 10 }; + let __a1 = (Item { key: 1, value: 10 }); (*v.borrow_mut()).push(__a1) }; { - let __a1 = Item { key: 2, value: 20 }; + let __a1 = (Item { key: 2, value: 20 }); (*v.borrow_mut()).push(__a1) }; match ({ v.decay().begin() },) { diff --git a/tests/unit/out/refcount/pair_converting_construction.rs b/tests/unit/out/refcount/pair_converting_construction.rs index f726f9358f..0f0be6cbbe 100644 --- a/tests/unit/out/refcount/pair_converting_construction.rs +++ b/tests/unit/out/refcount/pair_converting_construction.rs @@ -207,8 +207,8 @@ fn main_0() -> i32 { assert!(({ ({ (*(*from_copied_pair.borrow()).0.borrow()).degrees } == 5) })); assert!(({ ((*(*from_copied_pair.borrow()).1.borrow()) == 6_i64) })); let meters: Value<(Value, Value)> = Rc::new(RefCell::new(( - Rc::new(RefCell::new(Meters { value: 8 })), - Rc::new(RefCell::new(Meters { value: 9 })), + Rc::new(RefCell::new((Meters { value: 8 }))), + Rc::new(RefCell::new((Meters { value: 9 }))), ))); let from_operator_pair: Value<(Value, Value)> = Rc::new(RefCell::new(( Rc::new(RefCell::new(>::cpp_from( diff --git a/tests/unit/out/refcount/vector_subscript_direct.rs b/tests/unit/out/refcount/vector_subscript_direct.rs index 2ad78d1f5f..5e009e3be9 100644 --- a/tests/unit/out/refcount/vector_subscript_direct.rs +++ b/tests/unit/out/refcount/vector_subscript_direct.rs @@ -94,7 +94,7 @@ fn main_0() -> i32 { }; vec_elem!(h.as_pointer(), values, 1_usize).write(6); { - let __a1 = Point { x: 1, y: 2 }; + let __a1 = (Point { x: 1, y: 2 }); (*h.borrow_mut()).points.push(__a1) }; field!(vec_elem!(h.as_pointer(), points, 0_usize), y).write(5); diff --git a/tests/unit/out/unsafe/fn_ptr_stable_sort.rs b/tests/unit/out/unsafe/fn_ptr_stable_sort.rs index 25da3034f4..1cc5578aaf 100644 --- a/tests/unit/out/unsafe/fn_ptr_stable_sort.rs +++ b/tests/unit/out/unsafe/fn_ptr_stable_sort.rs @@ -24,15 +24,15 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut v: Vec = Vec::new(); { - let __a1 = Item { key: 3, value: 30 }; + let __a1 = (Item { key: 3, value: 30 }); v.push(__a1) }; { - let __a1 = Item { key: 1, value: 10 }; + let __a1 = (Item { key: 1, value: 10 }); v.push(__a1) }; { - let __a1 = Item { key: 2, value: 20 }; + let __a1 = (Item { key: 2, value: 20 }); v.push(__a1) }; match ({ v.begin() },) { diff --git a/tests/unit/out/unsafe/pair_converting_construction.rs b/tests/unit/out/unsafe/pair_converting_construction.rs index 817ae11786..b4c7963bee 100644 --- a/tests/unit/out/unsafe/pair_converting_construction.rs +++ b/tests/unit/out/unsafe/pair_converting_construction.rs @@ -173,7 +173,7 @@ unsafe fn main_0() -> i32 { ); assert!(((from_copied_pair.0.degrees) == (5))); assert!(((from_copied_pair.1) == (6_i64))); - let mut meters: (Meters, Meters) = (Meters { value: 8 }, Meters { value: 9 }); + let mut meters: (Meters, Meters) = ((Meters { value: 8 }), (Meters { value: 9 })); let mut from_operator_pair: (i32, i32) = ( >::cpp_from(&meters.0), >::cpp_from(&meters.1), diff --git a/tests/unit/out/unsafe/vector_subscript_direct.rs b/tests/unit/out/unsafe/vector_subscript_direct.rs index 8e986e9a63..c5081f921c 100644 --- a/tests/unit/out/unsafe/vector_subscript_direct.rs +++ b/tests/unit/out/unsafe/vector_subscript_direct.rs @@ -108,7 +108,7 @@ unsafe fn main_0() -> i32 { }; h.values[(1_usize)] = 6; { - let __a1 = Point { x: 1, y: 2 }; + let __a1 = (Point { x: 1, y: 2 }); h.points.push(__a1) }; h.points[(0_usize)].y = 5; From 71720445a20a17e5b8b21a0107e0992a9ca16ef2 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 18 Nov 2026 17:01:08 +0000 Subject: [PATCH 3/3] Update tests --- tests/unit/out/refcount/class_templates.rs | 2 +- tests/unit/out/refcount/operator_traits.rs | 6 +++--- tests/unit/out/unsafe/class_templates.rs | 2 +- tests/unit/out/unsafe/operator_traits.rs | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/unit/out/refcount/class_templates.rs b/tests/unit/out/refcount/class_templates.rs index fbd1a6e69f..0e9e421905 100644 --- a/tests/unit/out/refcount/class_templates.rs +++ b/tests/unit/out/refcount/class_templates.rs @@ -130,7 +130,7 @@ pub fn main() { fn main_0() -> i32 { let mut ev: Vec = Vec::new(); { - let __a1 = Elem { i: 2 }; + let __a1 = (Elem { i: 2 }); ev.push(__a1) }; assert!((ev[0_usize].i == 2)); diff --git a/tests/unit/out/refcount/operator_traits.rs b/tests/unit/out/refcount/operator_traits.rs index 3886c86055..91e2dff395 100644 --- a/tests/unit/out/refcount/operator_traits.rs +++ b/tests/unit/out/refcount/operator_traits.rs @@ -206,13 +206,13 @@ fn main_0() -> i32 { let m: Value, Value)>> = Rc::new(RefCell::new(Map::new())); Map::subscript_move( m.as_pointer(), - Rc::new(RefCell::new(Lt { v: 2 })).as_pointer(), + (Rc::new(RefCell::new(Lt { v: 2 })).as_pointer()), |__k| cpp_move!(__k), ) .write(20); Map::subscript_move( m.as_pointer(), - Rc::new(RefCell::new(Lt { v: 1 })).as_pointer(), + (Rc::new(RefCell::new(Lt { v: 1 })).as_pointer()), |__k| cpp_move!(__k), ) .write(10); @@ -230,7 +230,7 @@ fn main_0() -> i32 { assert!( ((Map::subscript_move( m.as_pointer(), - Rc::new(RefCell::new(Lt { v: 2 })).as_pointer(), + (Rc::new(RefCell::new(Lt { v: 2 })).as_pointer()), |__k| cpp_move!(__k) ) .read()) diff --git a/tests/unit/out/unsafe/class_templates.rs b/tests/unit/out/unsafe/class_templates.rs index f76d00878b..1c706f9239 100644 --- a/tests/unit/out/unsafe/class_templates.rs +++ b/tests/unit/out/unsafe/class_templates.rs @@ -229,7 +229,7 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut ev: Vec = Vec::new(); { - let __a1 = Elem { i: 2 }; + let __a1 = (Elem { i: 2 }); ev.push(__a1) }; assert!(((ev[(0_usize)].i) == (2))); diff --git a/tests/unit/out/unsafe/operator_traits.rs b/tests/unit/out/unsafe/operator_traits.rs index b44889ef22..1e3566b012 100644 --- a/tests/unit/out/unsafe/operator_traits.rs +++ b/tests/unit/out/unsafe/operator_traits.rs @@ -251,10 +251,10 @@ unsafe fn main_0() -> i32 { .v) == (2)) ); let mut m: UnsafeMap = UnsafeMap::new(); - (*m.subscript_move(&mut Lt { v: 2 }, |__k| cpp_move_unsafe!(__k))) = 20; - (*m.subscript_move(&mut Lt { v: 1 }, |__k| cpp_move_unsafe!(__k))) = 10; + (*m.subscript_move((&mut Lt { v: 2 }), |__k| cpp_move_unsafe!(__k))) = 20; + (*m.subscript_move((&mut Lt { v: 1 }), |__k| cpp_move_unsafe!(__k))) = 10; assert!((((*m.begin().iter_deref()).1) == (10))); - assert!(((*m.subscript_move(&mut Lt { v: 2 }, |__k| cpp_move_unsafe!(__k))) == (20))); + assert!(((*m.subscript_move((&mut Lt { v: 2 }), |__k| cpp_move_unsafe!(__k))) == (20))); return 0; } pub unsafe fn __cpp2rust_init_globals() {}