Skip to content

Fix default substitution inside nested containers - #564

Merged
nunoplopes merged 10 commits into
Cpp2Rust:masterfrom
lucic71:nested-default
Oct 29, 2026
Merged

nunoplopes merged 10 commits into
Cpp2Rust:masterfrom
lucic71:nested-default

Conversation

@lucic71

@lucic71 lucic71 commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

This fixes the default of unique_ptr<string[]>. Before this PR the translation did not use the default of string, now it does.

I added a new node in Rules IR called default. When cpp2rust encounters this node, it replaces with the default of the substituted type.

This also generates more idiomatic code:

-               arr: std::array::from_fn::<_, 3_usize, _>(|_| <i32>::default()).to_vec(),
+               arr: std::array::from_fn::<_, 3_usize, _>(|_| 0_i32).to_vec(),

@nunoplopes
nunoplopes merged commit bf51851 into Cpp2Rust:master Oct 29, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants