Skip to content

Suppress clone in iterator conversion#112

Merged
nunoplopes merged 15 commits into
Cpp2Rust:masterfrom
lucic71:redundant-copy
May 18, 2026
Merged

Suppress clone in iterator conversion#112
nunoplopes merged 15 commits into
Cpp2Rust:masterfrom
lucic71:redundant-copy

Conversation

@lucic71
Copy link
Copy Markdown
Contributor

@lucic71 lucic71 commented May 17, 2026

From, tests/unit/redundant_copy_in_conversion:

  // Comparing const_iterator with iterator forces an implicit conversion of
  // `end` to const_iterator. The AST shape differs between platforms:
  //
  //   Linux: const_it == ConvertingCtor(end)
  //   macOS: const_it == ConvertingCtor(CopyCtor(end))
  //
  // The extra inner CopyCtor on macOS would emit a redundant .clone() in the
  // generated Rust. cpp2rust suppresses it so the output matches Linux.
  const_it == end ? 0 : 1;

This only happens on iterator types because the distinction between iterator and const_iterator. Other containers don't have this issue.

@lucic71 lucic71 marked this pull request as draft May 17, 2026 13:21
@lucic71 lucic71 changed the title Only apply IsRedundantCopyInConversion for iterators Suppress clone in iterator conversion May 18, 2026
@lucic71 lucic71 marked this pull request as ready for review May 18, 2026 10:56
Comment thread tests/unit/out/unsafe/map.rs
@nunoplopes nunoplopes merged commit 08a11c2 into Cpp2Rust:master May 18, 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